361inline QMatrix4x4& QMatrix4x4::operator+=(
const QMatrix4x4& other)
363 m[0][0] += other.m[0][0];
364 m[0][1] += other.m[0][1];
365 m[0][2] += other.m[0][2];
366 m[0][3] += other.m[0][3];
367 m[1][0] += other.m[1][0];
368 m[1][1] += other.m[1][1];
369 m[1][2] += other.m[1][2];
370 m[1][3] += other.m[1][3];
371 m[2][0] += other.m[2][0];
372 m[2][1] += other.m[2][1];
373 m[2][2] += other.m[2][2];
374 m[2][3] += other.m[2][3];
375 m[3][0] += other.m[3][0];
376 m[3][1] += other.m[3][1];
377 m[3][2] += other.m[3][2];
378 m[3][3] += other.m[3][3];
383inline QMatrix4x4& QMatrix4x4::operator-=(
const QMatrix4x4& other)
385 m[0][0] -= other.m[0][0];
386 m[0][1] -= other.m[0][1];
387 m[0][2] -= other.m[0][2];
388 m[0][3] -= other.m[0][3];
389 m[1][0] -= other.m[1][0];
390 m[1][1] -= other.m[1][1];
391 m[1][2] -= other.m[1][2];
392 m[1][3] -= other.m[1][3];
393 m[2][0] -= other.m[2][0];
394 m[2][1] -= other.m[2][1];
395 m[2][2] -= other.m[2][2];
396 m[2][3] -= other.m[2][3];
397 m[3][0] -= other.m[3][0];
398 m[3][1] -= other.m[3][1];
399 m[3][2] -= other.m[3][2];
400 m[3][3] -= other.m[3][3];
405inline QMatrix4x4& QMatrix4x4::operator*=(
const QMatrix4x4& o)
407 const QMatrix4x4 other = o;
408 flagBits |= other.flagBits;
410 if (flagBits.toInt() < Rotation2D) {
411 m[3][0] += m[0][0] * other.m[3][0];
412 m[3][1] += m[1][1] * other.m[3][1];
413 m[3][2] += m[2][2] * other.m[3][2];
415 m[0][0] *= other.m[0][0];
416 m[1][1] *= other.m[1][1];
417 m[2][2] *= other.m[2][2];
422 m0 = m[0][0] * other.m[0][0]
423 + m[1][0] * other.m[0][1]
424 + m[2][0] * other.m[0][2]
425 + m[3][0] * other.m[0][3];
426 m1 = m[0][0] * other.m[1][0]
427 + m[1][0] * other.m[1][1]
428 + m[2][0] * other.m[1][2]
429 + m[3][0] * other.m[1][3];
430 m2 = m[0][0] * other.m[2][0]
431 + m[1][0] * other.m[2][1]
432 + m[2][0] * other.m[2][2]
433 + m[3][0] * other.m[2][3];
434 m[3][0] = m[0][0] * other.m[3][0]
435 + m[1][0] * other.m[3][1]
436 + m[2][0] * other.m[3][2]
437 + m[3][0] * other.m[3][3];
442 m0 = m[0][1] * other.m[0][0]
443 + m[1][1] * other.m[0][1]
444 + m[2][1] * other.m[0][2]
445 + m[3][1] * other.m[0][3];
446 m1 = m[0][1] * other.m[1][0]
447 + m[1][1] * other.m[1][1]
448 + m[2][1] * other.m[1][2]
449 + m[3][1] * other.m[1][3];
450 m2 = m[0][1] * other.m[2][0]
451 + m[1][1] * other.m[2][1]
452 + m[2][1] * other.m[2][2]
453 + m[3][1] * other.m[2][3];
454 m[3][1] = m[0][1] * other.m[3][0]
455 + m[1][1] * other.m[3][1]
456 + m[2][1] * other.m[3][2]
457 + m[3][1] * other.m[3][3];
462 m0 = m[0][2] * other.m[0][0]
463 + m[1][2] * other.m[0][1]
464 + m[2][2] * other.m[0][2]
465 + m[3][2] * other.m[0][3];
466 m1 = m[0][2] * other.m[1][0]
467 + m[1][2] * other.m[1][1]
468 + m[2][2] * other.m[1][2]
469 + m[3][2] * other.m[1][3];
470 m2 = m[0][2] * other.m[2][0]
471 + m[1][2] * other.m[2][1]
472 + m[2][2] * other.m[2][2]
473 + m[3][2] * other.m[2][3];
474 m[3][2] = m[0][2] * other.m[3][0]
475 + m[1][2] * other.m[3][1]
476 + m[2][2] * other.m[3][2]
477 + m[3][2] * other.m[3][3];
482 m0 = m[0][3] * other.m[0][0]
483 + m[1][3] * other.m[0][1]
484 + m[2][3] * other.m[0][2]
485 + m[3][3] * other.m[0][3];
486 m1 = m[0][3] * other.m[1][0]
487 + m[1][3] * other.m[1][1]
488 + m[2][3] * other.m[1][2]
489 + m[3][3] * other.m[1][3];
490 m2 = m[0][3] * other.m[2][0]
491 + m[1][3] * other.m[2][1]
492 + m[2][3] * other.m[2][2]
493 + m[3][3] * other.m[2][3];
494 m[3][3] = m[0][3] * other.m[3][0]
495 + m[1][3] * other.m[3][1]
496 + m[2][3] * other.m[3][2]
497 + m[3][3] * other.m[3][3];
526inline bool QMatrix4x4::operator==(
const QMatrix4x4& other)
const
528 return m[0][0] == other.m[0][0] &&
529 m[0][1] == other.m[0][1] &&
530 m[0][2] == other.m[0][2] &&
531 m[0][3] == other.m[0][3] &&
532 m[1][0] == other.m[1][0] &&
533 m[1][1] == other.m[1][1] &&
534 m[1][2] == other.m[1][2] &&
535 m[1][3] == other.m[1][3] &&
536 m[2][0] == other.m[2][0] &&
537 m[2][1] == other.m[2][1] &&
538 m[2][2] == other.m[2][2] &&
539 m[2][3] == other.m[2][3] &&
540 m[3][0] == other.m[3][0] &&
541 m[3][1] == other.m[3][1] &&
542 m[3][2] == other.m[3][2] &&
543 m[3][3] == other.m[3][3];
546inline bool QMatrix4x4::operator!=(
const QMatrix4x4& other)
const
548 return m[0][0] != other.m[0][0] ||
549 m[0][1] != other.m[0][1] ||
550 m[0][2] != other.m[0][2] ||
551 m[0][3] != other.m[0][3] ||
552 m[1][0] != other.m[1][0] ||
553 m[1][1] != other.m[1][1] ||
554 m[1][2] != other.m[1][2] ||
555 m[1][3] != other.m[1][3] ||
556 m[2][0] != other.m[2][0] ||
557 m[2][1] != other.m[2][1] ||
558 m[2][2] != other.m[2][2] ||
559 m[2][3] != other.m[2][3] ||
560 m[3][0] != other.m[3][0] ||
561 m[3][1] != other.m[3][1] ||
562 m[3][2] != other.m[3][2] ||
563 m[3][3] != other.m[3][3];
569 QMatrix4x4 m(Qt::Uninitialized);
570 m.m[0][0] = m1.m[0][0] + m2.m[0][0];
571 m.m[0][1] = m1.m[0][1] + m2.m[0][1];
572 m.m[0][2] = m1.m[0][2] + m2.m[0][2];
573 m.m[0][3] = m1.m[0][3] + m2.m[0][3];
574 m.m[1][0] = m1.m[1][0] + m2.m[1][0];
575 m.m[1][1] = m1.m[1][1] + m2.m[1][1];
576 m.m[1][2] = m1.m[1][2] + m2.m[1][2];
577 m.m[1][3] = m1.m[1][3] + m2.m[1][3];
578 m.m[2][0] = m1.m[2][0] + m2.m[2][0];
579 m.m[2][1] = m1.m[2][1] + m2.m[2][1];
580 m.m[2][2] = m1.m[2][2] + m2.m[2][2];
581 m.m[2][3] = m1.m[2][3] + m2.m[2][3];
582 m.m[3][0] = m1.m[3][0] + m2.m[3][0];
583 m.m[3][1] = m1.m[3][1] + m2.m[3][1];
584 m.m[3][2] = m1.m[3][2] + m2.m[3][2];
585 m.m[3][3] = m1.m[3][3] + m2.m[3][3];
592 QMatrix4x4 m(Qt::Uninitialized);
593 m.m[0][0] = m1.m[0][0] - m2.m[0][0];
594 m.m[0][1] = m1.m[0][1] - m2.m[0][1];
595 m.m[0][2] = m1.m[0][2] - m2.m[0][2];
596 m.m[0][3] = m1.m[0][3] - m2.m[0][3];
597 m.m[1][0] = m1.m[1][0] - m2.m[1][0];
598 m.m[1][1] = m1.m[1][1] - m2.m[1][1];
599 m.m[1][2] = m1.m[1][2] - m2.m[1][2];
600 m.m[1][3] = m1.m[1][3] - m2.m[1][3];
601 m.m[2][0] = m1.m[2][0] - m2.m[2][0];
602 m.m[2][1] = m1.m[2][1] - m2.m[2][1];
603 m.m[2][2] = m1.m[2][2] - m2.m[2][2];
604 m.m[2][3] = m1.m[2][3] - m2.m[2][3];
605 m.m[3][0] = m1.m[3][0] - m2.m[3][0];
606 m.m[3][1] = m1.m[3][1] - m2.m[3][1];
607 m.m[3][2] = m1.m[3][2] - m2.m[3][2];
608 m.m[3][3] = m1.m[3][3] - m2.m[3][3];
615 QMatrix4x4 m(Qt::Uninitialized);
616 QMatrix4x4::Flags flagBits = m1.flagBits | m2.flagBits;
617 if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
619 m.m[0][0] = m1.m[0][0] * m2.m[0][0];
625 m.m[1][1] = m1.m[1][1] * m2.m[1][1];
631 m.m[2][2] = m1.m[2][2] * m2.m[2][2];
634 m.m[3][0] = m1.m[3][0] + m1.m[0][0] * m2.m[3][0];
635 m.m[3][1] = m1.m[3][1] + m1.m[1][1] * m2.m[3][1];
636 m.m[3][2] = m1.m[3][2] + m1.m[2][2] * m2.m[3][2];
638 m.flagBits = flagBits;
642 m.m[0][0] = m1.m[0][0] * m2.m[0][0]
643 + m1.m[1][0] * m2.m[0][1]
644 + m1.m[2][0] * m2.m[0][2]
645 + m1.m[3][0] * m2.m[0][3];
646 m.m[0][1] = m1.m[0][1] * m2.m[0][0]
647 + m1.m[1][1] * m2.m[0][1]
648 + m1.m[2][1] * m2.m[0][2]
649 + m1.m[3][1] * m2.m[0][3];
650 m.m[0][2] = m1.m[0][2] * m2.m[0][0]
651 + m1.m[1][2] * m2.m[0][1]
652 + m1.m[2][2] * m2.m[0][2]
653 + m1.m[3][2] * m2.m[0][3];
654 m.m[0][3] = m1.m[0][3] * m2.m[0][0]
655 + m1.m[1][3] * m2.m[0][1]
656 + m1.m[2][3] * m2.m[0][2]
657 + m1.m[3][3] * m2.m[0][3];
659 m.m[1][0] = m1.m[0][0] * m2.m[1][0]
660 + m1.m[1][0] * m2.m[1][1]
661 + m1.m[2][0] * m2.m[1][2]
662 + m1.m[3][0] * m2.m[1][3];
663 m.m[1][1] = m1.m[0][1] * m2.m[1][0]
664 + m1.m[1][1] * m2.m[1][1]
665 + m1.m[2][1] * m2.m[1][2]
666 + m1.m[3][1] * m2.m[1][3];
667 m.m[1][2] = m1.m[0][2] * m2.m[1][0]
668 + m1.m[1][2] * m2.m[1][1]
669 + m1.m[2][2] * m2.m[1][2]
670 + m1.m[3][2] * m2.m[1][3];
671 m.m[1][3] = m1.m[0][3] * m2.m[1][0]
672 + m1.m[1][3] * m2.m[1][1]
673 + m1.m[2][3] * m2.m[1][2]
674 + m1.m[3][3] * m2.m[1][3];
676 m.m[2][0] = m1.m[0][0] * m2.m[2][0]
677 + m1.m[1][0] * m2.m[2][1]
678 + m1.m[2][0] * m2.m[2][2]
679 + m1.m[3][0] * m2.m[2][3];
680 m.m[2][1] = m1.m[0][1] * m2.m[2][0]
681 + m1.m[1][1] * m2.m[2][1]
682 + m1.m[2][1] * m2.m[2][2]
683 + m1.m[3][1] * m2.m[2][3];
684 m.m[2][2] = m1.m[0][2] * m2.m[2][0]
685 + m1.m[1][2] * m2.m[2][1]
686 + m1.m[2][2] * m2.m[2][2]
687 + m1.m[3][2] * m2.m[2][3];
688 m.m[2][3] = m1.m[0][3] * m2.m[2][0]
689 + m1.m[1][3] * m2.m[2][1]
690 + m1.m[2][3] * m2.m[2][2]
691 + m1.m[3][3] * m2.m[2][3];
693 m.m[3][0] = m1.m[0][0] * m2.m[3][0]
694 + m1.m[1][0] * m2.m[3][1]
695 + m1.m[2][0] * m2.m[3][2]
696 + m1.m[3][0] * m2.m[3][3];
697 m.m[3][1] = m1.m[0][1] * m2.m[3][0]
698 + m1.m[1][1] * m2.m[3][1]
699 + m1.m[2][1] * m2.m[3][2]
700 + m1.m[3][1] * m2.m[3][3];
701 m.m[3][2] = m1.m[0][2] * m2.m[3][0]
702 + m1.m[1][2] * m2.m[3][1]
703 + m1.m[2][2] * m2.m[3][2]
704 + m1.m[3][2] * m2.m[3][3];
705 m.m[3][3] = m1.m[0][3] * m2.m[3][0]
706 + m1.m[1][3] * m2.m[3][1]
707 + m1.m[2][3] * m2.m[3][2]
708 + m1.m[3][3] * m2.m[3][3];
709 m.flagBits = flagBits;
758 x = vector.x() * matrix.m[0][0] +
759 vector.y() * matrix.m[0][1] +
760 vector.z() * matrix.m[0][2] +
761 vector.w() * matrix.m[0][3];
762 y = vector.x() * matrix.m[1][0] +
763 vector.y() * matrix.m[1][1] +
764 vector.z() * matrix.m[1][2] +
765 vector.w() * matrix.m[1][3];
766 z = vector.x() * matrix.m[2][0] +
767 vector.y() * matrix.m[2][1] +
768 vector.z() * matrix.m[2][2] +
769 vector.w() * matrix.m[2][3];
770 w = vector.x() * matrix.m[3][0] +
771 vector.y() * matrix.m[3][1] +
772 vector.z() * matrix.m[3][2] +
773 vector.w() * matrix.m[3][3];
774 return QVector4D(x, y, z, w);
780 x = vector.x() * matrix.m[0][0] +
781 vector.y() * matrix.m[1][0] +
782 vector.z() * matrix.m[2][0] +
783 vector.w() * matrix.m[3][0];
784 y = vector.x() * matrix.m[0][1] +
785 vector.y() * matrix.m[1][1] +
786 vector.z() * matrix.m[2][1] +
787 vector.w() * matrix.m[3][1];
788 z = vector.x() * matrix.m[0][2] +
789 vector.y() * matrix.m[1][2] +
790 vector.z() * matrix.m[2][2] +
791 vector.w() * matrix.m[3][2];
792 w = vector.x() * matrix.m[0][3] +
793 vector.y() * matrix.m[1][3] +
794 vector.z() * matrix.m[2][3] +
795 vector.w() * matrix.m[3][3];
796 return QVector4D(x, y, z, w);
863 QMatrix4x4 m(Qt::Uninitialized);
864 m.m[0][0] = -matrix.m[0][0];
865 m.m[0][1] = -matrix.m[0][1];
866 m.m[0][2] = -matrix.m[0][2];
867 m.m[0][3] = -matrix.m[0][3];
868 m.m[1][0] = -matrix.m[1][0];
869 m.m[1][1] = -matrix.m[1][1];
870 m.m[1][2] = -matrix.m[1][2];
871 m.m[1][3] = -matrix.m[1][3];
872 m.m[2][0] = -matrix.m[2][0];
873 m.m[2][1] = -matrix.m[2][1];
874 m.m[2][2] = -matrix.m[2][2];
875 m.m[2][3] = -matrix.m[2][3];
876 m.m[3][0] = -matrix.m[3][0];
877 m.m[3][1] = -matrix.m[3][1];
878 m.m[3][2] = -matrix.m[3][2];
879 m.m[3][3] = -matrix.m[3][3];
886 QMatrix4x4 m(Qt::Uninitialized);
887 m.m[0][0] = matrix.m[0][0] * factor;
888 m.m[0][1] = matrix.m[0][1] * factor;
889 m.m[0][2] = matrix.m[0][2] * factor;
890 m.m[0][3] = matrix.m[0][3] * factor;
891 m.m[1][0] = matrix.m[1][0] * factor;
892 m.m[1][1] = matrix.m[1][1] * factor;
893 m.m[1][2] = matrix.m[1][2] * factor;
894 m.m[1][3] = matrix.m[1][3] * factor;
895 m.m[2][0] = matrix.m[2][0] * factor;
896 m.m[2][1] = matrix.m[2][1] * factor;
897 m.m[2][2] = matrix.m[2][2] * factor;
898 m.m[2][3] = matrix.m[2][3] * factor;
899 m.m[3][0] = matrix.m[3][0] * factor;
900 m.m[3][1] = matrix.m[3][1] * factor;
901 m.m[3][2] = matrix.m[3][2] * factor;
902 m.m[3][3] = matrix.m[3][3] * factor;
909 QMatrix4x4 m(Qt::Uninitialized);
910 m.m[0][0] = matrix.m[0][0] * factor;
911 m.m[0][1] = matrix.m[0][1] * factor;
912 m.m[0][2] = matrix.m[0][2] * factor;
913 m.m[0][3] = matrix.m[0][3] * factor;
914 m.m[1][0] = matrix.m[1][0] * factor;
915 m.m[1][1] = matrix.m[1][1] * factor;
916 m.m[1][2] = matrix.m[1][2] * factor;
917 m.m[1][3] = matrix.m[1][3] * factor;
918 m.m[2][0] = matrix.m[2][0] * factor;
919 m.m[2][1] = matrix.m[2][1] * factor;
920 m.m[2][2] = matrix.m[2][2] * factor;
921 m.m[2][3] = matrix.m[2][3] * factor;
922 m.m[3][0] = matrix.m[3][0] * factor;
923 m.m[3][1] = matrix.m[3][1] * factor;
924 m.m[3][2] = matrix.m[3][2] * factor;
925 m.m[3][3] = matrix.m[3][3] * factor;
929inline QPoint QMatrix4x4::map(
const QPoint& point)
const
935 if (flagBits == QMatrix4x4::Identity) {
937 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
939 return QPoint(qRound(xin * m[0][0] + m[3][0]),
940 qRound(yin * m[1][1] + m[3][1]));
941 }
else if (flagBits.toInt() < QMatrix4x4::Perspective) {
942 return QPoint(qRound(xin * m[0][0] + yin * m[1][0] + m[3][0]),
943 qRound(xin * m[0][1] + yin * m[1][1] + m[3][1]));
955 return QPoint(qRound(x), qRound(y));
957 return QPoint(qRound(x / w), qRound(y / w));
961inline QPointF QMatrix4x4::map(
const QPointF& point)
const
967 if (flagBits == QMatrix4x4::Identity) {
969 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
971 return QPointF(xin * qreal(m[0][0]) + qreal(m[3][0]),
972 yin * qreal(m[1][1]) + qreal(m[3][1]));
973 }
else if (flagBits.toInt() < QMatrix4x4::Perspective) {
974 return QPointF(xin * qreal(m[0][0]) + yin * qreal(m[1][0]) +
976 xin * qreal(m[0][1]) + yin * qreal(m[1][1]) +
979 x = xin * qreal(m[0][0]) +
980 yin * qreal(m[1][0]) +
982 y = xin * qreal(m[0][1]) +
983 yin * qreal(m[1][1]) +
985 w = xin * qreal(m[0][3]) +
986 yin * qreal(m[1][3]) +
989 return QPointF(qreal(x), qreal(y));
991 return QPointF(qreal(x / w), qreal(y / w));
998inline QVector3D QMatrix4x4::map(
const QVector3D& point)
const
1001 if (flagBits == QMatrix4x4::Identity) {
1003 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
1005 return QVector3D(point.x() * m[0][0] + m[3][0],
1006 point.y() * m[1][1] + m[3][1],
1007 point.z() * m[2][2] + m[3][2]);
1008 }
else if (flagBits.toInt() < QMatrix4x4::Rotation) {
1010 return QVector3D(point.x() * m[0][0] + point.y() * m[1][0] + m[3][0],
1011 point.x() * m[0][1] + point.y() * m[1][1] + m[3][1],
1012 point.z() * m[2][2] + m[3][2]);
1014 x = point.x() * m[0][0] +
1015 point.y() * m[1][0] +
1016 point.z() * m[2][0] +
1018 y = point.x() * m[0][1] +
1019 point.y() * m[1][1] +
1020 point.z() * m[2][1] +
1022 z = point.x() * m[0][2] +
1023 point.y() * m[1][2] +
1024 point.z() * m[2][2] +
1026 w = point.x() * m[0][3] +
1027 point.y() * m[1][3] +
1028 point.z() * m[2][3] +
1031 return QVector3D(x, y, z);
1033 return QVector3D(x / w, y / w, z / w);