360inline QMatrix4x4& QMatrix4x4::operator+=(
const QMatrix4x4& other)
362 m[0][0] += other.m[0][0];
363 m[0][1] += other.m[0][1];
364 m[0][2] += other.m[0][2];
365 m[0][3] += other.m[0][3];
366 m[1][0] += other.m[1][0];
367 m[1][1] += other.m[1][1];
368 m[1][2] += other.m[1][2];
369 m[1][3] += other.m[1][3];
370 m[2][0] += other.m[2][0];
371 m[2][1] += other.m[2][1];
372 m[2][2] += other.m[2][2];
373 m[2][3] += other.m[2][3];
374 m[3][0] += other.m[3][0];
375 m[3][1] += other.m[3][1];
376 m[3][2] += other.m[3][2];
377 m[3][3] += other.m[3][3];
382inline QMatrix4x4& QMatrix4x4::operator-=(
const QMatrix4x4& other)
384 m[0][0] -= other.m[0][0];
385 m[0][1] -= other.m[0][1];
386 m[0][2] -= other.m[0][2];
387 m[0][3] -= other.m[0][3];
388 m[1][0] -= other.m[1][0];
389 m[1][1] -= other.m[1][1];
390 m[1][2] -= other.m[1][2];
391 m[1][3] -= other.m[1][3];
392 m[2][0] -= other.m[2][0];
393 m[2][1] -= other.m[2][1];
394 m[2][2] -= other.m[2][2];
395 m[2][3] -= other.m[2][3];
396 m[3][0] -= other.m[3][0];
397 m[3][1] -= other.m[3][1];
398 m[3][2] -= other.m[3][2];
399 m[3][3] -= other.m[3][3];
404inline QMatrix4x4& QMatrix4x4::operator*=(
const QMatrix4x4& o)
406 const QMatrix4x4 other = o;
407 flagBits |= other.flagBits;
409 if (flagBits.toInt() < Rotation2D) {
410 m[3][0] += m[0][0] * other.m[3][0];
411 m[3][1] += m[1][1] * other.m[3][1];
412 m[3][2] += m[2][2] * other.m[3][2];
414 m[0][0] *= other.m[0][0];
415 m[1][1] *= other.m[1][1];
416 m[2][2] *= other.m[2][2];
421 m0 = m[0][0] * other.m[0][0]
422 + m[1][0] * other.m[0][1]
423 + m[2][0] * other.m[0][2]
424 + m[3][0] * other.m[0][3];
425 m1 = m[0][0] * other.m[1][0]
426 + m[1][0] * other.m[1][1]
427 + m[2][0] * other.m[1][2]
428 + m[3][0] * other.m[1][3];
429 m2 = m[0][0] * other.m[2][0]
430 + m[1][0] * other.m[2][1]
431 + m[2][0] * other.m[2][2]
432 + m[3][0] * other.m[2][3];
433 m[3][0] = m[0][0] * other.m[3][0]
434 + m[1][0] * other.m[3][1]
435 + m[2][0] * other.m[3][2]
436 + m[3][0] * other.m[3][3];
441 m0 = m[0][1] * other.m[0][0]
442 + m[1][1] * other.m[0][1]
443 + m[2][1] * other.m[0][2]
444 + m[3][1] * other.m[0][3];
445 m1 = m[0][1] * other.m[1][0]
446 + m[1][1] * other.m[1][1]
447 + m[2][1] * other.m[1][2]
448 + m[3][1] * other.m[1][3];
449 m2 = m[0][1] * other.m[2][0]
450 + m[1][1] * other.m[2][1]
451 + m[2][1] * other.m[2][2]
452 + m[3][1] * other.m[2][3];
453 m[3][1] = m[0][1] * other.m[3][0]
454 + m[1][1] * other.m[3][1]
455 + m[2][1] * other.m[3][2]
456 + m[3][1] * other.m[3][3];
461 m0 = m[0][2] * other.m[0][0]
462 + m[1][2] * other.m[0][1]
463 + m[2][2] * other.m[0][2]
464 + m[3][2] * other.m[0][3];
465 m1 = m[0][2] * other.m[1][0]
466 + m[1][2] * other.m[1][1]
467 + m[2][2] * other.m[1][2]
468 + m[3][2] * other.m[1][3];
469 m2 = m[0][2] * other.m[2][0]
470 + m[1][2] * other.m[2][1]
471 + m[2][2] * other.m[2][2]
472 + m[3][2] * other.m[2][3];
473 m[3][2] = m[0][2] * other.m[3][0]
474 + m[1][2] * other.m[3][1]
475 + m[2][2] * other.m[3][2]
476 + m[3][2] * other.m[3][3];
481 m0 = m[0][3] * other.m[0][0]
482 + m[1][3] * other.m[0][1]
483 + m[2][3] * other.m[0][2]
484 + m[3][3] * other.m[0][3];
485 m1 = m[0][3] * other.m[1][0]
486 + m[1][3] * other.m[1][1]
487 + m[2][3] * other.m[1][2]
488 + m[3][3] * other.m[1][3];
489 m2 = m[0][3] * other.m[2][0]
490 + m[1][3] * other.m[2][1]
491 + m[2][3] * other.m[2][2]
492 + m[3][3] * other.m[2][3];
493 m[3][3] = m[0][3] * other.m[3][0]
494 + m[1][3] * other.m[3][1]
495 + m[2][3] * other.m[3][2]
496 + m[3][3] * other.m[3][3];
525inline bool QMatrix4x4::operator==(
const QMatrix4x4& other)
const
527 return m[0][0] == other.m[0][0] &&
528 m[0][1] == other.m[0][1] &&
529 m[0][2] == other.m[0][2] &&
530 m[0][3] == other.m[0][3] &&
531 m[1][0] == other.m[1][0] &&
532 m[1][1] == other.m[1][1] &&
533 m[1][2] == other.m[1][2] &&
534 m[1][3] == other.m[1][3] &&
535 m[2][0] == other.m[2][0] &&
536 m[2][1] == other.m[2][1] &&
537 m[2][2] == other.m[2][2] &&
538 m[2][3] == other.m[2][3] &&
539 m[3][0] == other.m[3][0] &&
540 m[3][1] == other.m[3][1] &&
541 m[3][2] == other.m[3][2] &&
542 m[3][3] == other.m[3][3];
545inline bool QMatrix4x4::operator!=(
const QMatrix4x4& other)
const
547 return m[0][0] != other.m[0][0] ||
548 m[0][1] != other.m[0][1] ||
549 m[0][2] != other.m[0][2] ||
550 m[0][3] != other.m[0][3] ||
551 m[1][0] != other.m[1][0] ||
552 m[1][1] != other.m[1][1] ||
553 m[1][2] != other.m[1][2] ||
554 m[1][3] != other.m[1][3] ||
555 m[2][0] != other.m[2][0] ||
556 m[2][1] != other.m[2][1] ||
557 m[2][2] != other.m[2][2] ||
558 m[2][3] != other.m[2][3] ||
559 m[3][0] != other.m[3][0] ||
560 m[3][1] != other.m[3][1] ||
561 m[3][2] != other.m[3][2] ||
562 m[3][3] != other.m[3][3];
568 m.m[0][0] = m1.m[0][0] + m2.m[0][0];
569 m.m[0][1] = m1.m[0][1] + m2.m[0][1];
570 m.m[0][2] = m1.m[0][2] + m2.m[0][2];
571 m.m[0][3] = m1.m[0][3] + m2.m[0][3];
572 m.m[1][0] = m1.m[1][0] + m2.m[1][0];
573 m.m[1][1] = m1.m[1][1] + m2.m[1][1];
574 m.m[1][2] = m1.m[1][2] + m2.m[1][2];
575 m.m[1][3] = m1.m[1][3] + m2.m[1][3];
576 m.m[2][0] = m1.m[2][0] + m2.m[2][0];
577 m.m[2][1] = m1.m[2][1] + m2.m[2][1];
578 m.m[2][2] = m1.m[2][2] + m2.m[2][2];
579 m.m[2][3] = m1.m[2][3] + m2.m[2][3];
580 m.m[3][0] = m1.m[3][0] + m2.m[3][0];
581 m.m[3][1] = m1.m[3][1] + m2.m[3][1];
582 m.m[3][2] = m1.m[3][2] + m2.m[3][2];
583 m.m[3][3] = m1.m[3][3] + m2.m[3][3];
590 m.m[0][0] = m1.m[0][0] - m2.m[0][0];
591 m.m[0][1] = m1.m[0][1] - m2.m[0][1];
592 m.m[0][2] = m1.m[0][2] - m2.m[0][2];
593 m.m[0][3] = m1.m[0][3] - m2.m[0][3];
594 m.m[1][0] = m1.m[1][0] - m2.m[1][0];
595 m.m[1][1] = m1.m[1][1] - m2.m[1][1];
596 m.m[1][2] = m1.m[1][2] - m2.m[1][2];
597 m.m[1][3] = m1.m[1][3] - m2.m[1][3];
598 m.m[2][0] = m1.m[2][0] - m2.m[2][0];
599 m.m[2][1] = m1.m[2][1] - m2.m[2][1];
600 m.m[2][2] = m1.m[2][2] - m2.m[2][2];
601 m.m[2][3] = m1.m[2][3] - m2.m[2][3];
602 m.m[3][0] = m1.m[3][0] - m2.m[3][0];
603 m.m[3][1] = m1.m[3][1] - m2.m[3][1];
604 m.m[3][2] = m1.m[3][2] - m2.m[3][2];
605 m.m[3][3] = m1.m[3][3] - m2.m[3][3];
611 QMatrix4x4::Flags flagBits = m1.flagBits | m2.flagBits;
612 if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
614 m.m[3][0] += m.m[0][0] * m2.m[3][0];
615 m.m[3][1] += m.m[1][1] * m2.m[3][1];
616 m.m[3][2] += m.m[2][2] * m2.m[3][2];
618 m.m[0][0] *= m2.m[0][0];
619 m.m[1][1] *= m2.m[1][1];
620 m.m[2][2] *= m2.m[2][2];
621 m.flagBits = flagBits;
626 m.m[0][0] = m1.m[0][0] * m2.m[0][0]
627 + m1.m[1][0] * m2.m[0][1]
628 + m1.m[2][0] * m2.m[0][2]
629 + m1.m[3][0] * m2.m[0][3];
630 m.m[0][1] = m1.m[0][1] * m2.m[0][0]
631 + m1.m[1][1] * m2.m[0][1]
632 + m1.m[2][1] * m2.m[0][2]
633 + m1.m[3][1] * m2.m[0][3];
634 m.m[0][2] = m1.m[0][2] * m2.m[0][0]
635 + m1.m[1][2] * m2.m[0][1]
636 + m1.m[2][2] * m2.m[0][2]
637 + m1.m[3][2] * m2.m[0][3];
638 m.m[0][3] = m1.m[0][3] * m2.m[0][0]
639 + m1.m[1][3] * m2.m[0][1]
640 + m1.m[2][3] * m2.m[0][2]
641 + m1.m[3][3] * m2.m[0][3];
643 m.m[1][0] = m1.m[0][0] * m2.m[1][0]
644 + m1.m[1][0] * m2.m[1][1]
645 + m1.m[2][0] * m2.m[1][2]
646 + m1.m[3][0] * m2.m[1][3];
647 m.m[1][1] = m1.m[0][1] * m2.m[1][0]
648 + m1.m[1][1] * m2.m[1][1]
649 + m1.m[2][1] * m2.m[1][2]
650 + m1.m[3][1] * m2.m[1][3];
651 m.m[1][2] = m1.m[0][2] * m2.m[1][0]
652 + m1.m[1][2] * m2.m[1][1]
653 + m1.m[2][2] * m2.m[1][2]
654 + m1.m[3][2] * m2.m[1][3];
655 m.m[1][3] = m1.m[0][3] * m2.m[1][0]
656 + m1.m[1][3] * m2.m[1][1]
657 + m1.m[2][3] * m2.m[1][2]
658 + m1.m[3][3] * m2.m[1][3];
660 m.m[2][0] = m1.m[0][0] * m2.m[2][0]
661 + m1.m[1][0] * m2.m[2][1]
662 + m1.m[2][0] * m2.m[2][2]
663 + m1.m[3][0] * m2.m[2][3];
664 m.m[2][1] = m1.m[0][1] * m2.m[2][0]
665 + m1.m[1][1] * m2.m[2][1]
666 + m1.m[2][1] * m2.m[2][2]
667 + m1.m[3][1] * m2.m[2][3];
668 m.m[2][2] = m1.m[0][2] * m2.m[2][0]
669 + m1.m[1][2] * m2.m[2][1]
670 + m1.m[2][2] * m2.m[2][2]
671 + m1.m[3][2] * m2.m[2][3];
672 m.m[2][3] = m1.m[0][3] * m2.m[2][0]
673 + m1.m[1][3] * m2.m[2][1]
674 + m1.m[2][3] * m2.m[2][2]
675 + m1.m[3][3] * m2.m[2][3];
677 m.m[3][0] = m1.m[0][0] * m2.m[3][0]
678 + m1.m[1][0] * m2.m[3][1]
679 + m1.m[2][0] * m2.m[3][2]
680 + m1.m[3][0] * m2.m[3][3];
681 m.m[3][1] = m1.m[0][1] * m2.m[3][0]
682 + m1.m[1][1] * m2.m[3][1]
683 + m1.m[2][1] * m2.m[3][2]
684 + m1.m[3][1] * m2.m[3][3];
685 m.m[3][2] = m1.m[0][2] * m2.m[3][0]
686 + m1.m[1][2] * m2.m[3][1]
687 + m1.m[2][2] * m2.m[3][2]
688 + m1.m[3][2] * m2.m[3][3];
689 m.m[3][3] = m1.m[0][3] * m2.m[3][0]
690 + m1.m[1][3] * m2.m[3][1]
691 + m1.m[2][3] * m2.m[3][2]
692 + m1.m[3][3] * m2.m[3][3];
693 m.flagBits = flagBits;
742 x = vector.x() * matrix.m[0][0] +
743 vector.y() * matrix.m[0][1] +
744 vector.z() * matrix.m[0][2] +
745 vector.w() * matrix.m[0][3];
746 y = vector.x() * matrix.m[1][0] +
747 vector.y() * matrix.m[1][1] +
748 vector.z() * matrix.m[1][2] +
749 vector.w() * matrix.m[1][3];
750 z = vector.x() * matrix.m[2][0] +
751 vector.y() * matrix.m[2][1] +
752 vector.z() * matrix.m[2][2] +
753 vector.w() * matrix.m[2][3];
754 w = vector.x() * matrix.m[3][0] +
755 vector.y() * matrix.m[3][1] +
756 vector.z() * matrix.m[3][2] +
757 vector.w() * matrix.m[3][3];
758 return QVector4D(x, y, z, w);
764 x = vector.x() * matrix.m[0][0] +
765 vector.y() * matrix.m[1][0] +
766 vector.z() * matrix.m[2][0] +
767 vector.w() * matrix.m[3][0];
768 y = vector.x() * matrix.m[0][1] +
769 vector.y() * matrix.m[1][1] +
770 vector.z() * matrix.m[2][1] +
771 vector.w() * matrix.m[3][1];
772 z = vector.x() * matrix.m[0][2] +
773 vector.y() * matrix.m[1][2] +
774 vector.z() * matrix.m[2][2] +
775 vector.w() * matrix.m[3][2];
776 w = vector.x() * matrix.m[0][3] +
777 vector.y() * matrix.m[1][3] +
778 vector.z() * matrix.m[2][3] +
779 vector.w() * matrix.m[3][3];
780 return QVector4D(x, y, z, w);
847 m.m[0][0] = -matrix.m[0][0];
848 m.m[0][1] = -matrix.m[0][1];
849 m.m[0][2] = -matrix.m[0][2];
850 m.m[0][3] = -matrix.m[0][3];
851 m.m[1][0] = -matrix.m[1][0];
852 m.m[1][1] = -matrix.m[1][1];
853 m.m[1][2] = -matrix.m[1][2];
854 m.m[1][3] = -matrix.m[1][3];
855 m.m[2][0] = -matrix.m[2][0];
856 m.m[2][1] = -matrix.m[2][1];
857 m.m[2][2] = -matrix.m[2][2];
858 m.m[2][3] = -matrix.m[2][3];
859 m.m[3][0] = -matrix.m[3][0];
860 m.m[3][1] = -matrix.m[3][1];
861 m.m[3][2] = -matrix.m[3][2];
862 m.m[3][3] = -matrix.m[3][3];
869 m.m[0][0] = matrix.m[0][0] * factor;
870 m.m[0][1] = matrix.m[0][1] * factor;
871 m.m[0][2] = matrix.m[0][2] * factor;
872 m.m[0][3] = matrix.m[0][3] * factor;
873 m.m[1][0] = matrix.m[1][0] * factor;
874 m.m[1][1] = matrix.m[1][1] * factor;
875 m.m[1][2] = matrix.m[1][2] * factor;
876 m.m[1][3] = matrix.m[1][3] * factor;
877 m.m[2][0] = matrix.m[2][0] * factor;
878 m.m[2][1] = matrix.m[2][1] * factor;
879 m.m[2][2] = matrix.m[2][2] * factor;
880 m.m[2][3] = matrix.m[2][3] * factor;
881 m.m[3][0] = matrix.m[3][0] * factor;
882 m.m[3][1] = matrix.m[3][1] * factor;
883 m.m[3][2] = matrix.m[3][2] * factor;
884 m.m[3][3] = matrix.m[3][3] * factor;
891 m.m[0][0] = matrix.m[0][0] * factor;
892 m.m[0][1] = matrix.m[0][1] * factor;
893 m.m[0][2] = matrix.m[0][2] * factor;
894 m.m[0][3] = matrix.m[0][3] * factor;
895 m.m[1][0] = matrix.m[1][0] * factor;
896 m.m[1][1] = matrix.m[1][1] * factor;
897 m.m[1][2] = matrix.m[1][2] * factor;
898 m.m[1][3] = matrix.m[1][3] * factor;
899 m.m[2][0] = matrix.m[2][0] * factor;
900 m.m[2][1] = matrix.m[2][1] * factor;
901 m.m[2][2] = matrix.m[2][2] * factor;
902 m.m[2][3] = matrix.m[2][3] * factor;
903 m.m[3][0] = matrix.m[3][0] * factor;
904 m.m[3][1] = matrix.m[3][1] * factor;
905 m.m[3][2] = matrix.m[3][2] * factor;
906 m.m[3][3] = matrix.m[3][3] * factor;
910inline QPoint QMatrix4x4::map(
const QPoint& point)
const
916 if (flagBits == QMatrix4x4::Identity) {
918 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
920 return QPoint(qRound(xin * m[0][0] + m[3][0]),
921 qRound(yin * m[1][1] + m[3][1]));
922 }
else if (flagBits.toInt() < QMatrix4x4::Perspective) {
923 return QPoint(qRound(xin * m[0][0] + yin * m[1][0] + m[3][0]),
924 qRound(xin * m[0][1] + yin * m[1][1] + m[3][1]));
936 return QPoint(qRound(x), qRound(y));
938 return QPoint(qRound(x / w), qRound(y / w));
942inline QPointF QMatrix4x4::map(
const QPointF& point)
const
948 if (flagBits == QMatrix4x4::Identity) {
950 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
952 return QPointF(xin * qreal(m[0][0]) + qreal(m[3][0]),
953 yin * qreal(m[1][1]) + qreal(m[3][1]));
954 }
else if (flagBits.toInt() < QMatrix4x4::Perspective) {
955 return QPointF(xin * qreal(m[0][0]) + yin * qreal(m[1][0]) +
957 xin * qreal(m[0][1]) + yin * qreal(m[1][1]) +
960 x = xin * qreal(m[0][0]) +
961 yin * qreal(m[1][0]) +
963 y = xin * qreal(m[0][1]) +
964 yin * qreal(m[1][1]) +
966 w = xin * qreal(m[0][3]) +
967 yin * qreal(m[1][3]) +
970 return QPointF(qreal(x), qreal(y));
972 return QPointF(qreal(x / w), qreal(y / w));
979inline QVector3D QMatrix4x4::map(
const QVector3D& point)
const
982 if (flagBits == QMatrix4x4::Identity) {
984 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
986 return QVector3D(point.x() * m[0][0] + m[3][0],
987 point.y() * m[1][1] + m[3][1],
988 point.z() * m[2][2] + m[3][2]);
989 }
else if (flagBits.toInt() < QMatrix4x4::Rotation) {
991 return QVector3D(point.x() * m[0][0] + point.y() * m[1][0] + m[3][0],
992 point.x() * m[0][1] + point.y() * m[1][1] + m[3][1],
993 point.z() * m[2][2] + m[3][2]);
995 x = point.x() * m[0][0] +
996 point.y() * m[1][0] +
997 point.z() * m[2][0] +
999 y = point.x() * m[0][1] +
1000 point.y() * m[1][1] +
1001 point.z() * m[2][1] +
1003 z = point.x() * m[0][2] +
1004 point.y() * m[1][2] +
1005 point.z() * m[2][2] +
1007 w = point.x() * m[0][3] +
1008 point.y() * m[1][3] +
1009 point.z() * m[2][3] +
1012 return QVector3D(x, y, z);
1014 return QVector3D(x / w, y / w, z / w);