mirror of
https://github.com/minetest/irrlicht.git
synced 2025-03-23 12:40:33 +01:00
Reduce redundant code in core::quaternion
Instead of using same matrix calculations 3 times, getMatrixCenter and getMatrix now both call getMatrixFast. Additional function call might be slight cost in debug, in release compilers hopefully inline it away. Also getMatrix_transposed now split into getMatrix_transposed and getMatrixFast_transposed to make it similar to getMatrix. This also avoids a bunch of level 4 warnings in VS about function variables hiding class variables, which was why I started on this. Thought I also prefer having less code here. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6587 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
c35e0412a3
commit
1d3794c8b4
@ -130,7 +130,10 @@ class quaternion
|
|||||||
*/
|
*/
|
||||||
void getMatrixCenter( matrix4 &dest, const core::vector3df ¢er, const core::vector3df &translation ) const;
|
void getMatrixCenter( matrix4 &dest, const core::vector3df ¢er, const core::vector3df &translation ) const;
|
||||||
|
|
||||||
//! Creates a matrix from this quaternion
|
//! Faster method to create a transposed matrix, you should normalize the quaternion before!
|
||||||
|
inline void getMatrixFast_transposed(matrix4 &dest) const;
|
||||||
|
|
||||||
|
//! Creates a transposed matrix from this quaternion
|
||||||
inline void getMatrix_transposed( matrix4 &dest ) const;
|
inline void getMatrix_transposed( matrix4 &dest ) const;
|
||||||
|
|
||||||
//! Inverts this quaternion
|
//! Inverts this quaternion
|
||||||
@ -392,32 +395,11 @@ inline void quaternion::getMatrix(matrix4 &dest,
|
|||||||
|
|
||||||
quaternion q( *this);
|
quaternion q( *this);
|
||||||
q.normalize();
|
q.normalize();
|
||||||
f32 X = q.X;
|
q.getMatrixFast(dest);
|
||||||
f32 Y = q.Y;
|
|
||||||
f32 Z = q.Z;
|
|
||||||
f32 W = q.W;
|
|
||||||
|
|
||||||
dest[0] = 1.0f - 2.0f*Y*Y - 2.0f*Z*Z;
|
|
||||||
dest[1] = 2.0f*X*Y + 2.0f*Z*W;
|
|
||||||
dest[2] = 2.0f*X*Z - 2.0f*Y*W;
|
|
||||||
dest[3] = 0.0f;
|
|
||||||
|
|
||||||
dest[4] = 2.0f*X*Y - 2.0f*Z*W;
|
|
||||||
dest[5] = 1.0f - 2.0f*X*X - 2.0f*Z*Z;
|
|
||||||
dest[6] = 2.0f*Z*Y + 2.0f*X*W;
|
|
||||||
dest[7] = 0.0f;
|
|
||||||
|
|
||||||
dest[8] = 2.0f*X*Z + 2.0f*Y*W;
|
|
||||||
dest[9] = 2.0f*Z*Y - 2.0f*X*W;
|
|
||||||
dest[10] = 1.0f - 2.0f*X*X - 2.0f*Y*Y;
|
|
||||||
dest[11] = 0.0f;
|
|
||||||
|
|
||||||
dest[12] = center.X;
|
dest[12] = center.X;
|
||||||
dest[13] = center.Y;
|
dest[13] = center.Y;
|
||||||
dest[14] = center.Z;
|
dest[14] = center.Z;
|
||||||
dest[15] = 1.f;
|
|
||||||
|
|
||||||
dest.setDefinitelyIdentityMatrix ( false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -439,39 +421,14 @@ inline void quaternion::getMatrixCenter(matrix4 &dest,
|
|||||||
{
|
{
|
||||||
quaternion q(*this);
|
quaternion q(*this);
|
||||||
q.normalize();
|
q.normalize();
|
||||||
f32 X = q.X;
|
q.getMatrixFast(dest);
|
||||||
f32 Y = q.Y;
|
|
||||||
f32 Z = q.Z;
|
|
||||||
f32 W = q.W;
|
|
||||||
|
|
||||||
dest[0] = 1.0f - 2.0f*Y*Y - 2.0f*Z*Z;
|
|
||||||
dest[1] = 2.0f*X*Y + 2.0f*Z*W;
|
|
||||||
dest[2] = 2.0f*X*Z - 2.0f*Y*W;
|
|
||||||
dest[3] = 0.0f;
|
|
||||||
|
|
||||||
dest[4] = 2.0f*X*Y - 2.0f*Z*W;
|
|
||||||
dest[5] = 1.0f - 2.0f*X*X - 2.0f*Z*Z;
|
|
||||||
dest[6] = 2.0f*Z*Y + 2.0f*X*W;
|
|
||||||
dest[7] = 0.0f;
|
|
||||||
|
|
||||||
dest[8] = 2.0f*X*Z + 2.0f*Y*W;
|
|
||||||
dest[9] = 2.0f*Z*Y - 2.0f*X*W;
|
|
||||||
dest[10] = 1.0f - 2.0f*X*X - 2.0f*Y*Y;
|
|
||||||
dest[11] = 0.0f;
|
|
||||||
|
|
||||||
dest.setRotationCenter ( center, translation );
|
dest.setRotationCenter ( center, translation );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a matrix from this quaternion
|
//! Faster method to create a transposed matrix, you should normalize the quaternion before!
|
||||||
inline void quaternion::getMatrix_transposed(matrix4 &dest) const
|
inline void quaternion::getMatrixFast_transposed(matrix4 &dest) const
|
||||||
{
|
{
|
||||||
quaternion q(*this);
|
|
||||||
q.normalize();
|
|
||||||
f32 X = q.X;
|
|
||||||
f32 Y = q.Y;
|
|
||||||
f32 Z = q.Z;
|
|
||||||
f32 W = q.W;
|
|
||||||
|
|
||||||
dest[0] = 1.0f - 2.0f*Y*Y - 2.0f*Z*Z;
|
dest[0] = 1.0f - 2.0f*Y*Y - 2.0f*Z*Z;
|
||||||
dest[4] = 2.0f*X*Y + 2.0f*Z*W;
|
dest[4] = 2.0f*X*Y + 2.0f*Z*W;
|
||||||
dest[8] = 2.0f*X*Z - 2.0f*Y*W;
|
dest[8] = 2.0f*X*Z - 2.0f*Y*W;
|
||||||
@ -495,6 +452,14 @@ inline void quaternion::getMatrix_transposed(matrix4 &dest) const
|
|||||||
dest.setDefinitelyIdentityMatrix(false);
|
dest.setDefinitelyIdentityMatrix(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creates a matrix from this quaternion
|
||||||
|
inline void quaternion::getMatrix_transposed(matrix4 &dest) const
|
||||||
|
{
|
||||||
|
quaternion q(*this);
|
||||||
|
q.normalize();
|
||||||
|
q.getMatrixFast_transposed(dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Inverts this quaternion
|
// Inverts this quaternion
|
||||||
inline quaternion& quaternion::makeInverse()
|
inline quaternion& quaternion::makeInverse()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Tests finished. 72 tests of 72 passed.
|
Tests finished. 72 tests of 72 passed.
|
||||||
Compiled as DEBUG
|
Compiled as DEBUG
|
||||||
Test suite pass at GMT Sun Dec 31 17:50:49 2023
|
Test suite pass at GMT Sat Jan 27 14:25:49 2024
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user