358inline QMatrix4x4& QMatrix4x4::operator+=(
const QMatrix4x4& other)
360 m[0][0] += other.m[0][0];
361 m[0][1] += other.m[0][1];
362 m[0][2] += other.m[0][2];
363 m[0][3] += other.m[0][3];
364 m[1][0] += other.m[1][0];
365 m[1][1] += other.m[1][1];
366 m[1][2] += other.m[1][2];
367 m[1][3] += other.m[1][3];
368 m[2][0] += other.m[2][0];
369 m[2][1] += other.m[2][1];
370 m[2][2] += other.m[2][2];
371 m[2][3] += other.m[2][3];
372 m[3][0] += other.m[3][0];
373 m[3][1] += other.m[3][1];
374 m[3][2] += other.m[3][2];
375 m[3][3] += other.m[3][3];
380inline QMatrix4x4& QMatrix4x4::operator-=(
const QMatrix4x4& other)
382 m[0][0] -= other.m[0][0];
383 m[0][1] -= other.m[0][1];
384 m[0][2] -= other.m[0][2];
385 m[0][3] -= other.m[0][3];
386 m[1][0] -= other.m[1][0];
387 m[1][1] -= other.m[1][1];
388 m[1][2] -= other.m[1][2];
389 m[1][3] -= other.m[1][3];
390 m[2][0] -= other.m[2][0];
391 m[2][1] -= other.m[2][1];
392 m[2][2] -= other.m[2][2];
393 m[2][3] -= other.m[2][3];
394 m[3][0] -= other.m[3][0];
395 m[3][1] -= other.m[3][1];
396 m[3][2] -= other.m[3][2];
397 m[3][3] -= other.m[3][3];
402inline QMatrix4x4& QMatrix4x4::operator*=(
const QMatrix4x4& o)
404 const QMatrix4x4 other = o;
405 flagBits |= other.flagBits;
407 if (flagBits.toInt() < Rotation2D) {
408 m[3][0] += m[0][0] * other.m[3][0];
409 m[3][1] += m[1][1] * other.m[3][1];
410 m[3][2] += m[2][2] * other.m[3][2];
412 m[0][0] *= other.m[0][0];
413 m[1][1] *= other.m[1][1];
414 m[2][2] *= other.m[2][2];
419 m0 = m[0][0] * other.m[0][0]
420 + m[1][0] * other.m[0][1]
421 + m[2][0] * other.m[0][2]
422 + m[3][0] * other.m[0][3];
423 m1 = m[0][0] * other.m[1][0]
424 + m[1][0] * other.m[1][1]
425 + m[2][0] * other.m[1][2]
426 + m[3][0] * other.m[1][3];
427 m2 = m[0][0] * other.m[2][0]
428 + m[1][0] * other.m[2][1]
429 + m[2][0] * other.m[2][2]
430 + m[3][0] * other.m[2][3];
431 m[3][0] = m[0][0] * other.m[3][0]
432 + m[1][0] * other.m[3][1]
433 + m[2][0] * other.m[3][2]
434 + m[3][0] * other.m[3][3];
439 m0 = m[0][1] * other.m[0][0]
440 + m[1][1] * other.m[0][1]
441 + m[2][1] * other.m[0][2]
442 + m[3][1] * other.m[0][3];
443 m1 = m[0][1] * other.m[1][0]
444 + m[1][1] * other.m[1][1]
445 + m[2][1] * other.m[1][2]
446 + m[3][1] * other.m[1][3];
447 m2 = m[0][1] * other.m[2][0]
448 + m[1][1] * other.m[2][1]
449 + m[2][1] * other.m[2][2]
450 + m[3][1] * other.m[2][3];
451 m[3][1] = m[0][1] * other.m[3][0]
452 + m[1][1] * other.m[3][1]
453 + m[2][1] * other.m[3][2]
454 + m[3][1] * other.m[3][3];
459 m0 = m[0][2] * other.m[0][0]
460 + m[1][2] * other.m[0][1]
461 + m[2][2] * other.m[0][2]
462 + m[3][2] * other.m[0][3];
463 m1 = m[0][2] * other.m[1][0]
464 + m[1][2] * other.m[1][1]
465 + m[2][2] * other.m[1][2]
466 + m[3][2] * other.m[1][3];
467 m2 = m[0][2] * other.m[2][0]
468 + m[1][2] * other.m[2][1]
469 + m[2][2] * other.m[2][2]
470 + m[3][2] * other.m[2][3];
471 m[3][2] = m[0][2] * other.m[3][0]
472 + m[1][2] * other.m[3][1]
473 + m[2][2] * other.m[3][2]
474 + m[3][2] * other.m[3][3];
479 m0 = m[0][3] * other.m[0][0]
480 + m[1][3] * other.m[0][1]
481 + m[2][3] * other.m[0][2]
482 + m[3][3] * other.m[0][3];
483 m1 = m[0][3] * other.m[1][0]
484 + m[1][3] * other.m[1][1]
485 + m[2][3] * other.m[1][2]
486 + m[3][3] * other.m[1][3];
487 m2 = m[0][3] * other.m[2][0]
488 + m[1][3] * other.m[2][1]
489 + m[2][3] * other.m[2][2]
490 + m[3][3] * other.m[2][3];
491 m[3][3] = m[0][3] * other.m[3][0]
492 + m[1][3] * other.m[3][1]
493 + m[2][3] * other.m[3][2]
494 + m[3][3] * other.m[3][3];
523inline bool QMatrix4x4::operator==(
const QMatrix4x4& other)
const
525 return m[0][0] == other.m[0][0] &&
526 m[0][1] == other.m[0][1] &&
527 m[0][2] == other.m[0][2] &&
528 m[0][3] == other.m[0][3] &&
529 m[1][0] == other.m[1][0] &&
530 m[1][1] == other.m[1][1] &&
531 m[1][2] == other.m[1][2] &&
532 m[1][3] == other.m[1][3] &&
533 m[2][0] == other.m[2][0] &&
534 m[2][1] == other.m[2][1] &&
535 m[2][2] == other.m[2][2] &&
536 m[2][3] == other.m[2][3] &&
537 m[3][0] == other.m[3][0] &&
538 m[3][1] == other.m[3][1] &&
539 m[3][2] == other.m[3][2] &&
540 m[3][3] == other.m[3][3];
543inline bool QMatrix4x4::operator!=(
const QMatrix4x4& other)
const
545 return m[0][0] != other.m[0][0] ||
546 m[0][1] != other.m[0][1] ||
547 m[0][2] != other.m[0][2] ||
548 m[0][3] != other.m[0][3] ||
549 m[1][0] != other.m[1][0] ||
550 m[1][1] != other.m[1][1] ||
551 m[1][2] != other.m[1][2] ||
552 m[1][3] != other.m[1][3] ||
553 m[2][0] != other.m[2][0] ||
554 m[2][1] != other.m[2][1] ||
555 m[2][2] != other.m[2][2] ||
556 m[2][3] != other.m[2][3] ||
557 m[3][0] != other.m[3][0] ||
558 m[3][1] != other.m[3][1] ||
559 m[3][2] != other.m[3][2] ||
560 m[3][3] != other.m[3][3];
566 m.m[0][0] = m1.m[0][0] + m2.m[0][0];
567 m.m[0][1] = m1.m[0][1] + m2.m[0][1];
568 m.m[0][2] = m1.m[0][2] + m2.m[0][2];
569 m.m[0][3] = m1.m[0][3] + m2.m[0][3];
570 m.m[1][0] = m1.m[1][0] + m2.m[1][0];
571 m.m[1][1] = m1.m[1][1] + m2.m[1][1];
572 m.m[1][2] = m1.m[1][2] + m2.m[1][2];
573 m.m[1][3] = m1.m[1][3] + m2.m[1][3];
574 m.m[2][0] = m1.m[2][0] + m2.m[2][0];
575 m.m[2][1] = m1.m[2][1] + m2.m[2][1];
576 m.m[2][2] = m1.m[2][2] + m2.m[2][2];
577 m.m[2][3] = m1.m[2][3] + m2.m[2][3];
578 m.m[3][0] = m1.m[3][0] + m2.m[3][0];
579 m.m[3][1] = m1.m[3][1] + m2.m[3][1];
580 m.m[3][2] = m1.m[3][2] + m2.m[3][2];
581 m.m[3][3] = m1.m[3][3] + m2.m[3][3];
588 m.m[0][0] = m1.m[0][0] - m2.m[0][0];
589 m.m[0][1] = m1.m[0][1] - m2.m[0][1];
590 m.m[0][2] = m1.m[0][2] - m2.m[0][2];
591 m.m[0][3] = m1.m[0][3] - m2.m[0][3];
592 m.m[1][0] = m1.m[1][0] - m2.m[1][0];
593 m.m[1][1] = m1.m[1][1] - m2.m[1][1];
594 m.m[1][2] = m1.m[1][2] - m2.m[1][2];
595 m.m[1][3] = m1.m[1][3] - m2.m[1][3];
596 m.m[2][0] = m1.m[2][0] - m2.m[2][0];
597 m.m[2][1] = m1.m[2][1] - m2.m[2][1];
598 m.m[2][2] = m1.m[2][2] - m2.m[2][2];
599 m.m[2][3] = m1.m[2][3] - m2.m[2][3];
600 m.m[3][0] = m1.m[3][0] - m2.m[3][0];
601 m.m[3][1] = m1.m[3][1] - m2.m[3][1];
602 m.m[3][2] = m1.m[3][2] - m2.m[3][2];
603 m.m[3][3] = m1.m[3][3] - m2.m[3][3];
609 QMatrix4x4::Flags flagBits = m1.flagBits | m2.flagBits;
610 if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
612 m.m[3][0] += m.m[0][0] * m2.m[3][0];
613 m.m[3][1] += m.m[1][1] * m2.m[3][1];
614 m.m[3][2] += m.m[2][2] * m2.m[3][2];
616 m.m[0][0] *= m2.m[0][0];
617 m.m[1][1] *= m2.m[1][1];
618 m.m[2][2] *= m2.m[2][2];
619 m.flagBits = flagBits;
624 m.m[0][0] = m1.m[0][0] * m2.m[0][0]
625 + m1.m[1][0] * m2.m[0][1]
626 + m1.m[2][0] * m2.m[0][2]
627 + m1.m[3][0] * m2.m[0][3];
628 m.m[0][1] = m1.m[0][1] * m2.m[0][0]
629 + m1.m[1][1] * m2.m[0][1]
630 + m1.m[2][1] * m2.m[0][2]
631 + m1.m[3][1] * m2.m[0][3];
632 m.m[0][2] = m1.m[0][2] * m2.m[0][0]
633 + m1.m[1][2] * m2.m[0][1]
634 + m1.m[2][2] * m2.m[0][2]
635 + m1.m[3][2] * m2.m[0][3];
636 m.m[0][3] = m1.m[0][3] * m2.m[0][0]
637 + m1.m[1][3] * m2.m[0][1]
638 + m1.m[2][3] * m2.m[0][2]
639 + m1.m[3][3] * m2.m[0][3];
641 m.m[1][0] = m1.m[0][0] * m2.m[1][0]
642 + m1.m[1][0] * m2.m[1][1]
643 + m1.m[2][0] * m2.m[1][2]
644 + m1.m[3][0] * m2.m[1][3];
645 m.m[1][1] = m1.m[0][1] * m2.m[1][0]
646 + m1.m[1][1] * m2.m[1][1]
647 + m1.m[2][1] * m2.m[1][2]
648 + m1.m[3][1] * m2.m[1][3];
649 m.m[1][2] = m1.m[0][2] * m2.m[1][0]
650 + m1.m[1][2] * m2.m[1][1]
651 + m1.m[2][2] * m2.m[1][2]
652 + m1.m[3][2] * m2.m[1][3];
653 m.m[1][3] = m1.m[0][3] * m2.m[1][0]
654 + m1.m[1][3] * m2.m[1][1]
655 + m1.m[2][3] * m2.m[1][2]
656 + m1.m[3][3] * m2.m[1][3];
658 m.m[2][0] = m1.m[0][0] * m2.m[2][0]
659 + m1.m[1][0] * m2.m[2][1]
660 + m1.m[2][0] * m2.m[2][2]
661 + m1.m[3][0] * m2.m[2][3];
662 m.m[2][1] = m1.m[0][1] * m2.m[2][0]
663 + m1.m[1][1] * m2.m[2][1]
664 + m1.m[2][1] * m2.m[2][2]
665 + m1.m[3][1] * m2.m[2][3];
666 m.m[2][2] = m1.m[0][2] * m2.m[2][0]
667 + m1.m[1][2] * m2.m[2][1]
668 + m1.m[2][2] * m2.m[2][2]
669 + m1.m[3][2] * m2.m[2][3];
670 m.m[2][3] = m1.m[0][3] * m2.m[2][0]
671 + m1.m[1][3] * m2.m[2][1]
672 + m1.m[2][3] * m2.m[2][2]
673 + m1.m[3][3] * m2.m[2][3];
675 m.m[3][0] = m1.m[0][0] * m2.m[3][0]
676 + m1.m[1][0] * m2.m[3][1]
677 + m1.m[2][0] * m2.m[3][2]
678 + m1.m[3][0] * m2.m[3][3];
679 m.m[3][1] = m1.m[0][1] * m2.m[3][0]
680 + m1.m[1][1] * m2.m[3][1]
681 + m1.m[2][1] * m2.m[3][2]
682 + m1.m[3][1] * m2.m[3][3];
683 m.m[3][2] = m1.m[0][2] * m2.m[3][0]
684 + m1.m[1][2] * m2.m[3][1]
685 + m1.m[2][2] * m2.m[3][2]
686 + m1.m[3][2] * m2.m[3][3];
687 m.m[3][3] = m1.m[0][3] * m2.m[3][0]
688 + m1.m[1][3] * m2.m[3][1]
689 + m1.m[2][3] * m2.m[3][2]
690 + m1.m[3][3] * m2.m[3][3];
691 m.flagBits = flagBits;
740 x = vector.x() * matrix.m[0][0] +
741 vector.y() * matrix.m[0][1] +
742 vector.z() * matrix.m[0][2] +
743 vector.w() * matrix.m[0][3];
744 y = vector.x() * matrix.m[1][0] +
745 vector.y() * matrix.m[1][1] +
746 vector.z() * matrix.m[1][2] +
747 vector.w() * matrix.m[1][3];
748 z = vector.x() * matrix.m[2][0] +
749 vector.y() * matrix.m[2][1] +
750 vector.z() * matrix.m[2][2] +
751 vector.w() * matrix.m[2][3];
752 w = vector.x() * matrix.m[3][0] +
753 vector.y() * matrix.m[3][1] +
754 vector.z() * matrix.m[3][2] +
755 vector.w() * matrix.m[3][3];
756 return QVector4D(x, y, z, w);
762 x = vector.x() * matrix.m[0][0] +
763 vector.y() * matrix.m[1][0] +
764 vector.z() * matrix.m[2][0] +
765 vector.w() * matrix.m[3][0];
766 y = vector.x() * matrix.m[0][1] +
767 vector.y() * matrix.m[1][1] +
768 vector.z() * matrix.m[2][1] +
769 vector.w() * matrix.m[3][1];
770 z = vector.x() * matrix.m[0][2] +
771 vector.y() * matrix.m[1][2] +
772 vector.z() * matrix.m[2][2] +
773 vector.w() * matrix.m[3][2];
774 w = vector.x() * matrix.m[0][3] +
775 vector.y() * matrix.m[1][3] +
776 vector.z() * matrix.m[2][3] +
777 vector.w() * matrix.m[3][3];
778 return QVector4D(x, y, z, w);
845 m.m[0][0] = -matrix.m[0][0];
846 m.m[0][1] = -matrix.m[0][1];
847 m.m[0][2] = -matrix.m[0][2];
848 m.m[0][3] = -matrix.m[0][3];
849 m.m[1][0] = -matrix.m[1][0];
850 m.m[1][1] = -matrix.m[1][1];
851 m.m[1][2] = -matrix.m[1][2];
852 m.m[1][3] = -matrix.m[1][3];
853 m.m[2][0] = -matrix.m[2][0];
854 m.m[2][1] = -matrix.m[2][1];
855 m.m[2][2] = -matrix.m[2][2];
856 m.m[2][3] = -matrix.m[2][3];
857 m.m[3][0] = -matrix.m[3][0];
858 m.m[3][1] = -matrix.m[3][1];
859 m.m[3][2] = -matrix.m[3][2];
860 m.m[3][3] = -matrix.m[3][3];
867 m.m[0][0] = matrix.m[0][0] * factor;
868 m.m[0][1] = matrix.m[0][1] * factor;
869 m.m[0][2] = matrix.m[0][2] * factor;
870 m.m[0][3] = matrix.m[0][3] * factor;
871 m.m[1][0] = matrix.m[1][0] * factor;
872 m.m[1][1] = matrix.m[1][1] * factor;
873 m.m[1][2] = matrix.m[1][2] * factor;
874 m.m[1][3] = matrix.m[1][3] * factor;
875 m.m[2][0] = matrix.m[2][0] * factor;
876 m.m[2][1] = matrix.m[2][1] * factor;
877 m.m[2][2] = matrix.m[2][2] * factor;
878 m.m[2][3] = matrix.m[2][3] * factor;
879 m.m[3][0] = matrix.m[3][0] * factor;
880 m.m[3][1] = matrix.m[3][1] * factor;
881 m.m[3][2] = matrix.m[3][2] * factor;
882 m.m[3][3] = matrix.m[3][3] * factor;
889 m.m[0][0] = matrix.m[0][0] * factor;
890 m.m[0][1] = matrix.m[0][1] * factor;
891 m.m[0][2] = matrix.m[0][2] * factor;
892 m.m[0][3] = matrix.m[0][3] * factor;
893 m.m[1][0] = matrix.m[1][0] * factor;
894 m.m[1][1] = matrix.m[1][1] * factor;
895 m.m[1][2] = matrix.m[1][2] * factor;
896 m.m[1][3] = matrix.m[1][3] * factor;
897 m.m[2][0] = matrix.m[2][0] * factor;
898 m.m[2][1] = matrix.m[2][1] * factor;
899 m.m[2][2] = matrix.m[2][2] * factor;
900 m.m[2][3] = matrix.m[2][3] * factor;
901 m.m[3][0] = matrix.m[3][0] * factor;
902 m.m[3][1] = matrix.m[3][1] * factor;
903 m.m[3][2] = matrix.m[3][2] * factor;
904 m.m[3][3] = matrix.m[3][3] * factor;
908inline QPoint QMatrix4x4::map(
const QPoint& point)
const
914 if (flagBits == QMatrix4x4::Identity) {
916 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
918 return QPoint(qRound(xin * m[0][0] + m[3][0]),
919 qRound(yin * m[1][1] + m[3][1]));
920 }
else if (flagBits.toInt() < QMatrix4x4::Perspective) {
921 return QPoint(qRound(xin * m[0][0] + yin * m[1][0] + m[3][0]),
922 qRound(xin * m[0][1] + yin * m[1][1] + m[3][1]));
934 return QPoint(qRound(x), qRound(y));
936 return QPoint(qRound(x / w), qRound(y / w));
940inline QPointF QMatrix4x4::map(
const QPointF& point)
const
946 if (flagBits == QMatrix4x4::Identity) {
948 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
950 return QPointF(xin * qreal(m[0][0]) + qreal(m[3][0]),
951 yin * qreal(m[1][1]) + qreal(m[3][1]));
952 }
else if (flagBits.toInt() < QMatrix4x4::Perspective) {
953 return QPointF(xin * qreal(m[0][0]) + yin * qreal(m[1][0]) +
955 xin * qreal(m[0][1]) + yin * qreal(m[1][1]) +
958 x = xin * qreal(m[0][0]) +
959 yin * qreal(m[1][0]) +
961 y = xin * qreal(m[0][1]) +
962 yin * qreal(m[1][1]) +
964 w = xin * qreal(m[0][3]) +
965 yin * qreal(m[1][3]) +
968 return QPointF(qreal(x), qreal(y));
970 return QPointF(qreal(x / w), qreal(y / w));
977inline QVector3D QMatrix4x4::map(
const QVector3D& point)
const
980 if (flagBits == QMatrix4x4::Identity) {
982 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
984 return QVector3D(point.x() * m[0][0] + m[3][0],
985 point.y() * m[1][1] + m[3][1],
986 point.z() * m[2][2] + m[3][2]);
987 }
else if (flagBits.toInt() < QMatrix4x4::Rotation) {
989 return QVector3D(point.x() * m[0][0] + point.y() * m[1][0] + m[3][0],
990 point.x() * m[0][1] + point.y() * m[1][1] + m[3][1],
991 point.z() * m[2][2] + m[3][2]);
993 x = point.x() * m[0][0] +
994 point.y() * m[1][0] +
995 point.z() * m[2][0] +
997 y = point.x() * m[0][1] +
998 point.y() * m[1][1] +
999 point.z() * m[2][1] +
1001 z = point.x() * m[0][2] +
1002 point.y() * m[1][2] +
1003 point.z() * m[2][2] +
1005 w = point.x() * m[0][3] +
1006 point.y() * m[1][3] +
1007 point.z() * m[2][3] +
1010 return QVector3D(x, y, z);
1012 return QVector3D(x / w, y / w, z / w);