353inline QMatrix4x4& QMatrix4x4::operator+=(
const QMatrix4x4& other)
355 m[0][0] += other.m[0][0];
356 m[0][1] += other.m[0][1];
357 m[0][2] += other.m[0][2];
358 m[0][3] += other.m[0][3];
359 m[1][0] += other.m[1][0];
360 m[1][1] += other.m[1][1];
361 m[1][2] += other.m[1][2];
362 m[1][3] += other.m[1][3];
363 m[2][0] += other.m[2][0];
364 m[2][1] += other.m[2][1];
365 m[2][2] += other.m[2][2];
366 m[2][3] += other.m[2][3];
367 m[3][0] += other.m[3][0];
368 m[3][1] += other.m[3][1];
369 m[3][2] += other.m[3][2];
370 m[3][3] += other.m[3][3];
375inline QMatrix4x4& QMatrix4x4::operator-=(
const QMatrix4x4& other)
377 m[0][0] -= other.m[0][0];
378 m[0][1] -= other.m[0][1];
379 m[0][2] -= other.m[0][2];
380 m[0][3] -= other.m[0][3];
381 m[1][0] -= other.m[1][0];
382 m[1][1] -= other.m[1][1];
383 m[1][2] -= other.m[1][2];
384 m[1][3] -= other.m[1][3];
385 m[2][0] -= other.m[2][0];
386 m[2][1] -= other.m[2][1];
387 m[2][2] -= other.m[2][2];
388 m[2][3] -= other.m[2][3];
389 m[3][0] -= other.m[3][0];
390 m[3][1] -= other.m[3][1];
391 m[3][2] -= other.m[3][2];
392 m[3][3] -= other.m[3][3];
397inline QMatrix4x4& QMatrix4x4::operator*=(
const QMatrix4x4& o)
399 const QMatrix4x4 other = o;
400 flagBits |= other.flagBits;
402 if (flagBits.toInt() < Rotation2D) {
403 m[3][0] += m[0][0] * other.m[3][0];
404 m[3][1] += m[1][1] * other.m[3][1];
405 m[3][2] += m[2][2] * other.m[3][2];
407 m[0][0] *= other.m[0][0];
408 m[1][1] *= other.m[1][1];
409 m[2][2] *= other.m[2][2];
414 m0 = m[0][0] * other.m[0][0]
415 + m[1][0] * other.m[0][1]
416 + m[2][0] * other.m[0][2]
417 + m[3][0] * other.m[0][3];
418 m1 = m[0][0] * other.m[1][0]
419 + m[1][0] * other.m[1][1]
420 + m[2][0] * other.m[1][2]
421 + m[3][0] * other.m[1][3];
422 m2 = m[0][0] * other.m[2][0]
423 + m[1][0] * other.m[2][1]
424 + m[2][0] * other.m[2][2]
425 + m[3][0] * other.m[2][3];
426 m[3][0] = m[0][0] * other.m[3][0]
427 + m[1][0] * other.m[3][1]
428 + m[2][0] * other.m[3][2]
429 + m[3][0] * other.m[3][3];
434 m0 = m[0][1] * other.m[0][0]
435 + m[1][1] * other.m[0][1]
436 + m[2][1] * other.m[0][2]
437 + m[3][1] * other.m[0][3];
438 m1 = m[0][1] * other.m[1][0]
439 + m[1][1] * other.m[1][1]
440 + m[2][1] * other.m[1][2]
441 + m[3][1] * other.m[1][3];
442 m2 = m[0][1] * other.m[2][0]
443 + m[1][1] * other.m[2][1]
444 + m[2][1] * other.m[2][2]
445 + m[3][1] * other.m[2][3];
446 m[3][1] = m[0][1] * other.m[3][0]
447 + m[1][1] * other.m[3][1]
448 + m[2][1] * other.m[3][2]
449 + m[3][1] * other.m[3][3];
454 m0 = m[0][2] * other.m[0][0]
455 + m[1][2] * other.m[0][1]
456 + m[2][2] * other.m[0][2]
457 + m[3][2] * other.m[0][3];
458 m1 = m[0][2] * other.m[1][0]
459 + m[1][2] * other.m[1][1]
460 + m[2][2] * other.m[1][2]
461 + m[3][2] * other.m[1][3];
462 m2 = m[0][2] * other.m[2][0]
463 + m[1][2] * other.m[2][1]
464 + m[2][2] * other.m[2][2]
465 + m[3][2] * other.m[2][3];
466 m[3][2] = m[0][2] * other.m[3][0]
467 + m[1][2] * other.m[3][1]
468 + m[2][2] * other.m[3][2]
469 + m[3][2] * other.m[3][3];
474 m0 = m[0][3] * other.m[0][0]
475 + m[1][3] * other.m[0][1]
476 + m[2][3] * other.m[0][2]
477 + m[3][3] * other.m[0][3];
478 m1 = m[0][3] * other.m[1][0]
479 + m[1][3] * other.m[1][1]
480 + m[2][3] * other.m[1][2]
481 + m[3][3] * other.m[1][3];
482 m2 = m[0][3] * other.m[2][0]
483 + m[1][3] * other.m[2][1]
484 + m[2][3] * other.m[2][2]
485 + m[3][3] * other.m[2][3];
486 m[3][3] = m[0][3] * other.m[3][0]
487 + m[1][3] * other.m[3][1]
488 + m[2][3] * other.m[3][2]
489 + m[3][3] * other.m[3][3];
518inline bool QMatrix4x4::operator==(
const QMatrix4x4& other)
const
520 return m[0][0] == other.m[0][0] &&
521 m[0][1] == other.m[0][1] &&
522 m[0][2] == other.m[0][2] &&
523 m[0][3] == other.m[0][3] &&
524 m[1][0] == other.m[1][0] &&
525 m[1][1] == other.m[1][1] &&
526 m[1][2] == other.m[1][2] &&
527 m[1][3] == other.m[1][3] &&
528 m[2][0] == other.m[2][0] &&
529 m[2][1] == other.m[2][1] &&
530 m[2][2] == other.m[2][2] &&
531 m[2][3] == other.m[2][3] &&
532 m[3][0] == other.m[3][0] &&
533 m[3][1] == other.m[3][1] &&
534 m[3][2] == other.m[3][2] &&
535 m[3][3] == other.m[3][3];
538inline bool QMatrix4x4::operator!=(
const QMatrix4x4& other)
const
540 return m[0][0] != other.m[0][0] ||
541 m[0][1] != other.m[0][1] ||
542 m[0][2] != other.m[0][2] ||
543 m[0][3] != other.m[0][3] ||
544 m[1][0] != other.m[1][0] ||
545 m[1][1] != other.m[1][1] ||
546 m[1][2] != other.m[1][2] ||
547 m[1][3] != other.m[1][3] ||
548 m[2][0] != other.m[2][0] ||
549 m[2][1] != other.m[2][1] ||
550 m[2][2] != other.m[2][2] ||
551 m[2][3] != other.m[2][3] ||
552 m[3][0] != other.m[3][0] ||
553 m[3][1] != other.m[3][1] ||
554 m[3][2] != other.m[3][2] ||
555 m[3][3] != other.m[3][3];
561 QMatrix4x4 m(Qt::Uninitialized);
562 m.m[0][0] = m1.m[0][0] + m2.m[0][0];
563 m.m[0][1] = m1.m[0][1] + m2.m[0][1];
564 m.m[0][2] = m1.m[0][2] + m2.m[0][2];
565 m.m[0][3] = m1.m[0][3] + m2.m[0][3];
566 m.m[1][0] = m1.m[1][0] + m2.m[1][0];
567 m.m[1][1] = m1.m[1][1] + m2.m[1][1];
568 m.m[1][2] = m1.m[1][2] + m2.m[1][2];
569 m.m[1][3] = m1.m[1][3] + m2.m[1][3];
570 m.m[2][0] = m1.m[2][0] + m2.m[2][0];
571 m.m[2][1] = m1.m[2][1] + m2.m[2][1];
572 m.m[2][2] = m1.m[2][2] + m2.m[2][2];
573 m.m[2][3] = m1.m[2][3] + m2.m[2][3];
574 m.m[3][0] = m1.m[3][0] + m2.m[3][0];
575 m.m[3][1] = m1.m[3][1] + m2.m[3][1];
576 m.m[3][2] = m1.m[3][2] + m2.m[3][2];
577 m.m[3][3] = m1.m[3][3] + m2.m[3][3];
584 QMatrix4x4 m(Qt::Uninitialized);
585 m.m[0][0] = m1.m[0][0] - m2.m[0][0];
586 m.m[0][1] = m1.m[0][1] - m2.m[0][1];
587 m.m[0][2] = m1.m[0][2] - m2.m[0][2];
588 m.m[0][3] = m1.m[0][3] - m2.m[0][3];
589 m.m[1][0] = m1.m[1][0] - m2.m[1][0];
590 m.m[1][1] = m1.m[1][1] - m2.m[1][1];
591 m.m[1][2] = m1.m[1][2] - m2.m[1][2];
592 m.m[1][3] = m1.m[1][3] - m2.m[1][3];
593 m.m[2][0] = m1.m[2][0] - m2.m[2][0];
594 m.m[2][1] = m1.m[2][1] - m2.m[2][1];
595 m.m[2][2] = m1.m[2][2] - m2.m[2][2];
596 m.m[2][3] = m1.m[2][3] - m2.m[2][3];
597 m.m[3][0] = m1.m[3][0] - m2.m[3][0];
598 m.m[3][1] = m1.m[3][1] - m2.m[3][1];
599 m.m[3][2] = m1.m[3][2] - m2.m[3][2];
600 m.m[3][3] = m1.m[3][3] - m2.m[3][3];
607 QMatrix4x4 m(Qt::Uninitialized);
608 QMatrix4x4::Flags flagBits = m1.flagBits | m2.flagBits;
609 if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
611 m.m[0][0] = m1.m[0][0] * m2.m[0][0];
617 m.m[1][1] = m1.m[1][1] * m2.m[1][1];
623 m.m[2][2] = m1.m[2][2] * m2.m[2][2];
626 m.m[3][0] = m1.m[3][0] + m1.m[0][0] * m2.m[3][0];
627 m.m[3][1] = m1.m[3][1] + m1.m[1][1] * m2.m[3][1];
628 m.m[3][2] = m1.m[3][2] + m1.m[2][2] * m2.m[3][2];
630 m.flagBits = flagBits;
634 m.m[0][0] = m1.m[0][0] * m2.m[0][0]
635 + m1.m[1][0] * m2.m[0][1]
636 + m1.m[2][0] * m2.m[0][2]
637 + m1.m[3][0] * m2.m[0][3];
638 m.m[0][1] = m1.m[0][1] * m2.m[0][0]
639 + m1.m[1][1] * m2.m[0][1]
640 + m1.m[2][1] * m2.m[0][2]
641 + m1.m[3][1] * m2.m[0][3];
642 m.m[0][2] = m1.m[0][2] * m2.m[0][0]
643 + m1.m[1][2] * m2.m[0][1]
644 + m1.m[2][2] * m2.m[0][2]
645 + m1.m[3][2] * m2.m[0][3];
646 m.m[0][3] = m1.m[0][3] * m2.m[0][0]
647 + m1.m[1][3] * m2.m[0][1]
648 + m1.m[2][3] * m2.m[0][2]
649 + m1.m[3][3] * m2.m[0][3];
651 m.m[1][0] = m1.m[0][0] * m2.m[1][0]
652 + m1.m[1][0] * m2.m[1][1]
653 + m1.m[2][0] * m2.m[1][2]
654 + m1.m[3][0] * m2.m[1][3];
655 m.m[1][1] = m1.m[0][1] * m2.m[1][0]
656 + m1.m[1][1] * m2.m[1][1]
657 + m1.m[2][1] * m2.m[1][2]
658 + m1.m[3][1] * m2.m[1][3];
659 m.m[1][2] = m1.m[0][2] * m2.m[1][0]
660 + m1.m[1][2] * m2.m[1][1]
661 + m1.m[2][2] * m2.m[1][2]
662 + m1.m[3][2] * m2.m[1][3];
663 m.m[1][3] = m1.m[0][3] * m2.m[1][0]
664 + m1.m[1][3] * m2.m[1][1]
665 + m1.m[2][3] * m2.m[1][2]
666 + m1.m[3][3] * m2.m[1][3];
668 m.m[2][0] = m1.m[0][0] * m2.m[2][0]
669 + m1.m[1][0] * m2.m[2][1]
670 + m1.m[2][0] * m2.m[2][2]
671 + m1.m[3][0] * m2.m[2][3];
672 m.m[2][1] = m1.m[0][1] * m2.m[2][0]
673 + m1.m[1][1] * m2.m[2][1]
674 + m1.m[2][1] * m2.m[2][2]
675 + m1.m[3][1] * m2.m[2][3];
676 m.m[2][2] = m1.m[0][2] * m2.m[2][0]
677 + m1.m[1][2] * m2.m[2][1]
678 + m1.m[2][2] * m2.m[2][2]
679 + m1.m[3][2] * m2.m[2][3];
680 m.m[2][3] = m1.m[0][3] * m2.m[2][0]
681 + m1.m[1][3] * m2.m[2][1]
682 + m1.m[2][3] * m2.m[2][2]
683 + m1.m[3][3] * m2.m[2][3];
685 m.m[3][0] = m1.m[0][0] * m2.m[3][0]
686 + m1.m[1][0] * m2.m[3][1]
687 + m1.m[2][0] * m2.m[3][2]
688 + m1.m[3][0] * m2.m[3][3];
689 m.m[3][1] = m1.m[0][1] * m2.m[3][0]
690 + m1.m[1][1] * m2.m[3][1]
691 + m1.m[2][1] * m2.m[3][2]
692 + m1.m[3][1] * m2.m[3][3];
693 m.m[3][2] = m1.m[0][2] * m2.m[3][0]
694 + m1.m[1][2] * m2.m[3][1]
695 + m1.m[2][2] * m2.m[3][2]
696 + m1.m[3][2] * m2.m[3][3];
697 m.m[3][3] = m1.m[0][3] * m2.m[3][0]
698 + m1.m[1][3] * m2.m[3][1]
699 + m1.m[2][3] * m2.m[3][2]
700 + m1.m[3][3] * m2.m[3][3];
701 m.flagBits = flagBits;
750 x = vector.x() * matrix.m[0][0] +
751 vector.y() * matrix.m[0][1] +
752 vector.z() * matrix.m[0][2] +
753 vector.w() * matrix.m[0][3];
754 y = vector.x() * matrix.m[1][0] +
755 vector.y() * matrix.m[1][1] +
756 vector.z() * matrix.m[1][2] +
757 vector.w() * matrix.m[1][3];
758 z = vector.x() * matrix.m[2][0] +
759 vector.y() * matrix.m[2][1] +
760 vector.z() * matrix.m[2][2] +
761 vector.w() * matrix.m[2][3];
762 w = vector.x() * matrix.m[3][0] +
763 vector.y() * matrix.m[3][1] +
764 vector.z() * matrix.m[3][2] +
765 vector.w() * matrix.m[3][3];
766 return QVector4D(x, y, z, w);
772 x = vector.x() * matrix.m[0][0] +
773 vector.y() * matrix.m[1][0] +
774 vector.z() * matrix.m[2][0] +
775 vector.w() * matrix.m[3][0];
776 y = vector.x() * matrix.m[0][1] +
777 vector.y() * matrix.m[1][1] +
778 vector.z() * matrix.m[2][1] +
779 vector.w() * matrix.m[3][1];
780 z = vector.x() * matrix.m[0][2] +
781 vector.y() * matrix.m[1][2] +
782 vector.z() * matrix.m[2][2] +
783 vector.w() * matrix.m[3][2];
784 w = vector.x() * matrix.m[0][3] +
785 vector.y() * matrix.m[1][3] +
786 vector.z() * matrix.m[2][3] +
787 vector.w() * matrix.m[3][3];
788 return QVector4D(x, y, z, w);
855 QMatrix4x4 m(Qt::Uninitialized);
856 m.m[0][0] = -matrix.m[0][0];
857 m.m[0][1] = -matrix.m[0][1];
858 m.m[0][2] = -matrix.m[0][2];
859 m.m[0][3] = -matrix.m[0][3];
860 m.m[1][0] = -matrix.m[1][0];
861 m.m[1][1] = -matrix.m[1][1];
862 m.m[1][2] = -matrix.m[1][2];
863 m.m[1][3] = -matrix.m[1][3];
864 m.m[2][0] = -matrix.m[2][0];
865 m.m[2][1] = -matrix.m[2][1];
866 m.m[2][2] = -matrix.m[2][2];
867 m.m[2][3] = -matrix.m[2][3];
868 m.m[3][0] = -matrix.m[3][0];
869 m.m[3][1] = -matrix.m[3][1];
870 m.m[3][2] = -matrix.m[3][2];
871 m.m[3][3] = -matrix.m[3][3];
878 QMatrix4x4 m(Qt::Uninitialized);
879 m.m[0][0] = matrix.m[0][0] * factor;
880 m.m[0][1] = matrix.m[0][1] * factor;
881 m.m[0][2] = matrix.m[0][2] * factor;
882 m.m[0][3] = matrix.m[0][3] * factor;
883 m.m[1][0] = matrix.m[1][0] * factor;
884 m.m[1][1] = matrix.m[1][1] * factor;
885 m.m[1][2] = matrix.m[1][2] * factor;
886 m.m[1][3] = matrix.m[1][3] * factor;
887 m.m[2][0] = matrix.m[2][0] * factor;
888 m.m[2][1] = matrix.m[2][1] * factor;
889 m.m[2][2] = matrix.m[2][2] * factor;
890 m.m[2][3] = matrix.m[2][3] * factor;
891 m.m[3][0] = matrix.m[3][0] * factor;
892 m.m[3][1] = matrix.m[3][1] * factor;
893 m.m[3][2] = matrix.m[3][2] * factor;
894 m.m[3][3] = matrix.m[3][3] * factor;
901 QMatrix4x4 m(Qt::Uninitialized);
902 m.m[0][0] = matrix.m[0][0] * factor;
903 m.m[0][1] = matrix.m[0][1] * factor;
904 m.m[0][2] = matrix.m[0][2] * factor;
905 m.m[0][3] = matrix.m[0][3] * factor;
906 m.m[1][0] = matrix.m[1][0] * factor;
907 m.m[1][1] = matrix.m[1][1] * factor;
908 m.m[1][2] = matrix.m[1][2] * factor;
909 m.m[1][3] = matrix.m[1][3] * factor;
910 m.m[2][0] = matrix.m[2][0] * factor;
911 m.m[2][1] = matrix.m[2][1] * factor;
912 m.m[2][2] = matrix.m[2][2] * factor;
913 m.m[2][3] = matrix.m[2][3] * factor;
914 m.m[3][0] = matrix.m[3][0] * factor;
915 m.m[3][1] = matrix.m[3][1] * factor;
916 m.m[3][2] = matrix.m[3][2] * factor;
917 m.m[3][3] = matrix.m[3][3] * factor;
921inline QPoint QMatrix4x4::map(
const QPoint& point)
const
927 if (flagBits == QMatrix4x4::Identity) {
929 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
931 return QPoint(qRound(xin * m[0][0] + m[3][0]),
932 qRound(yin * m[1][1] + m[3][1]));
933 }
else if (flagBits.toInt() < QMatrix4x4::Perspective) {
934 return QPoint(qRound(xin * m[0][0] + yin * m[1][0] + m[3][0]),
935 qRound(xin * m[0][1] + yin * m[1][1] + m[3][1]));
947 return QPoint(qRound(x), qRound(y));
949 return QPoint(qRound(x / w), qRound(y / w));
953inline QPointF QMatrix4x4::map(
const QPointF& point)
const
959 if (flagBits == QMatrix4x4::Identity) {
961 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
963 return QPointF(xin * qreal(m[0][0]) + qreal(m[3][0]),
964 yin * qreal(m[1][1]) + qreal(m[3][1]));
965 }
else if (flagBits.toInt() < QMatrix4x4::Perspective) {
966 return QPointF(xin * qreal(m[0][0]) + yin * qreal(m[1][0]) +
968 xin * qreal(m[0][1]) + yin * qreal(m[1][1]) +
971 x = xin * qreal(m[0][0]) +
972 yin * qreal(m[1][0]) +
974 y = xin * qreal(m[0][1]) +
975 yin * qreal(m[1][1]) +
977 w = xin * qreal(m[0][3]) +
978 yin * qreal(m[1][3]) +
981 return QPointF(qreal(x), qreal(y));
983 return QPointF(qreal(x / w), qreal(y / w));
990inline QVector3D QMatrix4x4::map(
const QVector3D& point)
const
993 if (flagBits == QMatrix4x4::Identity) {
995 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
997 return QVector3D(point.x() * m[0][0] + m[3][0],
998 point.y() * m[1][1] + m[3][1],
999 point.z() * m[2][2] + m[3][2]);
1000 }
else if (flagBits.toInt() < QMatrix4x4::Rotation) {
1002 return QVector3D(point.x() * m[0][0] + point.y() * m[1][0] + m[3][0],
1003 point.x() * m[0][1] + point.y() * m[1][1] + m[3][1],
1004 point.z() * m[2][2] + m[3][2]);
1006 x = point.x() * m[0][0] +
1007 point.y() * m[1][0] +
1008 point.z() * m[2][0] +
1010 y = point.x() * m[0][1] +
1011 point.y() * m[1][1] +
1012 point.z() * m[2][1] +
1014 z = point.x() * m[0][2] +
1015 point.y() * m[1][2] +
1016 point.z() * m[2][2] +
1018 w = point.x() * m[0][3] +
1019 point.y() * m[1][3] +
1020 point.z() * m[2][3] +
1023 return QVector3D(x, y, z);
1025 return QVector3D(x / w, y / w, z / w);