Jump to content

  • Log In with Google      Sign In   
  • Create Account


Nick Joseph

Member Since 05 Jan 2012
Offline Last Active Mar 15 2013 09:05 AM

Posts I've Made

In Topic: Rotation Animation - Slerping the Kool-Aid Part 2

15 February 2013 - 09:27 AM

Not too sure why the above doesn't work as expected but I'm assuming it has to do my assumptions involving quaternions.  I had assumed multiplying quaternions was the same thing as multiplying rotation matrices but apparently not.  Instead of using the Quaternion's CreateFromAxisAngle I used the Matrix's and it resolved the issue...

 

Quaternion qStart = Quaternion.CreateFromRotationMatrix(transformComponent.Transform);

Quaternion qEnd =
    Quaternion.CreateFromRotationMatrix(
        transformComponent.Transform *
        Matrix.CreateFromAxisAngle(
            rotationAxis,
            rotationAngle));

Quaternion qSlerp = Quaternion.Slerp(
    qStart,
    qEnd,
    _slerpAmount);

Matrix rotation = Matrix.CreateFromQuaternion(qSlerp);

 

...thanks.


In Topic: Slerping the Kool Aid - Help!

26 January 2013 - 11:56 AM

I fixed the "slow down" by keeping track of the slerp amount in a private variable and incrementing it...

 

 

_slerpAmount += (float)gameTime.ElapsedGameTime.Milliseconds / 3000f;
 
                    Quaternion qStart = Quaternion.CreateFromRotationMatrix(transformComponent.Transform);
 
                    Quaternion qEnd = Quaternion.CreateFromAxisAngle(rotationAxis, rotationAngle);
 
                    Quaternion qSlerp = Quaternion.Slerp(
                        qStart,
                        qStart * qEnd,
                        _slerpAmount);

In Topic: Slerping the Kool Aid - Help!

26 January 2013 - 11:14 AM

I don't even know what to say, every point you made was valid.  Thank you so much!  To anyone interested here's the updated code (though it's not perfect, the rotation slows down as the actor gets closer to his desired rotation on account of the SLERP calculations so that'll be the next thing I look into)...

 

 

TransformComponent transformComponent = _actor.GetComponent<TransformComponent>();
 
            Vector3 position = transformComponent.Transform.Translation;
 
            Vector3 currentPatrolPoint = _patrolPoints.ElementAt(_currentPatrolPoint);
 
            Vector3 difference = (currentPatrolPoint - position);
 
            if (_hasFinishedRotating == false)
            {
                Vector3 lookAtDirection = Vector3.Normalize(difference);
                
                Vector3 forward = Vector3.Normalize(transformComponent.Transform.Forward);
 
                float forwardDot = (float)Math.Round(
                    Vector3.Dot(
                        forward,
                        lookAtDirection),
                    DOT_PRECISION);
 
                if (forwardDot != 1)
                {
                    Vector3 rotationAxis = Vector3.Normalize(
                        Vector3.Cross(
                            lookAtDirection, 
                            forward));
 
                    float rotationAngle = MathUtilities.GetUnsignedAngle(
                        forward,
                        lookAtDirection);
 
                    Vector3 right = Vector3.Normalize(transformComponent.Transform.Right);
 
                    float rightDot = (float)Math.Round(
                        Vector3.Dot(
                            right,
                            lookAtDirection),
                        DOT_PRECISION);
 
                    if (rightDot > 0)
                    {
                        rotationAngle *= -1;
                    }
 
                    float slerpAmount = (float)gameTime.ElapsedGameTime.Milliseconds / 1000f;
 
                    if (forwardDot > .98f)
                    {
                        slerpAmount = 1.0f;
                    }
 
                    Quaternion qStart = Quaternion.CreateFromRotationMatrix(transformComponent.Transform);
 
                    Quaternion qEnd = Quaternion.CreateFromAxisAngle(rotationAxis, rotationAngle);
 
                    Quaternion qSlerp = Quaternion.Slerp(
                        qStart,
                        qStart * qEnd,
                        slerpAmount);
 
                    Matrix rotation = Matrix.CreateFromQuaternion(qSlerp);
 
                    rotation.Translation = position;
 
                    PhysicsComponent physicsComponent = _actor.GetComponent<PhysicsComponent>();
 
                    physicsComponent.KinematicMove(rotation);
                }
                else
                {
                    _hasFinishedRotating = true;
                }
            }

PARTNERS