From 1407f3953cb884f1fc2218db660e004097f3f27b Mon Sep 17 00:00:00 2001 From: Areloch Date: Sun, 15 Oct 2017 03:41:26 -0500 Subject: [PATCH 1/2] Tweaks the asMatrixF for RotationF, as well as exposes additional console methods for rotation manipulation --- Engine/source/math/mRotation.cpp | 71 +++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/Engine/source/math/mRotation.cpp b/Engine/source/math/mRotation.cpp index fad915888..8fe8228ae 100644 --- a/Engine/source/math/mRotation.cpp +++ b/Engine/source/math/mRotation.cpp @@ -252,14 +252,29 @@ MatrixF RotationF::asMatrixF() const MatrixF returnMat; if (mRotationType == Euler) { - returnMat.set(EulerF(x, y, z)); + MatrixF imat, xmat, ymat, zmat; + xmat.set(EulerF(x, 0, 0)); + ymat.set(EulerF(0.0f, y, 0.0f)); + zmat.set(EulerF(0, 0, z)); + imat.mul(zmat, xmat); + returnMat.mul(imat, ymat); } else { AngAxisF aa; aa.set(Point3F(x, y, z), w); - aa.setMatrix(&returnMat); + MatrixF tempMat; + aa.setMatrix(&tempMat); + + EulerF eul = tempMat.toEuler(); + + MatrixF imat, xmat, ymat, zmat; + xmat.set(EulerF(eul.x, 0, 0)); + ymat.set(EulerF(0.0f, eul.y, 0.0f)); + zmat.set(EulerF(0, 0, eul.z)); + imat.mul(zmat, xmat); + returnMat.mul(imat, ymat); } return returnMat; @@ -357,6 +372,58 @@ DefineConsoleStaticMethod(rotation, LookAt, RotationF, (Point3F origin, Point3F return result; } +DefineConsoleStaticMethod(rotation, setRightVector, RotationF, (RotationF a, VectorF rightVec), , + "Subtracts two rotations.\n" + "@param a Rotation one." + "@param b Rotation two." + "@returns v difference of both rotations." + "@ingroup Math") +{ + a.asMatrixF().setColumn(0, rightVec); + return a; +} + +DefineConsoleStaticMethod(rotation, setUpVector, RotationF, (RotationF a, VectorF upVec), , + "Subtracts two rotations.\n" + "@param a Rotation one." + "@param b Rotation two." + "@returns v difference of both rotations." + "@ingroup Math") +{ + a.asMatrixF().setColumn(2, upVec); + return a; +} + +DefineConsoleStaticMethod(rotation, getForwardVector, VectorF, (RotationF a), , + "Subtracts two rotations.\n" + "@param a Rotation one." + "@param b Rotation two." + "@returns v difference of both rotations." + "@ingroup Math") +{ + return a.asMatrixF().getForwardVector(); +} + +DefineConsoleStaticMethod(rotation, getRightVector, VectorF, (RotationF a), , + "Subtracts two rotations.\n" + "@param a Rotation one." + "@param b Rotation two." + "@returns v difference of both rotations." + "@ingroup Math") +{ + return a.asMatrixF().getRightVector(); +} + +DefineConsoleStaticMethod(rotation, getUpVector, VectorF, (RotationF a), , + "Subtracts two rotations.\n" + "@param a Rotation one." + "@param b Rotation two." + "@returns v difference of both rotations." + "@ingroup Math") +{ + return a.asMatrixF().getUpVector(); +} + DefineConsoleStaticMethod(rotation, getDirection, Point3F, (RotationF rot),, "Takes the angles of the provided rotation and returns a direction vector.\n" "@param rot Our rotation." From 0fde97f2543a27d4839ce569eb93ef05fc340cbf Mon Sep 17 00:00:00 2001 From: Areloch Date: Tue, 17 Oct 2017 21:50:53 -0500 Subject: [PATCH 2/2] Corrects the documentation. --- Engine/source/math/mRotation.cpp | 74 ++++++++++++++------------------ 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/Engine/source/math/mRotation.cpp b/Engine/source/math/mRotation.cpp index 8fe8228ae..6d9bc3b35 100644 --- a/Engine/source/math/mRotation.cpp +++ b/Engine/source/math/mRotation.cpp @@ -325,7 +325,7 @@ TEST(Maths, RotationF_Calculations) }; #endif -DefineConsoleStaticMethod(rotation, Add, RotationF, (RotationF a, RotationF b), , +DefineConsoleFunction(AddRotation, RotationF, (RotationF a, RotationF b), , "Adds two rotations together.\n" "@param a Rotation one." "@param b Rotation two." @@ -335,7 +335,7 @@ DefineConsoleStaticMethod(rotation, Add, RotationF, (RotationF a, RotationF b), return a + b; } -DefineConsoleStaticMethod(rotation, Subtract, RotationF, (RotationF a, RotationF b), , +DefineConsoleFunction(SubtractRotation, RotationF, (RotationF a, RotationF b), , "Subtracts two rotations.\n" "@param a Rotation one." "@param b Rotation two." @@ -345,7 +345,7 @@ DefineConsoleStaticMethod(rotation, Subtract, RotationF, (RotationF a, RotationF return a - b; } -DefineConsoleStaticMethod(rotation, Interpolate, RotationF, (RotationF a, RotationF b, F32 factor), , +DefineConsoleFunction(InterpolateRotation, RotationF, (RotationF a, RotationF b, F32 factor), , "Interpolates between two rotations.\n" "@param a Rotation one." "@param b Rotation two." @@ -358,7 +358,7 @@ DefineConsoleStaticMethod(rotation, Interpolate, RotationF, (RotationF a, Rotati return result; } -DefineConsoleStaticMethod(rotation, LookAt, RotationF, (Point3F origin, Point3F target, Point3F up), +DefineConsoleFunction(RotationLookAt, RotationF, (Point3F origin, Point3F target, Point3F up), (Point3F(0, 0, 0), Point3F(0, 0, 0), Point3F(0, 0, 1)), "Provides a rotation orientation to look at a target from a given position.\n" "@param origin Position of the object doing the looking." @@ -372,63 +372,55 @@ DefineConsoleStaticMethod(rotation, LookAt, RotationF, (Point3F origin, Point3F return result; } -DefineConsoleStaticMethod(rotation, setRightVector, RotationF, (RotationF a, VectorF rightVec), , - "Subtracts two rotations.\n" - "@param a Rotation one." - "@param b Rotation two." - "@returns v difference of both rotations." +DefineConsoleFunction(setRotationRightVector, RotationF, (RotationF rot, VectorF rightVec), , + "Sets the right vector of the rotation.\n" + "@param Starting rotation." + "@param New up vector." + "@returns New rotation with the set right vector." "@ingroup Math") { - a.asMatrixF().setColumn(0, rightVec); - return a; + rot.asMatrixF().setColumn(0, rightVec); + return rot; } -DefineConsoleStaticMethod(rotation, setUpVector, RotationF, (RotationF a, VectorF upVec), , - "Subtracts two rotations.\n" - "@param a Rotation one." - "@param b Rotation two." - "@returns v difference of both rotations." +DefineConsoleFunction(setRotationUpVector, RotationF, (RotationF rot, VectorF upVec), , + "Sets the up vector of the rotation.\n" + "@param Starting rotation." + "@param New up vector." + "@returns New rotation with the set up vector." "@ingroup Math") { - a.asMatrixF().setColumn(2, upVec); - return a; + rot.asMatrixF().setColumn(2, upVec); + return rot; } -DefineConsoleStaticMethod(rotation, getForwardVector, VectorF, (RotationF a), , - "Subtracts two rotations.\n" - "@param a Rotation one." - "@param b Rotation two." - "@returns v difference of both rotations." +DefineConsoleFunction(getRotationForwardVector, VectorF, (RotationF rot), , + "Get the forward vector of a rotation.\n" "@ingroup Math") { - return a.asMatrixF().getForwardVector(); + return rot.asMatrixF().getForwardVector(); } -DefineConsoleStaticMethod(rotation, getRightVector, VectorF, (RotationF a), , - "Subtracts two rotations.\n" - "@param a Rotation one." - "@param b Rotation two." - "@returns v difference of both rotations." +DefineConsoleFunction(getRotationRightVector, VectorF, (RotationF rot), , + "Gets the right vector of a rotation.\n" + "@param Our rotation." "@ingroup Math") { - return a.asMatrixF().getRightVector(); + return rot.asMatrixF().getRightVector(); } -DefineConsoleStaticMethod(rotation, getUpVector, VectorF, (RotationF a), , - "Subtracts two rotations.\n" - "@param a Rotation one." - "@param b Rotation two." - "@returns v difference of both rotations." +DefineConsoleFunction(getRotationUpVector, VectorF, (RotationF rot), , + "Gets the up vector of a rotation.\n" + "@param Our rotation." "@ingroup Math") { - return a.asMatrixF().getUpVector(); + return rot.asMatrixF().getUpVector(); } -DefineConsoleStaticMethod(rotation, getDirection, Point3F, (RotationF rot),, -"Takes the angles of the provided rotation and returns a direction vector.\n" -"@param rot Our rotation." -"@returns v Direction vector result." -"@ingroup Math") +DefineConsoleFunction(getRotationDirection, Point3F, (RotationF rot),, + "Gets the direction from the rotation's angles.\n" + "@param Our rotation." + "@ingroup Math") { return rot.getDirection(); }