1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #pragma once19 20 #ifdef MATH_ENABLE_STL_SUPPORT21 #include <ostream>22 #include "[myassert.h]"23 #endif24 25 #include "../MathGeoLibFwd.h"26 #include "[MatrixProxy.h]"27 #include "../Math/float3.h"28 29 #ifdef MATH_OGRE_INTEROP30 #include <OgreMatrix3.h>31 #endif32 #ifdef MATH_BULLET_INTEROP33 #include <LinearMath/btMatrix3x3.h>34 #endif35 #ifdef MATH_URHO3D_INTEROP36 #include <Urho3D/Math/Matrix3.h>37 #endif38 39 [MATH_BEGIN_NAMESPACE]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 class [float3x3]71 {72 public:73 74 enum { [Rows] = 3 };75 76 77 enum { [Cols] = 3 };78 79 80 float [v][[Rows]][[Cols]];81 82 83 static const [float3x3] [zero];84 85 86 87 88 89 90 91 static const [float3x3] [identity];92 93 94 95 96 97 static const [float3x3] [nan];98 99 100 101 [float3x3]() {}102 103 #ifdef MATH_EXPLICIT_COPYCTORS104 105 106 [float3x3](const [float3x3] &rhs) { [Set](rhs); }107 #endif108 109 110 111 112 [float3x3](float _00, float _01, float _02,113 float _10, float _11, float _12,114 float _20, float _21, float _22);115 116 117 118 119 120 121 122 123 [float3x3](const [float3] &col0, const [float3] &col1, const [float3] &col2);124 125 126 explicit [float3x3](const [Quat] &orientation);127 128 129 130 static [float3x3] [RotateX](float angleRadians);131 132 static [float3x3] [RotateY](float angleRadians);133 134 static [float3x3] [RotateZ](float angleRadians);135 136 137 static [float3x3] [RotateAxisAngle](const [float3] &axisDirection, float angleRadians);138 139 140 141 142 143 144 145 static [float3x3] [RotateFromTo](const [float3] &sourceDirection, const [float3] &targetDirection);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 static [float3x3] [LookAt](const [float3] &localForward, const [float3] &targetDirection, const [float3] &localUp, const [float3] &worldUp);179 180 181 182 183 184 static [float3x3] [RandomRotation]([LCG] &lcg);185 186 187 188 189 static [float3x3] [RandomGeneral]([LCG] &lcg, float minElem, float maxElem);190 191 192 static [float3x3] [FromQuat](const [Quat] &orientation);193 194 195 196 [Quat] [ToQuat]() const;197 198 199 200 201 202 203 static [float3x3] [FromRS](const [Quat] &rotate, const [float3] &scale);204 static [float3x3] [FromRS](const [float3x3] &rotate, const [float3] &scale);205 206 207 208 209 static [float3x3] [FromEulerXYX](float ex, float ey, float ex2);210 static [float3x3] [FromEulerXZX](float ex, float ez, float ex2); 211 static [float3x3] [FromEulerYXY](float ey, float ex, float ey2); 212 static [float3x3] [FromEulerYZY](float ey, float ez, float ey2); 213 static [float3x3] [FromEulerZXZ](float ez, float ex, float ez2); 214 static [float3x3] [FromEulerZYZ](float ez, float ey, float ez2); 215 static [float3x3] [FromEulerXYZ](float ex, float ey, float ez); 216 static [float3x3] [FromEulerXZY](float ex, float ez, float ey); 217 static [float3x3] [FromEulerYXZ](float ey, float ex, float ez); 218 static [float3x3] [FromEulerYZX](float ey, float ez, float ex); 219 static [float3x3] [FromEulerZXY](float ez, float ex, float ey); 220 static [float3x3] [FromEulerZYX](float ez, float ey, float ex); 221 222 223 224 static [ScaleOp] [Scale](float sx, float sy, float sz);225 static [ScaleOp] [Scale](const [float3] &scale);226 227 228 229 230 static [float3x3] [ScaleAlongAxis](const [float3] &axis, float scalingFactor);231 232 233 static [ScaleOp] [UniformScale](float uniformScale);234 235 236 237 238 [float3] [GetScale]() const;239 240 241 242 243 static [float3x3] [ShearX](float yFactor, float zFactor);244 static [float3x3] [ShearY](float xFactor, float zFactor); 245 static [float3x3] [ShearZ](float xFactor, float yFactor); 246 247 248 249 250 static [float3x3] [Mirror](const [Plane] &p);251 252 253 static [float3x3] [OrthographicProjection](const [Plane] &target);254 static [float3x3] [OrthographicProjectionYZ](); 255 static [float3x3] [OrthographicProjectionXZ](); 256 static [float3x3] [OrthographicProjectionXY](); 257 258 259 260 261 262 263 264 265 266 267 268 [MatrixProxy<Cols>] &[operator[]](int row);269 const [MatrixProxy<Cols>] &[operator[]](int row) const;270 271 272 273 274 275 float &[At](int row, int col);276 [CONST_WIN32] float [At](int row, int col) const;277 278 279 280 [float3] &[Row](int row);281 const [float3] &[Row](int row) const;282 283 [float3] &[Row3](int row) { return [Row](row); }284 const [float3] &[Row3](int row) const { return [Row](row); }285 286 287 288 [CONST_WIN32] [float3] [Col](int col) const;289 [CONST_WIN32] [float3] [Col3](int col) const { return [Col](col); }290 291 292 293 [CONST_WIN32] [float3] [Diagonal]() const;294 295 296 void [ScaleRow](int row, float scalar);297 298 299 void [ScaleCol](int col, float scalar);300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 [float3] [WorldX]() const;322 323 324 [float3] [WorldY]() const;325 326 327 [float3] [WorldZ]() const;328 329 330 331 332 333 [FORCE_INLINE] float *[ptr]() { return &[v][0][0]; }334 [FORCE_INLINE] const float *[ptr]() const { return &[v][0][0]; }335 336 337 338 339 void [SetRow](int row, const float *data);340 void [SetRow](int row, float x, float y, float z);341 void [SetRow](int row, const [float3] &rowVector);342 343 344 345 346 void [SetCol](int column, const float *data);347 void [SetCol](int column, float x, float y, float z);348 void [SetCol](int column, const [float3] &columnVector);349 350 351 void [Set](float _00, float _01, float _02,352 float _10, float _11, float _12,353 float _20, float _21, float _22);354 355 356 void [Set](const [float3x3] &rhs);357 358 359 360 361 void [Set](const float *values);362 363 364 365 366 367 void [Set](int row, int col, float value);368 369 370 void [SetIdentity]();371 372 373 void [SwapColumns](int col1, int col2);374 375 376 void [SwapRows](int row1, int row2);377 378 379 380 void [SetRotatePartX](float angleRadians);381 382 void [SetRotatePartY](float angleRadians);383 384 void [SetRotatePartZ](float angleRadians);385 386 387 void [SetRotatePart](const [float3] &axisDirection, float angleRadians);388 389 void [SetRotatePart](const [Quat] &orientation);390 391 [float3x3] &[operator =](const [Quat] &rhs);392 [float3x3] &[operator =](const [float3x3] &rhs);393 394 395 396 397 398 399 400 401 float [Determinant]() const;402 403 404 405 406 407 float [DeterminantSymmetric]() const;408 409 410 411 412 413 414 415 416 bool [Inverse](float [epsilon] = 1[e]-6f);417 418 419 420 bool [InverseFast](float [epsilon] = 1[e]-6f);421 422 423 424 bool [SolveAxb]([float3] b, [float3] &x) const;425 426 427 428 429 [float3x3] [Inverted]() const;430 431 432 433 434 435 436 437 438 439 440 441 bool [InverseColOrthogonal]();442 443 444 445 446 447 448 449 450 451 bool [InverseOrthogonalUniformScale]();452 453 454 455 456 457 458 459 void [InverseOrthonormal]();460 461 462 463 464 465 466 467 bool [InverseSymmetric]();468 469 470 471 void [Transpose]();472 473 474 [float3x3] [Transposed]() const;475 476 477 478 bool [InverseTranspose]();479 480 481 482 [float3x3] [InverseTransposed]() const;483 484 485 float [Trace]() const;486 487 488 void [Orthonormalize](int firstColumn, int secondColumn, int thirdColumn);489 490 491 492 493 494 void [RemoveScale]();495 496 497 [float3] [Transform](const [float3] &vector) const;498 [float3] [Transform](float x, float y, float z) const;499 500 501 502 503 504 [float3] [TransformLeft](const [float3] &lhs) const;505 506 507 508 [float4] [Transform](const [float4] &vector) const;509 510 511 void [BatchTransform]([float3] *pointArray, int numPoints) const;512 513 514 void [BatchTransform]([float3] *pointArray, int numPoints, int stride) const;515 516 517 518 void [BatchTransform]([float4] *vectorArray, int numVectors) const;519 520 521 522 void [BatchTransform]([float4] *vectorArray, int numVectors, int stride) const;523 524 525 [float3x3] [operator *](const [float3x3] &rhs) const;526 527 528 [float3x3] [operator *](const [Quat] &rhs) const;529 530 531 [float3] [operator *](const [float3] &rhs) const;532 533 534 535 [float4] [operator *](const [float4] &rhs) const;536 537 [float3x3] [operator *](float scalar) const;538 [float3x3] [operator /](float scalar) const;539 [float3x3] [operator +](const [float3x3] &rhs) const;540 [float3x3] [operator -](const [float3x3] &rhs) const;541 [float3x3] [operator -]() const;542 543 544 [float3x3] [operator +]() const { return *this; }545 546 [float3x3] &[operator *=](float scalar);547 [float3x3] &[operator /=](float scalar);548 [float3x3] &[operator +=](const [float3x3] &rhs);549 [float3x3] &[operator -=](const [float3x3] &rhs);550 551 552 553 bool [IsFinite]() const;554 555 556 557 bool [IsIdentity](float [epsilon] = 1[e]-3f) const;558 559 560 561 bool [IsLowerTriangular](float [epsilon] = 1[e]-3f) const;562 563 564 565 bool [IsUpperTriangular](float [epsilon] = 1[e]-3f) const;566 567 568 569 bool [IsInvertible](float [epsilon] = 1[e]-3f) const;570 571 572 573 bool [IsSymmetric](float [epsilon] = 1[e]-3f) const;574 575 576 577 578 bool [IsSkewSymmetric](float [epsilon] = 1[e]-3f) const;579 580 581 582 583 584 585 586 bool [HasUnitaryScale](float epsilonSq = 1[e]-6f) const;587 588 589 590 591 592 593 bool [HasNegativeScale]() const;594 595 596 597 bool [HasUniformScale](float [epsilon] = 1[e]-3f) const;598 599 600 bool [IsRowOrthogonal](float [epsilon] = 1[e]-3f) const;601 602 603 bool [IsColOrthogonal](float [epsilon] = 1[e]-3f) const;604 bool [IsColOrthogonal3](float [epsilon] = 1[e]-3f) const { return [IsColOrthogonal]([epsilon]); }605 606 607 608 609 610 611 bool [IsOrthonormal](float [epsilon] = 1[e]-3f) const;612 613 614 bool [Equals](const [float3x3] &other, float [epsilon] = 1[e]-3f) const;615 616 #ifdef MATH_ENABLE_STL_SUPPORT617 618 std::string [ToString]() const;619 std::string [SerializeToString]() const;620 621 std::string [ToString2]() const;622 #endif623 624 625 626 627 628 629 [float3] [ToEulerXYX]() const;630 [float3] [ToEulerXZX]() const; 631 [float3] [ToEulerYXY]() const; 632 [float3] [ToEulerYZY]() const; 633 [float3] [ToEulerZXZ]() const; 634 [float3] [ToEulerZYZ]() const; 635 [float3] [ToEulerXYZ]() const; 636 [float3] [ToEulerXZY]() const; 637 [float3] [ToEulerYXZ]() const; 638 [float3] [ToEulerYZX]() const; 639 [float3] [ToEulerZXY]() const; 640 [float3] [ToEulerZYX]() const; 641 642 643 644 645 646 647 648 649 650 [float3] [ExtractScale]() const;651 652 653 654 655 656 657 658 659 660 661 void [Decompose]([Quat] &rotate, [float3] &scale) const;662 void [Decompose]([float3x3] &rotate, [float3] &scale) const;663 664 [float3x3] [Mul](const [float3x3] &rhs) const;665 [float3x4] [Mul](const [float3x4] &rhs) const;666 [float4x4] [Mul](const [float4x4] &rhs) const;667 [float3x3] [Mul](const [Quat] &rhs) const;668 [float3] [Mul](const [float3] &rhs) const;669 [float4] [Mul](const [float4] &rhs) const670 {671 return [float4]([Mul](rhs.[xyz]()), rhs.[w]);672 }673 [float3] [MulPos](const [float3] &rhs) const { return [Mul](rhs); }674 [float4] [MulPos](const [float4] &rhs) const675 {676 [assume](![EqualAbs](rhs.[w], 0.f));677 return [Mul](rhs);678 }679 [float3] [MulDir](const [float3] &rhs) const { return [Mul](rhs); }680 [float4] [MulDir](const [float4] &rhs) const681 {682 [assume]([EqualAbs](rhs.[w], 0.f));683 return [Mul](rhs);684 }685 686 #ifdef MATH_OGRE_INTEROP687 [float3x3](const Ogre::Matrix3 &m) { [Set](&m[0][0]); }688 operator Ogre::Matrix3() { return Ogre::Matrix3([v][0][0], [v][0][1], [v][0][2], [v][1][0], [v][1][1], [v][1][2], [v][2][0], [v][2][1], [v][2][2]); }689 #endif690 #ifdef MATH_BULLET_INTEROP691 [float3x3](const btMatrix3x3 &m) { [Set](m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2]); }692 operator btMatrix3x3() { return btMatrix3x3([v][0][0], [v][0][1], [v][0][2], [v][1][0], [v][1][1], [v][1][2], [v][2][0], [v][2][1], [v][2][2]); }693 #endif694 #ifdef MATH_QT_INTEROP695 operator QString() const { return toString(); }696 QString toString() const { return [ToString2]().c_str(); }697 #endif698 #ifdef MATH_URHO3D_INTEROP699 [float3x3](const Urho3D::Matrix3 &m) { [Set](m.m00_, m.m01_, m.m02_, m.m10_, m.m11_, m.m12_, m.m20_, m.m21_, m.m22_); }700 operator Urho3D::Matrix3() { return Urho3D::Matrix3([ptr]()); }701 #endif702 };703 704 #ifdef MATH_ENABLE_STL_SUPPORT705 706 std::ostream &[operator <<](std::ostream &out, const [float3x3] &rhs);707 #endif708 709 710 [float3x3] [operator *](const [Quat] &lhs, const [float3x3] &rhs);711 712 713 714 715 [float3] [operator *](const [float3] &lhs, const [float3x3] &rhs);716 717 718 719 720 721 [float4] [operator *](const [float4] &lhs, const [float3x3] &rhs);722 723 #ifdef MATH_QT_INTEROP724 Q_DECLARE_METATYPE([float3x3])725 Q_DECLARE_METATYPE([float3x3]*)726 #endif727 728 [MATH_END_NAMESPACE] Go back to previous page