mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-28 02:53:49 +00:00
Required changes for Inverse Kinematics
Added a * operator compute from to -> adds safeties around shortestArc conjugate -> reverses the xyz of the quaternion IK Solver commit Added: IKChain struct to tsshape commands to tsshapeconstruct to create and setup ikchains ik solvers -> ccd and fabrik, these are in their own file tsIKSolver TODO: there needs to be some tooling added to the shape editor for this
This commit is contained in:
parent
42e8687067
commit
9866908e99
10 changed files with 1048 additions and 1 deletions
|
|
@ -342,3 +342,40 @@ QuatF & QuatF::shortestArc( const VectorF &a, const VectorF &b )
|
|||
return *this;
|
||||
}
|
||||
|
||||
QuatF& QuatF::computeRotationFromTo(const VectorF& from, const VectorF& to)
|
||||
{
|
||||
VectorF f = from;
|
||||
VectorF t = to;
|
||||
|
||||
f.normalizeSafe();
|
||||
t.normalizeSafe();
|
||||
|
||||
if (f.isZero() || t.isZero())
|
||||
{
|
||||
return identity();
|
||||
}
|
||||
|
||||
F32 dot = mClampF(mDot(f, t), -1.0f, 1.0f);
|
||||
|
||||
// Parallel = no rotation.
|
||||
if (dot > 0.9999f)
|
||||
{
|
||||
return identity();
|
||||
}
|
||||
|
||||
// Opposite = pick perpendicular.
|
||||
if (dot < -0.9999f)
|
||||
{
|
||||
VectorF axis;
|
||||
if (mFabs(f.x) < mFabs(f.z))
|
||||
axis.set(0, -f.z, f.y);
|
||||
else
|
||||
axis.set(-f.y, f.x, 0);
|
||||
|
||||
axis.normalizeSafe();
|
||||
return set(axis, M_PI_F); // 180 degrees
|
||||
}
|
||||
|
||||
return shortestArc(f, t);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,10 +70,12 @@ public:
|
|||
QuatF& operator /=( F32 a );
|
||||
|
||||
QuatF operator-( const QuatF &c ) const;
|
||||
QuatF operator*(const QuatF& rhs) const;
|
||||
QuatF operator*( F32 a ) const;
|
||||
|
||||
QuatF& square();
|
||||
QuatF& neg();
|
||||
QuatF& conjugate();
|
||||
F32 dot( const QuatF &q ) const;
|
||||
|
||||
MatrixF* setMatrix( MatrixF * mat ) const;
|
||||
|
|
@ -91,6 +93,7 @@ public:
|
|||
|
||||
// Vectors passed in must be normalized
|
||||
QuatF& shortestArc( const VectorF &normalizedA, const VectorF &normalizedB );
|
||||
QuatF& computeRotationFromTo(const VectorF& from, const VectorF& to);
|
||||
};
|
||||
|
||||
// a couple simple utility methods
|
||||
|
|
@ -208,6 +211,18 @@ inline QuatF QuatF::operator -( const QuatF &c ) const
|
|||
w - c.w );
|
||||
}
|
||||
|
||||
inline QuatF QuatF::operator*(const QuatF& rhs) const
|
||||
{
|
||||
QuatF out;
|
||||
|
||||
out.w = w * rhs.w - x * rhs.x - y * rhs.y - z * rhs.z;
|
||||
out.x = w * rhs.x + x * rhs.w + y * rhs.z - z * rhs.y;
|
||||
out.y = w * rhs.y - x * rhs.z + y * rhs.w + z * rhs.x;
|
||||
out.z = w * rhs.z + x * rhs.y - y * rhs.x + z * rhs.w;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
inline QuatF QuatF::operator *( F32 a ) const
|
||||
{
|
||||
return QuatF( x * a,
|
||||
|
|
@ -225,6 +240,14 @@ inline QuatF& QuatF::neg()
|
|||
return *this;
|
||||
}
|
||||
|
||||
inline QuatF& QuatF::conjugate()
|
||||
{
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline F32 QuatF::dot( const QuatF &q ) const
|
||||
{
|
||||
return mClampF(w*q.w + x*q.x + y*q.y + z*q.z, -1.0f, 1.0f);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue