/usr/include/qt5/QtGui/qmatrix4x4.h is in qtbase5-dev 5.2.1+dfsg-1ubuntu14.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 | /****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QMATRIX4X4_H
#define QMATRIX4X4_H
#include <QtGui/qvector3d.h>
#include <QtGui/qvector4d.h>
#include <QtGui/qquaternion.h>
#include <QtGui/qgenericmatrix.h>
#include <QtCore/qrect.h>
QT_BEGIN_NAMESPACE
#ifndef QT_NO_MATRIX4X4
class QMatrix;
class QTransform;
class QVariant;
class Q_GUI_EXPORT QMatrix4x4
{
public:
inline QMatrix4x4() { setToIdentity(); }
explicit QMatrix4x4(const float *values);
inline QMatrix4x4(float m11, float m12, float m13, float m14,
float m21, float m22, float m23, float m24,
float m31, float m32, float m33, float m34,
float m41, float m42, float m43, float m44);
template <int N, int M>
explicit QMatrix4x4(const QGenericMatrix<N, M, float>& matrix);
QMatrix4x4(const float *values, int cols, int rows);
QMatrix4x4(const QTransform& transform);
QMatrix4x4(const QMatrix& matrix);
inline const float& operator()(int row, int column) const;
inline float& operator()(int row, int column);
#ifndef QT_NO_VECTOR4D
inline QVector4D column(int index) const;
inline void setColumn(int index, const QVector4D& value);
inline QVector4D row(int index) const;
inline void setRow(int index, const QVector4D& value);
#endif
inline bool isIdentity() const;
inline void setToIdentity();
inline void fill(float value);
double determinant() const;
QMatrix4x4 inverted(bool *invertible = 0) const;
QMatrix4x4 transposed() const;
QMatrix3x3 normalMatrix() const;
inline QMatrix4x4& operator+=(const QMatrix4x4& other);
inline QMatrix4x4& operator-=(const QMatrix4x4& other);
inline QMatrix4x4& operator*=(const QMatrix4x4& other);
inline QMatrix4x4& operator*=(float factor);
QMatrix4x4& operator/=(float divisor);
inline bool operator==(const QMatrix4x4& other) const;
inline bool operator!=(const QMatrix4x4& other) const;
friend QMatrix4x4 operator+(const QMatrix4x4& m1, const QMatrix4x4& m2);
friend QMatrix4x4 operator-(const QMatrix4x4& m1, const QMatrix4x4& m2);
friend QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2);
#ifndef QT_NO_VECTOR3D
friend QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector);
friend QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix);
#endif
#ifndef QT_NO_VECTOR4D
friend QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix);
friend QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector);
#endif
friend QPoint operator*(const QPoint& point, const QMatrix4x4& matrix);
friend QPointF operator*(const QPointF& point, const QMatrix4x4& matrix);
friend QMatrix4x4 operator-(const QMatrix4x4& matrix);
friend QPoint operator*(const QMatrix4x4& matrix, const QPoint& point);
friend QPointF operator*(const QMatrix4x4& matrix, const QPointF& point);
friend QMatrix4x4 operator*(float factor, const QMatrix4x4& matrix);
friend QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor);
friend Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor);
friend inline bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2);
#ifndef QT_NO_VECTOR3D
void scale(const QVector3D& vector);
void translate(const QVector3D& vector);
void rotate(float angle, const QVector3D& vector);
#endif
void scale(float x, float y);
void scale(float x, float y, float z);
void scale(float factor);
void translate(float x, float y);
void translate(float x, float y, float z);
void rotate(float angle, float x, float y, float z = 0.0f);
#ifndef QT_NO_QUATERNION
void rotate(const QQuaternion& quaternion);
#endif
void ortho(const QRect& rect);
void ortho(const QRectF& rect);
void ortho(float left, float right, float bottom, float top, float nearPlane, float farPlane);
void frustum(float left, float right, float bottom, float top, float nearPlane, float farPlane);
void perspective(float verticalAngle, float aspectRatio, float nearPlane, float farPlane);
#ifndef QT_NO_VECTOR3D
void lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up);
#endif
void flipCoordinates();
void copyDataTo(float *values) const;
QMatrix toAffine() const;
QTransform toTransform() const;
QTransform toTransform(float distanceToPlane) const;
QPoint map(const QPoint& point) const;
QPointF map(const QPointF& point) const;
#ifndef QT_NO_VECTOR3D
QVector3D map(const QVector3D& point) const;
QVector3D mapVector(const QVector3D& vector) const;
#endif
#ifndef QT_NO_VECTOR4D
QVector4D map(const QVector4D& point) const;
#endif
QRect mapRect(const QRect& rect) const;
QRectF mapRect(const QRectF& rect) const;
template <int N, int M>
QGenericMatrix<N, M, float> toGenericMatrix() const;
inline float *data();
inline const float *data() const { return *m; }
inline const float *constData() const { return *m; }
void optimize();
operator QVariant() const;
#ifndef QT_NO_DEBUG_STREAM
friend Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QMatrix4x4 &m);
#endif
private:
float m[4][4]; // Column-major order to match OpenGL.
int flagBits; // Flag bits from the enum below.
// When matrices are multiplied, the flag bits are or-ed together.
enum {
Identity = 0x0000, // Identity matrix
Translation = 0x0001, // Contains a translation
Scale = 0x0002, // Contains a scale
Rotation2D = 0x0004, // Contains a rotation about the Z axis
Rotation = 0x0008, // Contains an arbitrary rotation
Perspective = 0x0010, // Last row is different from (0, 0, 0, 1)
General = 0x001f // General matrix, unknown contents
};
// Construct without initializing identity matrix.
explicit QMatrix4x4(int) { }
QMatrix4x4 orthonormalInverse() const;
void projectedRotate(float angle, float x, float y, float z);
friend class QGraphicsRotation;
};
Q_DECLARE_TYPEINFO(QMatrix4x4, Q_MOVABLE_TYPE);
inline QMatrix4x4::QMatrix4x4
(float m11, float m12, float m13, float m14,
float m21, float m22, float m23, float m24,
float m31, float m32, float m33, float m34,
float m41, float m42, float m43, float m44)
{
m[0][0] = m11; m[0][1] = m21; m[0][2] = m31; m[0][3] = m41;
m[1][0] = m12; m[1][1] = m22; m[1][2] = m32; m[1][3] = m42;
m[2][0] = m13; m[2][1] = m23; m[2][2] = m33; m[2][3] = m43;
m[3][0] = m14; m[3][1] = m24; m[3][2] = m34; m[3][3] = m44;
flagBits = General;
}
template <int N, int M>
Q_INLINE_TEMPLATE QMatrix4x4::QMatrix4x4
(const QGenericMatrix<N, M, float>& matrix)
{
const float *values = matrix.constData();
for (int matrixCol = 0; matrixCol < 4; ++matrixCol) {
for (int matrixRow = 0; matrixRow < 4; ++matrixRow) {
if (matrixCol < N && matrixRow < M)
m[matrixCol][matrixRow] = values[matrixCol * M + matrixRow];
else if (matrixCol == matrixRow)
m[matrixCol][matrixRow] = 1.0f;
else
m[matrixCol][matrixRow] = 0.0f;
}
}
flagBits = General;
}
template <int N, int M>
QGenericMatrix<N, M, float> QMatrix4x4::toGenericMatrix() const
{
QGenericMatrix<N, M, float> result;
float *values = result.data();
for (int matrixCol = 0; matrixCol < N; ++matrixCol) {
for (int matrixRow = 0; matrixRow < M; ++matrixRow) {
if (matrixCol < 4 && matrixRow < 4)
values[matrixCol * M + matrixRow] = m[matrixCol][matrixRow];
else if (matrixCol == matrixRow)
values[matrixCol * M + matrixRow] = 1.0f;
else
values[matrixCol * M + matrixRow] = 0.0f;
}
}
return result;
}
inline const float& QMatrix4x4::operator()(int aRow, int aColumn) const
{
Q_ASSERT(aRow >= 0 && aRow < 4 && aColumn >= 0 && aColumn < 4);
return m[aColumn][aRow];
}
inline float& QMatrix4x4::operator()(int aRow, int aColumn)
{
Q_ASSERT(aRow >= 0 && aRow < 4 && aColumn >= 0 && aColumn < 4);
flagBits = General;
return m[aColumn][aRow];
}
#ifndef QT_NO_VECTOR4D
inline QVector4D QMatrix4x4::column(int index) const
{
Q_ASSERT(index >= 0 && index < 4);
return QVector4D(m[index][0], m[index][1], m[index][2], m[index][3]);
}
inline void QMatrix4x4::setColumn(int index, const QVector4D& value)
{
Q_ASSERT(index >= 0 && index < 4);
m[index][0] = value.x();
m[index][1] = value.y();
m[index][2] = value.z();
m[index][3] = value.w();
flagBits = General;
}
inline QVector4D QMatrix4x4::row(int index) const
{
Q_ASSERT(index >= 0 && index < 4);
return QVector4D(m[0][index], m[1][index], m[2][index], m[3][index]);
}
inline void QMatrix4x4::setRow(int index, const QVector4D& value)
{
Q_ASSERT(index >= 0 && index < 4);
m[0][index] = value.x();
m[1][index] = value.y();
m[2][index] = value.z();
m[3][index] = value.w();
flagBits = General;
}
#endif
Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor);
inline bool QMatrix4x4::isIdentity() const
{
if (flagBits == Identity)
return true;
if (m[0][0] != 1.0f || m[0][1] != 0.0f || m[0][2] != 0.0f)
return false;
if (m[0][3] != 0.0f || m[1][0] != 0.0f || m[1][1] != 1.0f)
return false;
if (m[1][2] != 0.0f || m[1][3] != 0.0f || m[2][0] != 0.0f)
return false;
if (m[2][1] != 0.0f || m[2][2] != 1.0f || m[2][3] != 0.0f)
return false;
if (m[3][0] != 0.0f || m[3][1] != 0.0f || m[3][2] != 0.0f)
return false;
return (m[3][3] == 1.0f);
}
inline void QMatrix4x4::setToIdentity()
{
m[0][0] = 1.0f;
m[0][1] = 0.0f;
m[0][2] = 0.0f;
m[0][3] = 0.0f;
m[1][0] = 0.0f;
m[1][1] = 1.0f;
m[1][2] = 0.0f;
m[1][3] = 0.0f;
m[2][0] = 0.0f;
m[2][1] = 0.0f;
m[2][2] = 1.0f;
m[2][3] = 0.0f;
m[3][0] = 0.0f;
m[3][1] = 0.0f;
m[3][2] = 0.0f;
m[3][3] = 1.0f;
flagBits = Identity;
}
inline void QMatrix4x4::fill(float value)
{
m[0][0] = value;
m[0][1] = value;
m[0][2] = value;
m[0][3] = value;
m[1][0] = value;
m[1][1] = value;
m[1][2] = value;
m[1][3] = value;
m[2][0] = value;
m[2][1] = value;
m[2][2] = value;
m[2][3] = value;
m[3][0] = value;
m[3][1] = value;
m[3][2] = value;
m[3][3] = value;
flagBits = General;
}
inline QMatrix4x4& QMatrix4x4::operator+=(const QMatrix4x4& other)
{
m[0][0] += other.m[0][0];
m[0][1] += other.m[0][1];
m[0][2] += other.m[0][2];
m[0][3] += other.m[0][3];
m[1][0] += other.m[1][0];
m[1][1] += other.m[1][1];
m[1][2] += other.m[1][2];
m[1][3] += other.m[1][3];
m[2][0] += other.m[2][0];
m[2][1] += other.m[2][1];
m[2][2] += other.m[2][2];
m[2][3] += other.m[2][3];
m[3][0] += other.m[3][0];
m[3][1] += other.m[3][1];
m[3][2] += other.m[3][2];
m[3][3] += other.m[3][3];
flagBits = General;
return *this;
}
inline QMatrix4x4& QMatrix4x4::operator-=(const QMatrix4x4& other)
{
m[0][0] -= other.m[0][0];
m[0][1] -= other.m[0][1];
m[0][2] -= other.m[0][2];
m[0][3] -= other.m[0][3];
m[1][0] -= other.m[1][0];
m[1][1] -= other.m[1][1];
m[1][2] -= other.m[1][2];
m[1][3] -= other.m[1][3];
m[2][0] -= other.m[2][0];
m[2][1] -= other.m[2][1];
m[2][2] -= other.m[2][2];
m[2][3] -= other.m[2][3];
m[3][0] -= other.m[3][0];
m[3][1] -= other.m[3][1];
m[3][2] -= other.m[3][2];
m[3][3] -= other.m[3][3];
flagBits = General;
return *this;
}
inline QMatrix4x4& QMatrix4x4::operator*=(const QMatrix4x4& other)
{
flagBits |= other.flagBits;
if (flagBits < Rotation2D) {
m[3][0] += m[0][0] * other.m[3][0];
m[3][1] += m[1][1] * other.m[3][1];
m[3][2] += m[2][2] * other.m[3][2];
m[0][0] *= other.m[0][0];
m[1][1] *= other.m[1][1];
m[2][2] *= other.m[2][2];
return *this;
}
float m0, m1, m2;
m0 = m[0][0] * other.m[0][0]
+ m[1][0] * other.m[0][1]
+ m[2][0] * other.m[0][2]
+ m[3][0] * other.m[0][3];
m1 = m[0][0] * other.m[1][0]
+ m[1][0] * other.m[1][1]
+ m[2][0] * other.m[1][2]
+ m[3][0] * other.m[1][3];
m2 = m[0][0] * other.m[2][0]
+ m[1][0] * other.m[2][1]
+ m[2][0] * other.m[2][2]
+ m[3][0] * other.m[2][3];
m[3][0] = m[0][0] * other.m[3][0]
+ m[1][0] * other.m[3][1]
+ m[2][0] * other.m[3][2]
+ m[3][0] * other.m[3][3];
m[0][0] = m0;
m[1][0] = m1;
m[2][0] = m2;
m0 = m[0][1] * other.m[0][0]
+ m[1][1] * other.m[0][1]
+ m[2][1] * other.m[0][2]
+ m[3][1] * other.m[0][3];
m1 = m[0][1] * other.m[1][0]
+ m[1][1] * other.m[1][1]
+ m[2][1] * other.m[1][2]
+ m[3][1] * other.m[1][3];
m2 = m[0][1] * other.m[2][0]
+ m[1][1] * other.m[2][1]
+ m[2][1] * other.m[2][2]
+ m[3][1] * other.m[2][3];
m[3][1] = m[0][1] * other.m[3][0]
+ m[1][1] * other.m[3][1]
+ m[2][1] * other.m[3][2]
+ m[3][1] * other.m[3][3];
m[0][1] = m0;
m[1][1] = m1;
m[2][1] = m2;
m0 = m[0][2] * other.m[0][0]
+ m[1][2] * other.m[0][1]
+ m[2][2] * other.m[0][2]
+ m[3][2] * other.m[0][3];
m1 = m[0][2] * other.m[1][0]
+ m[1][2] * other.m[1][1]
+ m[2][2] * other.m[1][2]
+ m[3][2] * other.m[1][3];
m2 = m[0][2] * other.m[2][0]
+ m[1][2] * other.m[2][1]
+ m[2][2] * other.m[2][2]
+ m[3][2] * other.m[2][3];
m[3][2] = m[0][2] * other.m[3][0]
+ m[1][2] * other.m[3][1]
+ m[2][2] * other.m[3][2]
+ m[3][2] * other.m[3][3];
m[0][2] = m0;
m[1][2] = m1;
m[2][2] = m2;
m0 = m[0][3] * other.m[0][0]
+ m[1][3] * other.m[0][1]
+ m[2][3] * other.m[0][2]
+ m[3][3] * other.m[0][3];
m1 = m[0][3] * other.m[1][0]
+ m[1][3] * other.m[1][1]
+ m[2][3] * other.m[1][2]
+ m[3][3] * other.m[1][3];
m2 = m[0][3] * other.m[2][0]
+ m[1][3] * other.m[2][1]
+ m[2][3] * other.m[2][2]
+ m[3][3] * other.m[2][3];
m[3][3] = m[0][3] * other.m[3][0]
+ m[1][3] * other.m[3][1]
+ m[2][3] * other.m[3][2]
+ m[3][3] * other.m[3][3];
m[0][3] = m0;
m[1][3] = m1;
m[2][3] = m2;
return *this;
}
inline QMatrix4x4& QMatrix4x4::operator*=(float factor)
{
m[0][0] *= factor;
m[0][1] *= factor;
m[0][2] *= factor;
m[0][3] *= factor;
m[1][0] *= factor;
m[1][1] *= factor;
m[1][2] *= factor;
m[1][3] *= factor;
m[2][0] *= factor;
m[2][1] *= factor;
m[2][2] *= factor;
m[2][3] *= factor;
m[3][0] *= factor;
m[3][1] *= factor;
m[3][2] *= factor;
m[3][3] *= factor;
flagBits = General;
return *this;
}
inline bool QMatrix4x4::operator==(const QMatrix4x4& other) const
{
return m[0][0] == other.m[0][0] &&
m[0][1] == other.m[0][1] &&
m[0][2] == other.m[0][2] &&
m[0][3] == other.m[0][3] &&
m[1][0] == other.m[1][0] &&
m[1][1] == other.m[1][1] &&
m[1][2] == other.m[1][2] &&
m[1][3] == other.m[1][3] &&
m[2][0] == other.m[2][0] &&
m[2][1] == other.m[2][1] &&
m[2][2] == other.m[2][2] &&
m[2][3] == other.m[2][3] &&
m[3][0] == other.m[3][0] &&
m[3][1] == other.m[3][1] &&
m[3][2] == other.m[3][2] &&
m[3][3] == other.m[3][3];
}
inline bool QMatrix4x4::operator!=(const QMatrix4x4& other) const
{
return m[0][0] != other.m[0][0] ||
m[0][1] != other.m[0][1] ||
m[0][2] != other.m[0][2] ||
m[0][3] != other.m[0][3] ||
m[1][0] != other.m[1][0] ||
m[1][1] != other.m[1][1] ||
m[1][2] != other.m[1][2] ||
m[1][3] != other.m[1][3] ||
m[2][0] != other.m[2][0] ||
m[2][1] != other.m[2][1] ||
m[2][2] != other.m[2][2] ||
m[2][3] != other.m[2][3] ||
m[3][0] != other.m[3][0] ||
m[3][1] != other.m[3][1] ||
m[3][2] != other.m[3][2] ||
m[3][3] != other.m[3][3];
}
inline QMatrix4x4 operator+(const QMatrix4x4& m1, const QMatrix4x4& m2)
{
QMatrix4x4 m(1);
m.m[0][0] = m1.m[0][0] + m2.m[0][0];
m.m[0][1] = m1.m[0][1] + m2.m[0][1];
m.m[0][2] = m1.m[0][2] + m2.m[0][2];
m.m[0][3] = m1.m[0][3] + m2.m[0][3];
m.m[1][0] = m1.m[1][0] + m2.m[1][0];
m.m[1][1] = m1.m[1][1] + m2.m[1][1];
m.m[1][2] = m1.m[1][2] + m2.m[1][2];
m.m[1][3] = m1.m[1][3] + m2.m[1][3];
m.m[2][0] = m1.m[2][0] + m2.m[2][0];
m.m[2][1] = m1.m[2][1] + m2.m[2][1];
m.m[2][2] = m1.m[2][2] + m2.m[2][2];
m.m[2][3] = m1.m[2][3] + m2.m[2][3];
m.m[3][0] = m1.m[3][0] + m2.m[3][0];
m.m[3][1] = m1.m[3][1] + m2.m[3][1];
m.m[3][2] = m1.m[3][2] + m2.m[3][2];
m.m[3][3] = m1.m[3][3] + m2.m[3][3];
m.flagBits = QMatrix4x4::General;
return m;
}
inline QMatrix4x4 operator-(const QMatrix4x4& m1, const QMatrix4x4& m2)
{
QMatrix4x4 m(1);
m.m[0][0] = m1.m[0][0] - m2.m[0][0];
m.m[0][1] = m1.m[0][1] - m2.m[0][1];
m.m[0][2] = m1.m[0][2] - m2.m[0][2];
m.m[0][3] = m1.m[0][3] - m2.m[0][3];
m.m[1][0] = m1.m[1][0] - m2.m[1][0];
m.m[1][1] = m1.m[1][1] - m2.m[1][1];
m.m[1][2] = m1.m[1][2] - m2.m[1][2];
m.m[1][3] = m1.m[1][3] - m2.m[1][3];
m.m[2][0] = m1.m[2][0] - m2.m[2][0];
m.m[2][1] = m1.m[2][1] - m2.m[2][1];
m.m[2][2] = m1.m[2][2] - m2.m[2][2];
m.m[2][3] = m1.m[2][3] - m2.m[2][3];
m.m[3][0] = m1.m[3][0] - m2.m[3][0];
m.m[3][1] = m1.m[3][1] - m2.m[3][1];
m.m[3][2] = m1.m[3][2] - m2.m[3][2];
m.m[3][3] = m1.m[3][3] - m2.m[3][3];
m.flagBits = QMatrix4x4::General;
return m;
}
inline QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)
{
int flagBits = m1.flagBits | m2.flagBits;
if (flagBits < QMatrix4x4::Rotation2D) {
QMatrix4x4 m = m1;
m.m[3][0] += m.m[0][0] * m2.m[3][0];
m.m[3][1] += m.m[1][1] * m2.m[3][1];
m.m[3][2] += m.m[2][2] * m2.m[3][2];
m.m[0][0] *= m2.m[0][0];
m.m[1][1] *= m2.m[1][1];
m.m[2][2] *= m2.m[2][2];
m.flagBits = flagBits;
return m;
}
QMatrix4x4 m(1);
m.m[0][0] = m1.m[0][0] * m2.m[0][0]
+ m1.m[1][0] * m2.m[0][1]
+ m1.m[2][0] * m2.m[0][2]
+ m1.m[3][0] * m2.m[0][3];
m.m[0][1] = m1.m[0][1] * m2.m[0][0]
+ m1.m[1][1] * m2.m[0][1]
+ m1.m[2][1] * m2.m[0][2]
+ m1.m[3][1] * m2.m[0][3];
m.m[0][2] = m1.m[0][2] * m2.m[0][0]
+ m1.m[1][2] * m2.m[0][1]
+ m1.m[2][2] * m2.m[0][2]
+ m1.m[3][2] * m2.m[0][3];
m.m[0][3] = m1.m[0][3] * m2.m[0][0]
+ m1.m[1][3] * m2.m[0][1]
+ m1.m[2][3] * m2.m[0][2]
+ m1.m[3][3] * m2.m[0][3];
m.m[1][0] = m1.m[0][0] * m2.m[1][0]
+ m1.m[1][0] * m2.m[1][1]
+ m1.m[2][0] * m2.m[1][2]
+ m1.m[3][0] * m2.m[1][3];
m.m[1][1] = m1.m[0][1] * m2.m[1][0]
+ m1.m[1][1] * m2.m[1][1]
+ m1.m[2][1] * m2.m[1][2]
+ m1.m[3][1] * m2.m[1][3];
m.m[1][2] = m1.m[0][2] * m2.m[1][0]
+ m1.m[1][2] * m2.m[1][1]
+ m1.m[2][2] * m2.m[1][2]
+ m1.m[3][2] * m2.m[1][3];
m.m[1][3] = m1.m[0][3] * m2.m[1][0]
+ m1.m[1][3] * m2.m[1][1]
+ m1.m[2][3] * m2.m[1][2]
+ m1.m[3][3] * m2.m[1][3];
m.m[2][0] = m1.m[0][0] * m2.m[2][0]
+ m1.m[1][0] * m2.m[2][1]
+ m1.m[2][0] * m2.m[2][2]
+ m1.m[3][0] * m2.m[2][3];
m.m[2][1] = m1.m[0][1] * m2.m[2][0]
+ m1.m[1][1] * m2.m[2][1]
+ m1.m[2][1] * m2.m[2][2]
+ m1.m[3][1] * m2.m[2][3];
m.m[2][2] = m1.m[0][2] * m2.m[2][0]
+ m1.m[1][2] * m2.m[2][1]
+ m1.m[2][2] * m2.m[2][2]
+ m1.m[3][2] * m2.m[2][3];
m.m[2][3] = m1.m[0][3] * m2.m[2][0]
+ m1.m[1][3] * m2.m[2][1]
+ m1.m[2][3] * m2.m[2][2]
+ m1.m[3][3] * m2.m[2][3];
m.m[3][0] = m1.m[0][0] * m2.m[3][0]
+ m1.m[1][0] * m2.m[3][1]
+ m1.m[2][0] * m2.m[3][2]
+ m1.m[3][0] * m2.m[3][3];
m.m[3][1] = m1.m[0][1] * m2.m[3][0]
+ m1.m[1][1] * m2.m[3][1]
+ m1.m[2][1] * m2.m[3][2]
+ m1.m[3][1] * m2.m[3][3];
m.m[3][2] = m1.m[0][2] * m2.m[3][0]
+ m1.m[1][2] * m2.m[3][1]
+ m1.m[2][2] * m2.m[3][2]
+ m1.m[3][2] * m2.m[3][3];
m.m[3][3] = m1.m[0][3] * m2.m[3][0]
+ m1.m[1][3] * m2.m[3][1]
+ m1.m[2][3] * m2.m[3][2]
+ m1.m[3][3] * m2.m[3][3];
m.flagBits = flagBits;
return m;
}
#ifndef QT_NO_VECTOR3D
inline QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)
{
float x, y, z, w;
x = vector.x() * matrix.m[0][0] +
vector.y() * matrix.m[0][1] +
vector.z() * matrix.m[0][2] +
matrix.m[0][3];
y = vector.x() * matrix.m[1][0] +
vector.y() * matrix.m[1][1] +
vector.z() * matrix.m[1][2] +
matrix.m[1][3];
z = vector.x() * matrix.m[2][0] +
vector.y() * matrix.m[2][1] +
vector.z() * matrix.m[2][2] +
matrix.m[2][3];
w = vector.x() * matrix.m[3][0] +
vector.y() * matrix.m[3][1] +
vector.z() * matrix.m[3][2] +
matrix.m[3][3];
if (w == 1.0f)
return QVector3D(x, y, z);
else
return QVector3D(x / w, y / w, z / w);
}
inline QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector)
{
float x, y, z, w;
if (matrix.flagBits == QMatrix4x4::Identity) {
return vector;
} else if (matrix.flagBits < QMatrix4x4::Rotation2D) {
// Translation | Scale
return QVector3D(vector.x() * matrix.m[0][0] + matrix.m[3][0],
vector.y() * matrix.m[1][1] + matrix.m[3][1],
vector.z() * matrix.m[2][2] + matrix.m[3][2]);
} else if (matrix.flagBits < QMatrix4x4::Rotation) {
// Translation | Scale | Rotation2D
return QVector3D(vector.x() * matrix.m[0][0] + vector.y() * matrix.m[1][0] + matrix.m[3][0],
vector.x() * matrix.m[0][1] + vector.y() * matrix.m[1][1] + matrix.m[3][1],
vector.z() * matrix.m[2][2] + matrix.m[3][2]);
} else {
x = vector.x() * matrix.m[0][0] +
vector.y() * matrix.m[1][0] +
vector.z() * matrix.m[2][0] +
matrix.m[3][0];
y = vector.x() * matrix.m[0][1] +
vector.y() * matrix.m[1][1] +
vector.z() * matrix.m[2][1] +
matrix.m[3][1];
z = vector.x() * matrix.m[0][2] +
vector.y() * matrix.m[1][2] +
vector.z() * matrix.m[2][2] +
matrix.m[3][2];
w = vector.x() * matrix.m[0][3] +
vector.y() * matrix.m[1][3] +
vector.z() * matrix.m[2][3] +
matrix.m[3][3];
if (w == 1.0f)
return QVector3D(x, y, z);
else
return QVector3D(x / w, y / w, z / w);
}
}
#endif
#ifndef QT_NO_VECTOR4D
inline QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix)
{
float x, y, z, w;
x = vector.x() * matrix.m[0][0] +
vector.y() * matrix.m[0][1] +
vector.z() * matrix.m[0][2] +
vector.w() * matrix.m[0][3];
y = vector.x() * matrix.m[1][0] +
vector.y() * matrix.m[1][1] +
vector.z() * matrix.m[1][2] +
vector.w() * matrix.m[1][3];
z = vector.x() * matrix.m[2][0] +
vector.y() * matrix.m[2][1] +
vector.z() * matrix.m[2][2] +
vector.w() * matrix.m[2][3];
w = vector.x() * matrix.m[3][0] +
vector.y() * matrix.m[3][1] +
vector.z() * matrix.m[3][2] +
vector.w() * matrix.m[3][3];
return QVector4D(x, y, z, w);
}
inline QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector)
{
float x, y, z, w;
x = vector.x() * matrix.m[0][0] +
vector.y() * matrix.m[1][0] +
vector.z() * matrix.m[2][0] +
vector.w() * matrix.m[3][0];
y = vector.x() * matrix.m[0][1] +
vector.y() * matrix.m[1][1] +
vector.z() * matrix.m[2][1] +
vector.w() * matrix.m[3][1];
z = vector.x() * matrix.m[0][2] +
vector.y() * matrix.m[1][2] +
vector.z() * matrix.m[2][2] +
vector.w() * matrix.m[3][2];
w = vector.x() * matrix.m[0][3] +
vector.y() * matrix.m[1][3] +
vector.z() * matrix.m[2][3] +
vector.w() * matrix.m[3][3];
return QVector4D(x, y, z, w);
}
#endif
inline QPoint operator*(const QPoint& point, const QMatrix4x4& matrix)
{
float xin, yin;
float x, y, w;
xin = point.x();
yin = point.y();
x = xin * matrix.m[0][0] +
yin * matrix.m[0][1] +
matrix.m[0][3];
y = xin * matrix.m[1][0] +
yin * matrix.m[1][1] +
matrix.m[1][3];
w = xin * matrix.m[3][0] +
yin * matrix.m[3][1] +
matrix.m[3][3];
if (w == 1.0f)
return QPoint(qRound(x), qRound(y));
else
return QPoint(qRound(x / w), qRound(y / w));
}
inline QPointF operator*(const QPointF& point, const QMatrix4x4& matrix)
{
float xin, yin;
float x, y, w;
xin = point.x();
yin = point.y();
x = xin * matrix.m[0][0] +
yin * matrix.m[0][1] +
matrix.m[0][3];
y = xin * matrix.m[1][0] +
yin * matrix.m[1][1] +
matrix.m[1][3];
w = xin * matrix.m[3][0] +
yin * matrix.m[3][1] +
matrix.m[3][3];
if (w == 1.0f) {
return QPointF(float(x), float(y));
} else {
return QPointF(float(x / w), float(y / w));
}
}
inline QPoint operator*(const QMatrix4x4& matrix, const QPoint& point)
{
float xin, yin;
float x, y, w;
xin = point.x();
yin = point.y();
if (matrix.flagBits == QMatrix4x4::Identity) {
return point;
} else if (matrix.flagBits < QMatrix4x4::Rotation2D) {
// Translation | Scale
return QPoint(qRound(xin * matrix.m[0][0] + matrix.m[3][0]),
qRound(yin * matrix.m[1][1] + matrix.m[3][1]));
} else if (matrix.flagBits < QMatrix4x4::Perspective) {
return QPoint(qRound(xin * matrix.m[0][0] + yin * matrix.m[1][0] + matrix.m[3][0]),
qRound(xin * matrix.m[0][1] + yin * matrix.m[1][1] + matrix.m[3][1]));
} else {
x = xin * matrix.m[0][0] +
yin * matrix.m[1][0] +
matrix.m[3][0];
y = xin * matrix.m[0][1] +
yin * matrix.m[1][1] +
matrix.m[3][1];
w = xin * matrix.m[0][3] +
yin * matrix.m[1][3] +
matrix.m[3][3];
if (w == 1.0f)
return QPoint(qRound(x), qRound(y));
else
return QPoint(qRound(x / w), qRound(y / w));
}
}
inline QPointF operator*(const QMatrix4x4& matrix, const QPointF& point)
{
float xin, yin;
float x, y, w;
xin = point.x();
yin = point.y();
if (matrix.flagBits == QMatrix4x4::Identity) {
return point;
} else if (matrix.flagBits < QMatrix4x4::Rotation2D) {
// Translation | Scale
return QPointF(xin * matrix.m[0][0] + matrix.m[3][0],
yin * matrix.m[1][1] + matrix.m[3][1]);
} else if (matrix.flagBits < QMatrix4x4::Perspective) {
return QPointF(xin * matrix.m[0][0] + yin * matrix.m[1][0] + matrix.m[3][0],
xin * matrix.m[0][1] + yin * matrix.m[1][1] + matrix.m[3][1]);
} else {
x = xin * matrix.m[0][0] +
yin * matrix.m[1][0] +
matrix.m[3][0];
y = xin * matrix.m[0][1] +
yin * matrix.m[1][1] +
matrix.m[3][1];
w = xin * matrix.m[0][3] +
yin * matrix.m[1][3] +
matrix.m[3][3];
if (w == 1.0f) {
return QPointF(float(x), float(y));
} else {
return QPointF(float(x / w), float(y / w));
}
}
}
inline QMatrix4x4 operator-(const QMatrix4x4& matrix)
{
QMatrix4x4 m(1);
m.m[0][0] = -matrix.m[0][0];
m.m[0][1] = -matrix.m[0][1];
m.m[0][2] = -matrix.m[0][2];
m.m[0][3] = -matrix.m[0][3];
m.m[1][0] = -matrix.m[1][0];
m.m[1][1] = -matrix.m[1][1];
m.m[1][2] = -matrix.m[1][2];
m.m[1][3] = -matrix.m[1][3];
m.m[2][0] = -matrix.m[2][0];
m.m[2][1] = -matrix.m[2][1];
m.m[2][2] = -matrix.m[2][2];
m.m[2][3] = -matrix.m[2][3];
m.m[3][0] = -matrix.m[3][0];
m.m[3][1] = -matrix.m[3][1];
m.m[3][2] = -matrix.m[3][2];
m.m[3][3] = -matrix.m[3][3];
m.flagBits = QMatrix4x4::General;
return m;
}
inline QMatrix4x4 operator*(float factor, const QMatrix4x4& matrix)
{
QMatrix4x4 m(1);
m.m[0][0] = matrix.m[0][0] * factor;
m.m[0][1] = matrix.m[0][1] * factor;
m.m[0][2] = matrix.m[0][2] * factor;
m.m[0][3] = matrix.m[0][3] * factor;
m.m[1][0] = matrix.m[1][0] * factor;
m.m[1][1] = matrix.m[1][1] * factor;
m.m[1][2] = matrix.m[1][2] * factor;
m.m[1][3] = matrix.m[1][3] * factor;
m.m[2][0] = matrix.m[2][0] * factor;
m.m[2][1] = matrix.m[2][1] * factor;
m.m[2][2] = matrix.m[2][2] * factor;
m.m[2][3] = matrix.m[2][3] * factor;
m.m[3][0] = matrix.m[3][0] * factor;
m.m[3][1] = matrix.m[3][1] * factor;
m.m[3][2] = matrix.m[3][2] * factor;
m.m[3][3] = matrix.m[3][3] * factor;
m.flagBits = QMatrix4x4::General;
return m;
}
inline QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor)
{
QMatrix4x4 m(1);
m.m[0][0] = matrix.m[0][0] * factor;
m.m[0][1] = matrix.m[0][1] * factor;
m.m[0][2] = matrix.m[0][2] * factor;
m.m[0][3] = matrix.m[0][3] * factor;
m.m[1][0] = matrix.m[1][0] * factor;
m.m[1][1] = matrix.m[1][1] * factor;
m.m[1][2] = matrix.m[1][2] * factor;
m.m[1][3] = matrix.m[1][3] * factor;
m.m[2][0] = matrix.m[2][0] * factor;
m.m[2][1] = matrix.m[2][1] * factor;
m.m[2][2] = matrix.m[2][2] * factor;
m.m[2][3] = matrix.m[2][3] * factor;
m.m[3][0] = matrix.m[3][0] * factor;
m.m[3][1] = matrix.m[3][1] * factor;
m.m[3][2] = matrix.m[3][2] * factor;
m.m[3][3] = matrix.m[3][3] * factor;
m.flagBits = QMatrix4x4::General;
return m;
}
inline bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2)
{
return qFuzzyCompare(m1.m[0][0], m2.m[0][0]) &&
qFuzzyCompare(m1.m[0][1], m2.m[0][1]) &&
qFuzzyCompare(m1.m[0][2], m2.m[0][2]) &&
qFuzzyCompare(m1.m[0][3], m2.m[0][3]) &&
qFuzzyCompare(m1.m[1][0], m2.m[1][0]) &&
qFuzzyCompare(m1.m[1][1], m2.m[1][1]) &&
qFuzzyCompare(m1.m[1][2], m2.m[1][2]) &&
qFuzzyCompare(m1.m[1][3], m2.m[1][3]) &&
qFuzzyCompare(m1.m[2][0], m2.m[2][0]) &&
qFuzzyCompare(m1.m[2][1], m2.m[2][1]) &&
qFuzzyCompare(m1.m[2][2], m2.m[2][2]) &&
qFuzzyCompare(m1.m[2][3], m2.m[2][3]) &&
qFuzzyCompare(m1.m[3][0], m2.m[3][0]) &&
qFuzzyCompare(m1.m[3][1], m2.m[3][1]) &&
qFuzzyCompare(m1.m[3][2], m2.m[3][2]) &&
qFuzzyCompare(m1.m[3][3], m2.m[3][3]);
}
inline QPoint QMatrix4x4::map(const QPoint& point) const
{
return *this * point;
}
inline QPointF QMatrix4x4::map(const QPointF& point) const
{
return *this * point;
}
#ifndef QT_NO_VECTOR3D
inline QVector3D QMatrix4x4::map(const QVector3D& point) const
{
return *this * point;
}
inline QVector3D QMatrix4x4::mapVector(const QVector3D& vector) const
{
if (flagBits < Scale) {
// Translation
return vector;
} else if (flagBits < Rotation2D) {
// Translation | Scale
return QVector3D(vector.x() * m[0][0],
vector.y() * m[1][1],
vector.z() * m[2][2]);
} else {
return QVector3D(vector.x() * m[0][0] +
vector.y() * m[1][0] +
vector.z() * m[2][0],
vector.x() * m[0][1] +
vector.y() * m[1][1] +
vector.z() * m[2][1],
vector.x() * m[0][2] +
vector.y() * m[1][2] +
vector.z() * m[2][2]);
}
}
#endif
#ifndef QT_NO_VECTOR4D
inline QVector4D QMatrix4x4::map(const QVector4D& point) const
{
return *this * point;
}
#endif
inline float *QMatrix4x4::data()
{
// We have to assume that the caller will modify the matrix elements,
// so we flip it over to "General" mode.
flagBits = General;
return *m;
}
#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QMatrix4x4 &m);
#endif
#ifndef QT_NO_DATASTREAM
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QMatrix4x4 &);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QMatrix4x4 &);
#endif
#if QT_DEPRECATED_SINCE(5, 0)
template <int N, int M>
QT_DEPRECATED QMatrix4x4 qGenericMatrixToMatrix4x4(const QGenericMatrix<N, M, float>& matrix)
{
return QMatrix4x4(matrix.constData(), N, M);
}
template <int N, int M>
QT_DEPRECATED QGenericMatrix<N, M, float> qGenericMatrixFromMatrix4x4(const QMatrix4x4& matrix)
{
QGenericMatrix<N, M, float> result;
const float *m = matrix.constData();
float *values = result.data();
for (int col = 0; col < N; ++col) {
for (int row = 0; row < M; ++row) {
if (col < 4 && row < 4)
values[col * M + row] = m[col * 4 + row];
else if (col == row)
values[col * M + row] = 1.0f;
else
values[col * M + row] = 0.0f;
}
}
return result;
}
#endif
#endif
QT_END_NAMESPACE
#endif
|