mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 23:54:35 +00:00
Merge pull request #1949 from Areloch/getSignedAngleFunc
Adds the getSignedAngleBetweenVectors function
This commit is contained in:
commit
9c7b5eec73
3 changed files with 34 additions and 0 deletions
|
|
@ -373,3 +373,20 @@ DefineConsoleFunction( mGetAngleBetweenVectors, F32, (VectorF vecA, VectorF vecB
|
||||||
{
|
{
|
||||||
return MathUtils::getAngleBetweenVectors(vecA, vecB);
|
return MathUtils::getAngleBetweenVectors(vecA, vecB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DefineConsoleFunction(mGetSignedAngleBetweenVectors, F32, (VectorF vecA, VectorF vecB, VectorF norm), (VectorF::Zero, VectorF::Zero, VectorF::Zero),
|
||||||
|
"Returns signed angle between two vectors, using a normal for orientation.\n"
|
||||||
|
"@param vecA First input vector."
|
||||||
|
"@param vecB Second input vector."
|
||||||
|
"@param norm Normal/Cross Product vector."
|
||||||
|
"@returns Angle between both vectors in radians."
|
||||||
|
"@ingroup Math")
|
||||||
|
{
|
||||||
|
if (vecA.isZero() || vecB.isZero() || norm.isZero())
|
||||||
|
{
|
||||||
|
Con::errorf("mGetSignedAngleBetweenVectors - Error! Requires all 3 vectors used to be non-zero!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MathUtils::getSignedAngleBetweenVectors(vecA, vecB, norm);
|
||||||
|
}
|
||||||
|
|
@ -371,6 +371,18 @@ F32 getAngleBetweenVectors(VectorF vecA, VectorF vecB)
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
F32 getSignedAngleBetweenVectors(VectorF vecA, VectorF vecB, VectorF norm)
|
||||||
|
{
|
||||||
|
// angle in 0-180
|
||||||
|
F32 angle = getAngleBetweenVectors(vecA, vecB);
|
||||||
|
F32 sign = mSign(mDot(norm, mCross(vecA, vecB)));
|
||||||
|
|
||||||
|
// angle in -179-180
|
||||||
|
F32 signed_angle = angle * sign;
|
||||||
|
|
||||||
|
return signed_angle;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void transformBoundingBox(const Box3F &sbox, const MatrixF &mat, const Point3F scale, Box3F &dbox)
|
void transformBoundingBox(const Box3F &sbox, const MatrixF &mat, const Point3F scale, Box3F &dbox)
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,11 @@ namespace MathUtils
|
||||||
///
|
///
|
||||||
F32 getAngleBetweenVectors(VectorF vecA, VectorF vecB);
|
F32 getAngleBetweenVectors(VectorF vecA, VectorF vecB);
|
||||||
|
|
||||||
|
/// Returns the angle between two given vectors, utilizing a normal vector to discertain the angle's sign
|
||||||
|
///
|
||||||
|
/// Angles is in RADIANS
|
||||||
|
///
|
||||||
|
F32 getSignedAngleBetweenVectors(VectorF vecA, VectorF vecB, VectorF norm);
|
||||||
|
|
||||||
/// Simple reflection equation - pass in a vector and a normal to reflect off of
|
/// Simple reflection equation - pass in a vector and a normal to reflect off of
|
||||||
inline Point3F reflect( Point3F &inVec, Point3F &norm )
|
inline Point3F reflect( Point3F &inVec, Point3F &norm )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue