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 QMatrix4x4 m(Qt::Uninitialized);
569 m.m[0][0] = m1.m[0][0] + m2.m[0][0];
570 m.m[0][1] = m1.m[0][1] + m2.m[0][1];
571 m.m[0][2] = m1.m[0][2] + m2.m[0][2];
572 m.m[0][3] = m1.m[0][3] + m2.m[0][3];
573 m.m[1][0] = m1.m[1][0] + m2.m[1][0];
574 m.m[1][1] = m1.m[1][1] + m2.m[1][1];
575 m.m[1][2] = m1.m[1][2] + m2.m[1][2];
576 m.m[1][3] = m1.m[1][3] + m2.m[1][3];
577 m.m[2][0] = m1.m[2][0] + m2.m[2][0];
578 m.m[2][1] = m1.m[2][1] + m2.m[2][1];
579 m.m[2][2] = m1.m[2][2] + m2.m[2][2];
580 m.m[2][3] = m1.m[2][3] + m2.m[2][3];
581 m.m[3][0] = m1.m[3][0] + m2.m[3][0];
582 m.m[3][1] = m1.m[3][1] + m2.m[3][1];
583 m.m[3][2] = m1.m[3][2] + m2.m[3][2];
584 m.m[3][3] = m1.m[3][3] + m2.m[3][3];
591 QMatrix4x4 m(Qt::Uninitialized);
592 m.m[0][0] = m1.m[0][0] - m2.m[0][0];
593 m.m[0][1] = m1.m[0][1] - m2.m[0][1];
594 m.m[0][2] = m1.m[0][2] - m2.m[0][2];
595 m.m[0][3] = m1.m[0][3] - m2.m[0][3];
596 m.m[1][0] = m1.m[1][0] - m2.m[1][0];
597 m.m[1][1] = m1.m[1][1] - m2.m[1][1];
598 m.m[1][2] = m1.m[1][2] - m2.m[1][2];
599 m.m[1][3] = m1.m[1][3] - m2.m[1][3];
600 m.m[2][0] = m1.m[2][0] - m2.m[2][0];
601 m.m[2][1] = m1.m[2][1] - m2.m[2][1];
602 m.m[2][2] = m1.m[2][2] - m2.m[2][2];
603 m.m[2][3] = m1.m[2][3] - m2.m[2][3];
604 m.m[3][0] = m1.m[3][0] - m2.m[3][0];
605 m.m[3][1] = m1.m[3][1] - m2.m[3][1];
606 m.m[3][2] = m1.m[3][2] - m2.m[3][2];
607 m.m[3][3] = m1.m[3][3] - m2.m[3][3];
614 QMatrix4x4 m(Qt::Uninitialized);
615 QMatrix4x4::Flags flagBits = m1.flagBits | m2.flagBits;
616 if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
618 m.m[0][0] = m1.m[0][0] * m2.m[0][0];
624 m.m[1][1] = m1.m[1][1] * m2.m[1][1];
630 m.m[2][2] = m1.m[2][2] * m2.m[2][2];
633 m.m[3][0] = m1.m[3][0] + m1.m[0][0] * m2.m[3][0];
634 m.m[3][1] = m1.m[3][1] + m1.m[1][1] * m2.m[3][1];
635 m.m[3][2] = m1.m[3][2] + m1.m[2][2] * m2.m[3][2];
637 m.flagBits = flagBits;
641 m.m[0][0] = m1.m[0][0] * m2.m[0][0]
642 + m1.m[1][0] * m2.m[0][1]
643 + m1.m[2][0] * m2.m[0][2]
644 + m1.m[3][0] * m2.m[0][3];
645 m.m[0][1] = m1.m[0][1] * m2.m[0][0]
646 + m1.m[1][1] * m2.m[0][1]
647 + m1.m[2][1] * m2.m[0][2]
648 + m1.m[3][1] * m2.m[0][3];
649 m.m[0][2] = m1.m[0][2] * m2.m[0][0]
650 + m1.m[1][2] * m2.m[0][1]
651 + m1.m[2][2] * m2.m[0][2]
652 + m1.m[3][2] * m2.m[0][3];
653 m.m[0][3] = m1.m[0][3] * m2.m[0][0]
654 + m1.m[1][3] * m2.m[0][1]
655 + m1.m[2][3] * m2.m[0][2]
656 + m1.m[3][3] * m2.m[0][3];
658 m.m[1][0] = m1.m[0][0] * m2.m[1][0]
659 + m1.m[1][0] * m2.m[1][1]
660 + m1.m[2][0] * m2.m[1][2]
661 + m1.m[3][0] * m2.m[1][3];
662 m.m[1][1] = m1.m[0][1] * m2.m[1][0]
663 + m1.m[1][1] * m2.m[1][1]
664 + m1.m[2][1] * m2.m[1][2]
665 + m1.m[3][1] * m2.m[1][3];
666 m.m[1][2] = m1.m[0][2] * m2.m[1][0]
667 + m1.m[1][2] * m2.m[1][1]
668 + m1.m[2][2] * m2.m[1][2]
669 + m1.m[3][2] * m2.m[1][3];
670 m.m[1][3] = m1.m[0][3] * m2.m[1][0]
671 + m1.m[1][3] * m2.m[1][1]
672 + m1.m[2][3] * m2.m[1][2]
673 + m1.m[3][3] * m2.m[1][3];
675 m.m[2][0] = m1.m[0][0] * m2.m[2][0]
676 + m1.m[1][0] * m2.m[2][1]
677 + m1.m[2][0] * m2.m[2][2]
678 + m1.m[3][0] * m2.m[2][3];
679 m.m[2][1] = m1.m[0][1] * m2.m[2][0]
680 + m1.m[1][1] * m2.m[2][1]
681 + m1.m[2][1] * m2.m[2][2]
682 + m1.m[3][1] * m2.m[2][3];
683 m.m[2][2] = m1.m[0][2] * m2.m[2][0]
684 + m1.m[1][2] * m2.m[2][1]
685 + m1.m[2][2] * m2.m[2][2]
686 + m1.m[3][2] * m2.m[2][3];
687 m.m[2][3] = m1.m[0][3] * m2.m[2][0]
688 + m1.m[1][3] * m2.m[2][1]
689 + m1.m[2][3] * m2.m[2][2]
690 + m1.m[3][3] * m2.m[2][3];
692 m.m[3][0] = m1.m[0][0] * m2.m[3][0]
693 + m1.m[1][0] * m2.m[3][1]
694 + m1.m[2][0] * m2.m[3][2]
695 + m1.m[3][0] * m2.m[3][3];
696 m.m[3][1] = m1.m[0][1] * m2.m[3][0]
697 + m1.m[1][1] * m2.m[3][1]
698 + m1.m[2][1] * m2.m[3][2]
699 + m1.m[3][1] * m2.m[3][3];
700 m.m[3][2] = m1.m[0][2] * m2.m[3][0]
701 + m1.m[1][2] * m2.m[3][1]
702 + m1.m[2][2] * m2.m[3][2]
703 + m1.m[3][2] * m2.m[3][3];
704 m.m[3][3] = m1.m[0][3] * m2.m[3][0]
705 + m1.m[1][3] * m2.m[3][1]
706 + m1.m[2][3] * m2.m[3][2]
707 + m1.m[3][3] * m2.m[3][3];
708 m.flagBits = flagBits;
757 x = vector.x() * matrix.m[0][0] +
758 vector.y() * matrix.m[0][1] +
759 vector.z() * matrix.m[0][2] +
760 vector.w() * matrix.m[0][3];
761 y = vector.x() * matrix.m[1][0] +
762 vector.y() * matrix.m[1][1] +
763 vector.z() * matrix.m[1][2] +
764 vector.w() * matrix.m[1][3];
765 z = vector.x() * matrix.m[2][0] +
766 vector.y() * matrix.m[2][1] +
767 vector.z() * matrix.m[2][2] +
768 vector.w() * matrix.m[2][3];
769 w = vector.x() * matrix.m[3][0] +
770 vector.y() * matrix.m[3][1] +
771 vector.z() * matrix.m[3][2] +
772 vector.w() * matrix.m[3][3];
773 return QVector4D(x, y, z, w);
779 x = vector.x() * matrix.m[0][0] +
780 vector.y() * matrix.m[1][0] +
781 vector.z() * matrix.m[2][0] +
782 vector.w() * matrix.m[3][0];
783 y = vector.x() * matrix.m[0][1] +
784 vector.y() * matrix.m[1][1] +
785 vector.z() * matrix.m[2][1] +
786 vector.w() * matrix.m[3][1];
787 z = vector.x() * matrix.m[0][2] +
788 vector.y() * matrix.m[1][2] +
789 vector.z() * matrix.m[2][2] +
790 vector.w() * matrix.m[3][2];
791 w = vector.x() * matrix.m[0][3] +
792 vector.y() * matrix.m[1][3] +
793 vector.z() * matrix.m[2][3] +
794 vector.w() * matrix.m[3][3];
795 return QVector4D(x, y, z, w);
862 QMatrix4x4 m(Qt::Uninitialized);
863 m.m[0][0] = -matrix.m[0][0];
864 m.m[0][1] = -matrix.m[0][1];
865 m.m[0][2] = -matrix.m[0][2];
866 m.m[0][3] = -matrix.m[0][3];
867 m.m[1][0] = -matrix.m[1][0];
868 m.m[1][1] = -matrix.m[1][1];
869 m.m[1][2] = -matrix.m[1][2];
870 m.m[1][3] = -matrix.m[1][3];
871 m.m[2][0] = -matrix.m[2][0];
872 m.m[2][1] = -matrix.m[2][1];
873 m.m[2][2] = -matrix.m[2][2];
874 m.m[2][3] = -matrix.m[2][3];
875 m.m[3][0] = -matrix.m[3][0];
876 m.m[3][1] = -matrix.m[3][1];
877 m.m[3][2] = -matrix.m[3][2];
878 m.m[3][3] = -matrix.m[3][3];
885 QMatrix4x4 m(Qt::Uninitialized);
886 m.m[0][0] = matrix.m[0][0] * factor;
887 m.m[0][1] = matrix.m[0][1] * factor;
888 m.m[0][2] = matrix.m[0][2] * factor;
889 m.m[0][3] = matrix.m[0][3] * factor;
890 m.m[1][0] = matrix.m[1][0] * factor;
891 m.m[1][1] = matrix.m[1][1] * factor;
892 m.m[1][2] = matrix.m[1][2] * factor;
893 m.m[1][3] = matrix.m[1][3] * factor;
894 m.m[2][0] = matrix.m[2][0] * factor;
895 m.m[2][1] = matrix.m[2][1] * factor;
896 m.m[2][2] = matrix.m[2][2] * factor;
897 m.m[2][3] = matrix.m[2][3] * factor;
898 m.m[3][0] = matrix.m[3][0] * factor;
899 m.m[3][1] = matrix.m[3][1] * factor;
900 m.m[3][2] = matrix.m[3][2] * factor;
901 m.m[3][3] = matrix.m[3][3] * factor;
908 QMatrix4x4 m(Qt::Uninitialized);
909 m.m[0][0] = matrix.m[0][0] * factor;
910 m.m[0][1] = matrix.m[0][1] * factor;
911 m.m[0][2] = matrix.m[0][2] * factor;
912 m.m[0][3] = matrix.m[0][3] * factor;
913 m.m[1][0] = matrix.m[1][0] * factor;
914 m.m[1][1] = matrix.m[1][1] * factor;
915 m.m[1][2] = matrix.m[1][2] * factor;
916 m.m[1][3] = matrix.m[1][3] * factor;
917 m.m[2][0] = matrix.m[2][0] * factor;
918 m.m[2][1] = matrix.m[2][1] * factor;
919 m.m[2][2] = matrix.m[2][2] * factor;
920 m.m[2][3] = matrix.m[2][3] * factor;
921 m.m[3][0] = matrix.m[3][0] * factor;
922 m.m[3][1] = matrix.m[3][1] * factor;
923 m.m[3][2] = matrix.m[3][2] * factor;
924 m.m[3][3] = matrix.m[3][3] * factor;
928inline QPoint QMatrix4x4::map(
const QPoint& point)
const
934 if (flagBits == QMatrix4x4::Identity) {
936 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
938 return QPoint(qRound(xin * m[0][0] + m[3][0]),
939 qRound(yin * m[1][1] + m[3][1]));
940 }
else if (flagBits.toInt() < QMatrix4x4::Perspective) {
941 return QPoint(qRound(xin * m[0][0] + yin * m[1][0] + m[3][0]),
942 qRound(xin * m[0][1] + yin * m[1][1] + m[3][1]));
954 return QPoint(qRound(x), qRound(y));
956 return QPoint(qRound(x / w), qRound(y / w));
960inline QPointF QMatrix4x4::map(
const QPointF& point)
const
966 if (flagBits == QMatrix4x4::Identity) {
968 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
970 return QPointF(xin * qreal(m[0][0]) + qreal(m[3][0]),
971 yin * qreal(m[1][1]) + qreal(m[3][1]));
972 }
else if (flagBits.toInt() < QMatrix4x4::Perspective) {
973 return QPointF(xin * qreal(m[0][0]) + yin * qreal(m[1][0]) +
975 xin * qreal(m[0][1]) + yin * qreal(m[1][1]) +
978 x = xin * qreal(m[0][0]) +
979 yin * qreal(m[1][0]) +
981 y = xin * qreal(m[0][1]) +
982 yin * qreal(m[1][1]) +
984 w = xin * qreal(m[0][3]) +
985 yin * qreal(m[1][3]) +
988 return QPointF(qreal(x), qreal(y));
990 return QPointF(qreal(x / w), qreal(y / w));
997inline QVector3D QMatrix4x4::map(
const QVector3D& point)
const
1000 if (flagBits == QMatrix4x4::Identity) {
1002 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
1004 return QVector3D(point.x() * m[0][0] + m[3][0],
1005 point.y() * m[1][1] + m[3][1],
1006 point.z() * m[2][2] + m[3][2]);
1007 }
else if (flagBits.toInt() < QMatrix4x4::Rotation) {
1009 return QVector3D(point.x() * m[0][0] + point.y() * m[1][0] + m[3][0],
1010 point.x() * m[0][1] + point.y() * m[1][1] + m[3][1],
1011 point.z() * m[2][2] + m[3][2]);
1013 x = point.x() * m[0][0] +
1014 point.y() * m[1][0] +
1015 point.z() * m[2][0] +
1017 y = point.x() * m[0][1] +
1018 point.y() * m[1][1] +
1019 point.z() * m[2][1] +
1021 z = point.x() * m[0][2] +
1022 point.y() * m[1][2] +
1023 point.z() * m[2][2] +
1025 w = point.x() * m[0][3] +
1026 point.y() * m[1][3] +
1027 point.z() * m[2][3] +
1030 return QVector3D(x, y, z);
1032 return QVector3D(x / w, y / w, z / w);