/usr/include/OGRE/OgreMatrix4.h is in libogre-1.8-dev 1.8.0+dfsg1-7+b1.
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 | /*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2012 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Matrix4__
#define __Matrix4__
// Precompiler options
#include "OgrePrerequisites.h"
#include "OgreVector3.h"
#include "OgreMatrix3.h"
#include "OgreVector4.h"
#include "OgrePlane.h"
namespace Ogre
{
/** \addtogroup Core
* @{
*/
/** \addtogroup Math
* @{
*/
/** Class encapsulating a standard 4x4 homogeneous matrix.
@remarks
OGRE uses column vectors when applying matrix multiplications,
This means a vector is represented as a single column, 4-row
matrix. This has the effect that the transformations implemented
by the matrices happens right-to-left e.g. if vector V is to be
transformed by M1 then M2 then M3, the calculation would be
M3 * M2 * M1 * V. The order that matrices are concatenated is
vital since matrix multiplication is not commutative, i.e. you
can get a different result if you concatenate in the wrong order.
@par
The use of column vectors and right-to-left ordering is the
standard in most mathematical texts, and is the same as used in
OpenGL. It is, however, the opposite of Direct3D, which has
inexplicably chosen to differ from the accepted standard and uses
row vectors and left-to-right matrix multiplication.
@par
OGRE deals with the differences between D3D and OpenGL etc.
internally when operating through different render systems. OGRE
users only need to conform to standard maths conventions, i.e.
right-to-left matrix multiplication, (OGRE transposes matrices it
passes to D3D to compensate).
@par
The generic form M * V which shows the layout of the matrix
entries is shown below:
<pre>
[ m[0][0] m[0][1] m[0][2] m[0][3] ] {x}
| m[1][0] m[1][1] m[1][2] m[1][3] | * {y}
| m[2][0] m[2][1] m[2][2] m[2][3] | {z}
[ m[3][0] m[3][1] m[3][2] m[3][3] ] {1}
</pre>
*/
class _OgreExport Matrix4
{
protected:
/// The matrix entries, indexed by [row][col].
union {
Real m[4][4];
Real _m[16];
};
public:
/** Default constructor.
@note
It does <b>NOT</b> initialize the matrix for efficiency.
*/
inline Matrix4()
{
}
inline Matrix4(
Real m00, Real m01, Real m02, Real m03,
Real m10, Real m11, Real m12, Real m13,
Real m20, Real m21, Real m22, Real m23,
Real m30, Real m31, Real m32, Real m33 )
{
m[0][0] = m00;
m[0][1] = m01;
m[0][2] = m02;
m[0][3] = m03;
m[1][0] = m10;
m[1][1] = m11;
m[1][2] = m12;
m[1][3] = m13;
m[2][0] = m20;
m[2][1] = m21;
m[2][2] = m22;
m[2][3] = m23;
m[3][0] = m30;
m[3][1] = m31;
m[3][2] = m32;
m[3][3] = m33;
}
/** Creates a standard 4x4 transformation matrix with a zero translation part from a rotation/scaling 3x3 matrix.
*/
inline Matrix4(const Matrix3& m3x3)
{
operator=(IDENTITY);
operator=(m3x3);
}
/** Creates a standard 4x4 transformation matrix with a zero translation part from a rotation/scaling Quaternion.
*/
inline Matrix4(const Quaternion& rot)
{
Matrix3 m3x3;
rot.ToRotationMatrix(m3x3);
operator=(IDENTITY);
operator=(m3x3);
}
/** Exchange the contents of this matrix with another.
*/
inline void swap(Matrix4& other)
{
std::swap(m[0][0], other.m[0][0]);
std::swap(m[0][1], other.m[0][1]);
std::swap(m[0][2], other.m[0][2]);
std::swap(m[0][3], other.m[0][3]);
std::swap(m[1][0], other.m[1][0]);
std::swap(m[1][1], other.m[1][1]);
std::swap(m[1][2], other.m[1][2]);
std::swap(m[1][3], other.m[1][3]);
std::swap(m[2][0], other.m[2][0]);
std::swap(m[2][1], other.m[2][1]);
std::swap(m[2][2], other.m[2][2]);
std::swap(m[2][3], other.m[2][3]);
std::swap(m[3][0], other.m[3][0]);
std::swap(m[3][1], other.m[3][1]);
std::swap(m[3][2], other.m[3][2]);
std::swap(m[3][3], other.m[3][3]);
}
inline Real* operator [] ( size_t iRow )
{
assert( iRow < 4 );
return m[iRow];
}
inline const Real *operator [] ( size_t iRow ) const
{
assert( iRow < 4 );
return m[iRow];
}
inline Matrix4 concatenate(const Matrix4 &m2) const
{
Matrix4 r;
r.m[0][0] = m[0][0] * m2.m[0][0] + m[0][1] * m2.m[1][0] + m[0][2] * m2.m[2][0] + m[0][3] * m2.m[3][0];
r.m[0][1] = m[0][0] * m2.m[0][1] + m[0][1] * m2.m[1][1] + m[0][2] * m2.m[2][1] + m[0][3] * m2.m[3][1];
r.m[0][2] = m[0][0] * m2.m[0][2] + m[0][1] * m2.m[1][2] + m[0][2] * m2.m[2][2] + m[0][3] * m2.m[3][2];
r.m[0][3] = m[0][0] * m2.m[0][3] + m[0][1] * m2.m[1][3] + m[0][2] * m2.m[2][3] + m[0][3] * m2.m[3][3];
r.m[1][0] = m[1][0] * m2.m[0][0] + m[1][1] * m2.m[1][0] + m[1][2] * m2.m[2][0] + m[1][3] * m2.m[3][0];
r.m[1][1] = m[1][0] * m2.m[0][1] + m[1][1] * m2.m[1][1] + m[1][2] * m2.m[2][1] + m[1][3] * m2.m[3][1];
r.m[1][2] = m[1][0] * m2.m[0][2] + m[1][1] * m2.m[1][2] + m[1][2] * m2.m[2][2] + m[1][3] * m2.m[3][2];
r.m[1][3] = m[1][0] * m2.m[0][3] + m[1][1] * m2.m[1][3] + m[1][2] * m2.m[2][3] + m[1][3] * m2.m[3][3];
r.m[2][0] = m[2][0] * m2.m[0][0] + m[2][1] * m2.m[1][0] + m[2][2] * m2.m[2][0] + m[2][3] * m2.m[3][0];
r.m[2][1] = m[2][0] * m2.m[0][1] + m[2][1] * m2.m[1][1] + m[2][2] * m2.m[2][1] + m[2][3] * m2.m[3][1];
r.m[2][2] = m[2][0] * m2.m[0][2] + m[2][1] * m2.m[1][2] + m[2][2] * m2.m[2][2] + m[2][3] * m2.m[3][2];
r.m[2][3] = m[2][0] * m2.m[0][3] + m[2][1] * m2.m[1][3] + m[2][2] * m2.m[2][3] + m[2][3] * m2.m[3][3];
r.m[3][0] = m[3][0] * m2.m[0][0] + m[3][1] * m2.m[1][0] + m[3][2] * m2.m[2][0] + m[3][3] * m2.m[3][0];
r.m[3][1] = m[3][0] * m2.m[0][1] + m[3][1] * m2.m[1][1] + m[3][2] * m2.m[2][1] + m[3][3] * m2.m[3][1];
r.m[3][2] = m[3][0] * m2.m[0][2] + m[3][1] * m2.m[1][2] + m[3][2] * m2.m[2][2] + m[3][3] * m2.m[3][2];
r.m[3][3] = m[3][0] * m2.m[0][3] + m[3][1] * m2.m[1][3] + m[3][2] * m2.m[2][3] + m[3][3] * m2.m[3][3];
return r;
}
/** Matrix concatenation using '*'.
*/
inline Matrix4 operator * ( const Matrix4 &m2 ) const
{
return concatenate( m2 );
}
/** Vector transformation using '*'.
@remarks
Transforms the given 3-D vector by the matrix, projecting the
result back into <i>w</i> = 1.
@note
This means that the initial <i>w</i> is considered to be 1.0,
and then all the tree elements of the resulting 3-D vector are
divided by the resulting <i>w</i>.
*/
inline Vector3 operator * ( const Vector3 &v ) const
{
Vector3 r;
Real fInvW = 1.0f / ( m[3][0] * v.x + m[3][1] * v.y + m[3][2] * v.z + m[3][3] );
r.x = ( m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] ) * fInvW;
r.y = ( m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] ) * fInvW;
r.z = ( m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] ) * fInvW;
return r;
}
inline Vector4 operator * (const Vector4& v) const
{
return Vector4(
m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] * v.w,
m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] * v.w,
m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] * v.w,
m[3][0] * v.x + m[3][1] * v.y + m[3][2] * v.z + m[3][3] * v.w
);
}
inline Plane operator * (const Plane& p) const
{
Plane ret;
Matrix4 invTrans = inverse().transpose();
Vector4 v4( p.normal.x, p.normal.y, p.normal.z, p.d );
v4 = invTrans * v4;
ret.normal.x = v4.x;
ret.normal.y = v4.y;
ret.normal.z = v4.z;
ret.d = v4.w / ret.normal.normalise();
return ret;
}
/** Matrix addition.
*/
inline Matrix4 operator + ( const Matrix4 &m2 ) const
{
Matrix4 r;
r.m[0][0] = m[0][0] + m2.m[0][0];
r.m[0][1] = m[0][1] + m2.m[0][1];
r.m[0][2] = m[0][2] + m2.m[0][2];
r.m[0][3] = m[0][3] + m2.m[0][3];
r.m[1][0] = m[1][0] + m2.m[1][0];
r.m[1][1] = m[1][1] + m2.m[1][1];
r.m[1][2] = m[1][2] + m2.m[1][2];
r.m[1][3] = m[1][3] + m2.m[1][3];
r.m[2][0] = m[2][0] + m2.m[2][0];
r.m[2][1] = m[2][1] + m2.m[2][1];
r.m[2][2] = m[2][2] + m2.m[2][2];
r.m[2][3] = m[2][3] + m2.m[2][3];
r.m[3][0] = m[3][0] + m2.m[3][0];
r.m[3][1] = m[3][1] + m2.m[3][1];
r.m[3][2] = m[3][2] + m2.m[3][2];
r.m[3][3] = m[3][3] + m2.m[3][3];
return r;
}
/** Matrix subtraction.
*/
inline Matrix4 operator - ( const Matrix4 &m2 ) const
{
Matrix4 r;
r.m[0][0] = m[0][0] - m2.m[0][0];
r.m[0][1] = m[0][1] - m2.m[0][1];
r.m[0][2] = m[0][2] - m2.m[0][2];
r.m[0][3] = m[0][3] - m2.m[0][3];
r.m[1][0] = m[1][0] - m2.m[1][0];
r.m[1][1] = m[1][1] - m2.m[1][1];
r.m[1][2] = m[1][2] - m2.m[1][2];
r.m[1][3] = m[1][3] - m2.m[1][3];
r.m[2][0] = m[2][0] - m2.m[2][0];
r.m[2][1] = m[2][1] - m2.m[2][1];
r.m[2][2] = m[2][2] - m2.m[2][2];
r.m[2][3] = m[2][3] - m2.m[2][3];
r.m[3][0] = m[3][0] - m2.m[3][0];
r.m[3][1] = m[3][1] - m2.m[3][1];
r.m[3][2] = m[3][2] - m2.m[3][2];
r.m[3][3] = m[3][3] - m2.m[3][3];
return r;
}
/** Tests 2 matrices for equality.
*/
inline bool operator == ( const Matrix4& m2 ) const
{
if(
m[0][0] != m2.m[0][0] || m[0][1] != m2.m[0][1] || m[0][2] != m2.m[0][2] || m[0][3] != m2.m[0][3] ||
m[1][0] != m2.m[1][0] || m[1][1] != m2.m[1][1] || m[1][2] != m2.m[1][2] || m[1][3] != m2.m[1][3] ||
m[2][0] != m2.m[2][0] || m[2][1] != m2.m[2][1] || m[2][2] != m2.m[2][2] || m[2][3] != m2.m[2][3] ||
m[3][0] != m2.m[3][0] || m[3][1] != m2.m[3][1] || m[3][2] != m2.m[3][2] || m[3][3] != m2.m[3][3] )
return false;
return true;
}
/** Tests 2 matrices for inequality.
*/
inline bool operator != ( const Matrix4& m2 ) const
{
if(
m[0][0] != m2.m[0][0] || m[0][1] != m2.m[0][1] || m[0][2] != m2.m[0][2] || m[0][3] != m2.m[0][3] ||
m[1][0] != m2.m[1][0] || m[1][1] != m2.m[1][1] || m[1][2] != m2.m[1][2] || m[1][3] != m2.m[1][3] ||
m[2][0] != m2.m[2][0] || m[2][1] != m2.m[2][1] || m[2][2] != m2.m[2][2] || m[2][3] != m2.m[2][3] ||
m[3][0] != m2.m[3][0] || m[3][1] != m2.m[3][1] || m[3][2] != m2.m[3][2] || m[3][3] != m2.m[3][3] )
return true;
return false;
}
/** Assignment from 3x3 matrix.
*/
inline void operator = ( const Matrix3& mat3 )
{
m[0][0] = mat3.m[0][0]; m[0][1] = mat3.m[0][1]; m[0][2] = mat3.m[0][2];
m[1][0] = mat3.m[1][0]; m[1][1] = mat3.m[1][1]; m[1][2] = mat3.m[1][2];
m[2][0] = mat3.m[2][0]; m[2][1] = mat3.m[2][1]; m[2][2] = mat3.m[2][2];
}
inline Matrix4 transpose(void) const
{
return Matrix4(m[0][0], m[1][0], m[2][0], m[3][0],
m[0][1], m[1][1], m[2][1], m[3][1],
m[0][2], m[1][2], m[2][2], m[3][2],
m[0][3], m[1][3], m[2][3], m[3][3]);
}
/*
-----------------------------------------------------------------------
Translation Transformation
-----------------------------------------------------------------------
*/
/** Sets the translation transformation part of the matrix.
*/
inline void setTrans( const Vector3& v )
{
m[0][3] = v.x;
m[1][3] = v.y;
m[2][3] = v.z;
}
/** Extracts the translation transformation part of the matrix.
*/
inline Vector3 getTrans() const
{
return Vector3(m[0][3], m[1][3], m[2][3]);
}
/** Builds a translation matrix
*/
inline void makeTrans( const Vector3& v )
{
m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0; m[0][3] = v.x;
m[1][0] = 0.0; m[1][1] = 1.0; m[1][2] = 0.0; m[1][3] = v.y;
m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0; m[2][3] = v.z;
m[3][0] = 0.0; m[3][1] = 0.0; m[3][2] = 0.0; m[3][3] = 1.0;
}
inline void makeTrans( Real tx, Real ty, Real tz )
{
m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0; m[0][3] = tx;
m[1][0] = 0.0; m[1][1] = 1.0; m[1][2] = 0.0; m[1][3] = ty;
m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0; m[2][3] = tz;
m[3][0] = 0.0; m[3][1] = 0.0; m[3][2] = 0.0; m[3][3] = 1.0;
}
/** Gets a translation matrix.
*/
inline static Matrix4 getTrans( const Vector3& v )
{
Matrix4 r;
r.m[0][0] = 1.0; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = v.x;
r.m[1][0] = 0.0; r.m[1][1] = 1.0; r.m[1][2] = 0.0; r.m[1][3] = v.y;
r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = 1.0; r.m[2][3] = v.z;
r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
return r;
}
/** Gets a translation matrix - variation for not using a vector.
*/
inline static Matrix4 getTrans( Real t_x, Real t_y, Real t_z )
{
Matrix4 r;
r.m[0][0] = 1.0; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = t_x;
r.m[1][0] = 0.0; r.m[1][1] = 1.0; r.m[1][2] = 0.0; r.m[1][3] = t_y;
r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = 1.0; r.m[2][3] = t_z;
r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
return r;
}
/*
-----------------------------------------------------------------------
Scale Transformation
-----------------------------------------------------------------------
*/
/** Sets the scale part of the matrix.
*/
inline void setScale( const Vector3& v )
{
m[0][0] = v.x;
m[1][1] = v.y;
m[2][2] = v.z;
}
/** Gets a scale matrix.
*/
inline static Matrix4 getScale( const Vector3& v )
{
Matrix4 r;
r.m[0][0] = v.x; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = 0.0;
r.m[1][0] = 0.0; r.m[1][1] = v.y; r.m[1][2] = 0.0; r.m[1][3] = 0.0;
r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = v.z; r.m[2][3] = 0.0;
r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
return r;
}
/** Gets a scale matrix - variation for not using a vector.
*/
inline static Matrix4 getScale( Real s_x, Real s_y, Real s_z )
{
Matrix4 r;
r.m[0][0] = s_x; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = 0.0;
r.m[1][0] = 0.0; r.m[1][1] = s_y; r.m[1][2] = 0.0; r.m[1][3] = 0.0;
r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = s_z; r.m[2][3] = 0.0;
r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
return r;
}
/** Extracts the rotation / scaling part of the Matrix as a 3x3 matrix.
@param m3x3 Destination Matrix3
*/
inline void extract3x3Matrix(Matrix3& m3x3) const
{
m3x3.m[0][0] = m[0][0];
m3x3.m[0][1] = m[0][1];
m3x3.m[0][2] = m[0][2];
m3x3.m[1][0] = m[1][0];
m3x3.m[1][1] = m[1][1];
m3x3.m[1][2] = m[1][2];
m3x3.m[2][0] = m[2][0];
m3x3.m[2][1] = m[2][1];
m3x3.m[2][2] = m[2][2];
}
/** Determines if this matrix involves a scaling. */
inline bool hasScale() const
{
// check magnitude of column vectors (==local axes)
Real t = m[0][0] * m[0][0] + m[1][0] * m[1][0] + m[2][0] * m[2][0];
if (!Math::RealEqual(t, 1.0, (Real)1e-04))
return true;
t = m[0][1] * m[0][1] + m[1][1] * m[1][1] + m[2][1] * m[2][1];
if (!Math::RealEqual(t, 1.0, (Real)1e-04))
return true;
t = m[0][2] * m[0][2] + m[1][2] * m[1][2] + m[2][2] * m[2][2];
if (!Math::RealEqual(t, 1.0, (Real)1e-04))
return true;
return false;
}
/** Determines if this matrix involves a negative scaling. */
inline bool hasNegativeScale() const
{
return determinant() < 0;
}
/** Extracts the rotation / scaling part as a quaternion from the Matrix.
*/
inline Quaternion extractQuaternion() const
{
Matrix3 m3x3;
extract3x3Matrix(m3x3);
return Quaternion(m3x3);
}
static const Matrix4 ZERO;
static const Matrix4 ZEROAFFINE;
static const Matrix4 IDENTITY;
/** Useful little matrix which takes 2D clipspace {-1, 1} to {0,1}
and inverts the Y. */
static const Matrix4 CLIPSPACE2DTOIMAGESPACE;
inline Matrix4 operator*(Real scalar) const
{
return Matrix4(
scalar*m[0][0], scalar*m[0][1], scalar*m[0][2], scalar*m[0][3],
scalar*m[1][0], scalar*m[1][1], scalar*m[1][2], scalar*m[1][3],
scalar*m[2][0], scalar*m[2][1], scalar*m[2][2], scalar*m[2][3],
scalar*m[3][0], scalar*m[3][1], scalar*m[3][2], scalar*m[3][3]);
}
/** Function for writing to a stream.
*/
inline _OgreExport friend std::ostream& operator <<
( std::ostream& o, const Matrix4& mat )
{
o << "Matrix4(";
for (size_t i = 0; i < 4; ++i)
{
o << " row" << (unsigned)i << "{";
for(size_t j = 0; j < 4; ++j)
{
o << mat[i][j] << " ";
}
o << "}";
}
o << ")";
return o;
}
Matrix4 adjoint() const;
Real determinant() const;
Matrix4 inverse() const;
/** Building a Matrix4 from orientation / scale / position.
@remarks
Transform is performed in the order scale, rotate, translation, i.e. translation is independent
of orientation axes, scale does not affect size of translation, rotation and scaling are always
centered on the origin.
*/
void makeTransform(const Vector3& position, const Vector3& scale, const Quaternion& orientation);
/** Building an inverse Matrix4 from orientation / scale / position.
@remarks
As makeTransform except it build the inverse given the same data as makeTransform, so
performing -translation, -rotate, 1/scale in that order.
*/
void makeInverseTransform(const Vector3& position, const Vector3& scale, const Quaternion& orientation);
/** Decompose a Matrix4 to orientation / scale / position.
*/
void decomposition(Vector3& position, Vector3& scale, Quaternion& orientation) const;
/** Check whether or not the matrix is affine matrix.
@remarks
An affine matrix is a 4x4 matrix with row 3 equal to (0, 0, 0, 1),
e.g. no projective coefficients.
*/
inline bool isAffine(void) const
{
return m[3][0] == 0 && m[3][1] == 0 && m[3][2] == 0 && m[3][3] == 1;
}
/** Returns the inverse of the affine matrix.
@note
The matrix must be an affine matrix. @see Matrix4::isAffine.
*/
Matrix4 inverseAffine(void) const;
/** Concatenate two affine matrices.
@note
The matrices must be affine matrix. @see Matrix4::isAffine.
*/
inline Matrix4 concatenateAffine(const Matrix4 &m2) const
{
assert(isAffine() && m2.isAffine());
return Matrix4(
m[0][0] * m2.m[0][0] + m[0][1] * m2.m[1][0] + m[0][2] * m2.m[2][0],
m[0][0] * m2.m[0][1] + m[0][1] * m2.m[1][1] + m[0][2] * m2.m[2][1],
m[0][0] * m2.m[0][2] + m[0][1] * m2.m[1][2] + m[0][2] * m2.m[2][2],
m[0][0] * m2.m[0][3] + m[0][1] * m2.m[1][3] + m[0][2] * m2.m[2][3] + m[0][3],
m[1][0] * m2.m[0][0] + m[1][1] * m2.m[1][0] + m[1][2] * m2.m[2][0],
m[1][0] * m2.m[0][1] + m[1][1] * m2.m[1][1] + m[1][2] * m2.m[2][1],
m[1][0] * m2.m[0][2] + m[1][1] * m2.m[1][2] + m[1][2] * m2.m[2][2],
m[1][0] * m2.m[0][3] + m[1][1] * m2.m[1][3] + m[1][2] * m2.m[2][3] + m[1][3],
m[2][0] * m2.m[0][0] + m[2][1] * m2.m[1][0] + m[2][2] * m2.m[2][0],
m[2][0] * m2.m[0][1] + m[2][1] * m2.m[1][1] + m[2][2] * m2.m[2][1],
m[2][0] * m2.m[0][2] + m[2][1] * m2.m[1][2] + m[2][2] * m2.m[2][2],
m[2][0] * m2.m[0][3] + m[2][1] * m2.m[1][3] + m[2][2] * m2.m[2][3] + m[2][3],
0, 0, 0, 1);
}
/** 3-D Vector transformation specially for an affine matrix.
@remarks
Transforms the given 3-D vector by the matrix, projecting the
result back into <i>w</i> = 1.
@note
The matrix must be an affine matrix. @see Matrix4::isAffine.
*/
inline Vector3 transformAffine(const Vector3& v) const
{
assert(isAffine());
return Vector3(
m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3],
m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3],
m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3]);
}
/** 4-D Vector transformation specially for an affine matrix.
@note
The matrix must be an affine matrix. @see Matrix4::isAffine.
*/
inline Vector4 transformAffine(const Vector4& v) const
{
assert(isAffine());
return Vector4(
m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] * v.w,
m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] * v.w,
m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] * v.w,
v.w);
}
};
/* Removed from Vector4 and made a non-member here because otherwise
OgreMatrix4.h and OgreVector4.h have to try to include and inline each
other, which frankly doesn't work ;)
*/
inline Vector4 operator * (const Vector4& v, const Matrix4& mat)
{
return Vector4(
v.x*mat[0][0] + v.y*mat[1][0] + v.z*mat[2][0] + v.w*mat[3][0],
v.x*mat[0][1] + v.y*mat[1][1] + v.z*mat[2][1] + v.w*mat[3][1],
v.x*mat[0][2] + v.y*mat[1][2] + v.z*mat[2][2] + v.w*mat[3][2],
v.x*mat[0][3] + v.y*mat[1][3] + v.z*mat[2][3] + v.w*mat[3][3]
);
}
/** @} */
/** @} */
}
#endif
|