338inline QMatrix4x4& QMatrix4x4::operator+=(
const QMatrix4x4& other)
340 m[0][0] += other.m[0][0];
341 m[0][1] += other.m[0][1];
342 m[0][2] += other.m[0][2];
343 m[0][3] += other.m[0][3];
344 m[1][0] += other.m[1][0];
345 m[1][1] += other.m[1][1];
346 m[1][2] += other.m[1][2];
347 m[1][3] += other.m[1][3];
348 m[2][0] += other.m[2][0];
349 m[2][1] += other.m[2][1];
350 m[2][2] += other.m[2][2];
351 m[2][3] += other.m[2][3];
352 m[3][0] += other.m[3][0];
353 m[3][1] += other.m[3][1];
354 m[3][2] += other.m[3][2];
355 m[3][3] += other.m[3][3];
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& o)
384 const QMatrix4x4 other = o;
385 flagBits |= other.flagBits;
387 if (flagBits.toInt() < Rotation2D) {
388 m[3][0] += m[0][0] * other.m[3][0];
389 m[3][1] += m[1][1] * other.m[3][1];
390 m[3][2] += m[2][2] * other.m[3][2];
392 m[0][0] *= other.m[0][0];
393 m[1][1] *= other.m[1][1];
394 m[2][2] *= other.m[2][2];
399 m0 = m[0][0] * other.m[0][0]
400 + m[1][0] * other.m[0][1]
401 + m[2][0] * other.m[0][2]
402 + m[3][0] * other.m[0][3];
403 m1 = m[0][0] * other.m[1][0]
404 + m[1][0] * other.m[1][1]
405 + m[2][0] * other.m[1][2]
406 + m[3][0] * other.m[1][3];
407 m2 = m[0][0] * other.m[2][0]
408 + m[1][0] * other.m[2][1]
409 + m[2][0] * other.m[2][2]
410 + m[3][0] * other.m[2][3];
411 m[3][0] = m[0][0] * other.m[3][0]
412 + m[1][0] * other.m[3][1]
413 + m[2][0] * other.m[3][2]
414 + m[3][0] * other.m[3][3];
419 m0 = m[0][1] * other.m[0][0]
420 + m[1][1] * other.m[0][1]
421 + m[2][1] * other.m[0][2]
422 + m[3][1] * other.m[0][3];
423 m1 = m[0][1] * other.m[1][0]
424 + m[1][1] * other.m[1][1]
425 + m[2][1] * other.m[1][2]
426 + m[3][1] * other.m[1][3];
427 m2 = m[0][1] * other.m[2][0]
428 + m[1][1] * other.m[2][1]
429 + m[2][1] * other.m[2][2]
430 + m[3][1] * other.m[2][3];
431 m[3][1] = m[0][1] * other.m[3][0]
432 + m[1][1] * other.m[3][1]
433 + m[2][1] * other.m[3][2]
434 + m[3][1] * other.m[3][3];
439 m0 = m[0][2] * other.m[0][0]
440 + m[1][2] * other.m[0][1]
441 + m[2][2] * other.m[0][2]
442 + m[3][2] * other.m[0][3];
443 m1 = m[0][2] * other.m[1][0]
444 + m[1][2] * other.m[1][1]
445 + m[2][2] * other.m[1][2]
446 + m[3][2] * other.m[1][3];
447 m2 = m[0][2] * other.m[2][0]
448 + m[1][2] * other.m[2][1]
449 + m[2][2] * other.m[2][2]
450 + m[3][2] * other.m[2][3];
451 m[3][2] = m[0][2] * other.m[3][0]
452 + m[1][2] * other.m[3][1]
453 + m[2][2] * other.m[3][2]
454 + m[3][2] * other.m[3][3];
459 m0 = m[0][3] * other.m[0][0]
460 + m[1][3] * other.m[0][1]
461 + m[2][3] * other.m[0][2]
462 + m[3][3] * other.m[0][3];
463 m1 = m[0][3] * other.m[1][0]
464 + m[1][3] * other.m[1][1]
465 + m[2][3] * other.m[1][2]
466 + m[3][3] * other.m[1][3];
467 m2 = m[0][3] * other.m[2][0]
468 + m[1][3] * other.m[2][1]
469 + m[2][3] * other.m[2][2]
470 + m[3][3] * other.m[2][3];
471 m[3][3] = m[0][3] * other.m[3][0]
472 + m[1][3] * other.m[3][1]
473 + m[2][3] * other.m[3][2]
474 + m[3][3] * other.m[3][3];
503inline bool QMatrix4x4::operator==(
const QMatrix4x4& other)
const
505 return m[0][0] == other.m[0][0] &&
506 m[0][1] == other.m[0][1] &&
507 m[0][2] == other.m[0][2] &&
508 m[0][3] == other.m[0][3] &&
509 m[1][0] == other.m[1][0] &&
510 m[1][1] == other.m[1][1] &&
511 m[1][2] == other.m[1][2] &&
512 m[1][3] == other.m[1][3] &&
513 m[2][0] == other.m[2][0] &&
514 m[2][1] == other.m[2][1] &&
515 m[2][2] == other.m[2][2] &&
516 m[2][3] == other.m[2][3] &&
517 m[3][0] == other.m[3][0] &&
518 m[3][1] == other.m[3][1] &&
519 m[3][2] == other.m[3][2] &&
520 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];
546 QMatrix4x4 m(Qt::Uninitialized);
547 m.m[0][0] = m1.m[0][0] + m2.m[0][0];
548 m.m[0][1] = m1.m[0][1] + m2.m[0][1];
549 m.m[0][2] = m1.m[0][2] + m2.m[0][2];
550 m.m[0][3] = m1.m[0][3] + m2.m[0][3];
551 m.m[1][0] = m1.m[1][0] + m2.m[1][0];
552 m.m[1][1] = m1.m[1][1] + m2.m[1][1];
553 m.m[1][2] = m1.m[1][2] + m2.m[1][2];
554 m.m[1][3] = m1.m[1][3] + m2.m[1][3];
555 m.m[2][0] = m1.m[2][0] + m2.m[2][0];
556 m.m[2][1] = m1.m[2][1] + m2.m[2][1];
557 m.m[2][2] = m1.m[2][2] + m2.m[2][2];
558 m.m[2][3] = m1.m[2][3] + m2.m[2][3];
559 m.m[3][0] = m1.m[3][0] + m2.m[3][0];
560 m.m[3][1] = m1.m[3][1] + m2.m[3][1];
561 m.m[3][2] = m1.m[3][2] + m2.m[3][2];
562 m.m[3][3] = m1.m[3][3] + m2.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 QMatrix4x4::Flags flagBits = m1.flagBits | m2.flagBits;
594 if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
596 m.m[0][0] = m1.m[0][0] * m2.m[0][0];
602 m.m[1][1] = m1.m[1][1] * m2.m[1][1];
608 m.m[2][2] = m1.m[2][2] * m2.m[2][2];
611 m.m[3][0] = m1.m[3][0] + m1.m[0][0] * m2.m[3][0];
612 m.m[3][1] = m1.m[3][1] + m1.m[1][1] * m2.m[3][1];
613 m.m[3][2] = m1.m[3][2] + m1.m[2][2] * m2.m[3][2];
615 m.flagBits = flagBits;
619 m.m[0][0] = m1.m[0][0] * m2.m[0][0]
620 + m1.m[1][0] * m2.m[0][1]
621 + m1.m[2][0] * m2.m[0][2]
622 + m1.m[3][0] * m2.m[0][3];
623 m.m[0][1] = m1.m[0][1] * m2.m[0][0]
624 + m1.m[1][1] * m2.m[0][1]
625 + m1.m[2][1] * m2.m[0][2]
626 + m1.m[3][1] * m2.m[0][3];
627 m.m[0][2] = m1.m[0][2] * m2.m[0][0]
628 + m1.m[1][2] * m2.m[0][1]
629 + m1.m[2][2] * m2.m[0][2]
630 + m1.m[3][2] * m2.m[0][3];
631 m.m[0][3] = m1.m[0][3] * m2.m[0][0]
632 + m1.m[1][3] * m2.m[0][1]
633 + m1.m[2][3] * m2.m[0][2]
634 + m1.m[3][3] * m2.m[0][3];
636 m.m[1][0] = m1.m[0][0] * m2.m[1][0]
637 + m1.m[1][0] * m2.m[1][1]
638 + m1.m[2][0] * m2.m[1][2]
639 + m1.m[3][0] * m2.m[1][3];
640 m.m[1][1] = m1.m[0][1] * m2.m[1][0]
641 + m1.m[1][1] * m2.m[1][1]
642 + m1.m[2][1] * m2.m[1][2]
643 + m1.m[3][1] * m2.m[1][3];
644 m.m[1][2] = m1.m[0][2] * m2.m[1][0]
645 + m1.m[1][2] * m2.m[1][1]
646 + m1.m[2][2] * m2.m[1][2]
647 + m1.m[3][2] * m2.m[1][3];
648 m.m[1][3] = m1.m[0][3] * m2.m[1][0]
649 + m1.m[1][3] * m2.m[1][1]
650 + m1.m[2][3] * m2.m[1][2]
651 + m1.m[3][3] * m2.m[1][3];
653 m.m[2][0] = m1.m[0][0] * m2.m[2][0]
654 + m1.m[1][0] * m2.m[2][1]
655 + m1.m[2][0] * m2.m[2][2]
656 + m1.m[3][0] * m2.m[2][3];
657 m.m[2][1] = m1.m[0][1] * m2.m[2][0]
658 + m1.m[1][1] * m2.m[2][1]
659 + m1.m[2][1] * m2.m[2][2]
660 + m1.m[3][1] * m2.m[2][3];
661 m.m[2][2] = m1.m[0][2] * m2.m[2][0]
662 + m1.m[1][2] * m2.m[2][1]
663 + m1.m[2][2] * m2.m[2][2]
664 + m1.m[3][2] * m2.m[2][3];
665 m.m[2][3] = m1.m[0][3] * m2.m[2][0]
666 + m1.m[1][3] * m2.m[2][1]
667 + m1.m[2][3] * m2.m[2][2]
668 + m1.m[3][3] * m2.m[2][3];
670 m.m[3][0] = m1.m[0][0] * m2.m[3][0]
671 + m1.m[1][0] * m2.m[3][1]
672 + m1.m[2][0] * m2.m[3][2]
673 + m1.m[3][0] * m2.m[3][3];
674 m.m[3][1] = m1.m[0][1] * m2.m[3][0]
675 + m1.m[1][1] * m2.m[3][1]
676 + m1.m[2][1] * m2.m[3][2]
677 + m1.m[3][1] * m2.m[3][3];
678 m.m[3][2] = m1.m[0][2] * m2.m[3][0]
679 + m1.m[1][2] * m2.m[3][1]
680 + m1.m[2][2] * m2.m[3][2]
681 + m1.m[3][2] * m2.m[3][3];
682 m.m[3][3] = m1.m[0][3] * m2.m[3][0]
683 + m1.m[1][3] * m2.m[3][1]
684 + m1.m[2][3] * m2.m[3][2]
685 + m1.m[3][3] * m2.m[3][3];
686 m.flagBits = flagBits;
735 x = vector.x() * matrix.m[0][0] +
736 vector.y() * matrix.m[0][1] +
737 vector.z() * matrix.m[0][2] +
738 vector.w() * matrix.m[0][3];
739 y = vector.x() * matrix.m[1][0] +
740 vector.y() * matrix.m[1][1] +
741 vector.z() * matrix.m[1][2] +
742 vector.w() * matrix.m[1][3];
743 z = vector.x() * matrix.m[2][0] +
744 vector.y() * matrix.m[2][1] +
745 vector.z() * matrix.m[2][2] +
746 vector.w() * matrix.m[2][3];
747 w = vector.x() * matrix.m[3][0] +
748 vector.y() * matrix.m[3][1] +
749 vector.z() * matrix.m[3][2] +
750 vector.w() * matrix.m[3][3];
751 return QVector4D(x, y, z, w);
757 x = vector.x() * matrix.m[0][0] +
758 vector.y() * matrix.m[1][0] +
759 vector.z() * matrix.m[2][0] +
760 vector.w() * matrix.m[3][0];
761 y = vector.x() * matrix.m[0][1] +
762 vector.y() * matrix.m[1][1] +
763 vector.z() * matrix.m[2][1] +
764 vector.w() * matrix.m[3][1];
765 z = vector.x() * matrix.m[0][2] +
766 vector.y() * matrix.m[1][2] +
767 vector.z() * matrix.m[2][2] +
768 vector.w() * matrix.m[3][2];
769 w = vector.x() * matrix.m[0][3] +
770 vector.y() * matrix.m[1][3] +
771 vector.z() * matrix.m[2][3] +
772 vector.w() * matrix.m[3][3];
773 return QVector4D(x, y, z, w);
840 QMatrix4x4 m(Qt::Uninitialized);
841 m.m[0][0] = -matrix.m[0][0];
842 m.m[0][1] = -matrix.m[0][1];
843 m.m[0][2] = -matrix.m[0][2];
844 m.m[0][3] = -matrix.m[0][3];
845 m.m[1][0] = -matrix.m[1][0];
846 m.m[1][1] = -matrix.m[1][1];
847 m.m[1][2] = -matrix.m[1][2];
848 m.m[1][3] = -matrix.m[1][3];
849 m.m[2][0] = -matrix.m[2][0];
850 m.m[2][1] = -matrix.m[2][1];
851 m.m[2][2] = -matrix.m[2][2];
852 m.m[2][3] = -matrix.m[2][3];
853 m.m[3][0] = -matrix.m[3][0];
854 m.m[3][1] = -matrix.m[3][1];
855 m.m[3][2] = -matrix.m[3][2];
856 m.m[3][3] = -matrix.m[3][3];
863 QMatrix4x4 m(Qt::Uninitialized);
864 m.m[0][0] = matrix.m[0][0] * factor;
865 m.m[0][1] = matrix.m[0][1] * factor;
866 m.m[0][2] = matrix.m[0][2] * factor;
867 m.m[0][3] = matrix.m[0][3] * factor;
868 m.m[1][0] = matrix.m[1][0] * factor;
869 m.m[1][1] = matrix.m[1][1] * factor;
870 m.m[1][2] = matrix.m[1][2] * factor;
871 m.m[1][3] = matrix.m[1][3] * factor;
872 m.m[2][0] = matrix.m[2][0] * factor;
873 m.m[2][1] = matrix.m[2][1] * factor;
874 m.m[2][2] = matrix.m[2][2] * factor;
875 m.m[2][3] = matrix.m[2][3] * factor;
876 m.m[3][0] = matrix.m[3][0] * factor;
877 m.m[3][1] = matrix.m[3][1] * factor;
878 m.m[3][2] = matrix.m[3][2] * factor;
879 m.m[3][3] = matrix.m[3][3] * factor;
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;
906inline QPoint QMatrix4x4::map(
const QPoint& point)
const
912 if (flagBits == QMatrix4x4::Identity) {
914 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
916 return QPoint(qRound(xin * m[0][0] + m[3][0]),
917 qRound(yin * m[1][1] + m[3][1]));
918 }
else if (flagBits.toInt() < QMatrix4x4::Perspective) {
919 return QPoint(qRound(xin * m[0][0] + yin * m[1][0] + m[3][0]),
920 qRound(xin * m[0][1] + yin * m[1][1] + m[3][1]));
932 return QPoint(qRound(x), qRound(y));
934 return QPoint(qRound(x / w), qRound(y / w));
938inline QPointF QMatrix4x4::map(
const QPointF& point)
const
944 if (flagBits == QMatrix4x4::Identity) {
946 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
948 return QPointF(xin * qreal(m[0][0]) + qreal(m[3][0]),
949 yin * qreal(m[1][1]) + qreal(m[3][1]));
950 }
else if (flagBits.toInt() < QMatrix4x4::Perspective) {
951 return QPointF(xin * qreal(m[0][0]) + yin * qreal(m[1][0]) +
953 xin * qreal(m[0][1]) + yin * qreal(m[1][1]) +
956 x = xin * qreal(m[0][0]) +
957 yin * qreal(m[1][0]) +
959 y = xin * qreal(m[0][1]) +
960 yin * qreal(m[1][1]) +
962 w = xin * qreal(m[0][3]) +
963 yin * qreal(m[1][3]) +
966 return QPointF(qreal(x), qreal(y));
968 return QPointF(qreal(x / w), qreal(y / w));
975inline QVector3D QMatrix4x4::map(
const QVector3D& point)
const
978 if (flagBits == QMatrix4x4::Identity) {
980 }
else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
982 return QVector3D(point.x() * m[0][0] + m[3][0],
983 point.y() * m[1][1] + m[3][1],
984 point.z() * m[2][2] + m[3][2]);
985 }
else if (flagBits.toInt() < QMatrix4x4::Rotation) {
987 return QVector3D(point.x() * m[0][0] + point.y() * m[1][0] + m[3][0],
988 point.x() * m[0][1] + point.y() * m[1][1] + m[3][1],
989 point.z() * m[2][2] + m[3][2]);
991 x = point.x() * m[0][0] +
992 point.y() * m[1][0] +
993 point.z() * m[2][0] +
995 y = point.x() * m[0][1] +
996 point.y() * m[1][1] +
997 point.z() * m[2][1] +
999 z = point.x() * m[0][2] +
1000 point.y() * m[1][2] +
1001 point.z() * m[2][2] +
1003 w = point.x() * m[0][3] +
1004 point.y() * m[1][3] +
1005 point.z() * m[2][3] +
1008 return QVector3D(x, y, z);
1010 return QVector3D(x / w, y / w, z / w);