•      Sign In
• Create Account

We're offering banner ads on our site from just \$5!

### #Actualeppo

Posted 26 January 2013 - 04:55 AM

Quaternion.CreateFromAxisAngle(rotationAxis, rotationAngle) calculates the difference in orientation between forward and lookAt, but when slerping you treat is as an absolute orientation.

Quaternion qSlerp = Quaternion.Slerp(qStart, qEnd, (float)gameTime.ElapsedGameTime.Milliseconds / 1000f);

should be:

Quaternion qSlerp = Quaternion.Slerp(qStart, qStart * qEnd, (float)gameTime.ElapsedGameTime.Milliseconds / 1000f);

I don't know the exact implementation of these math functions, but you should check whether CreateFromAxisAngle() requires a normalized vector as input (which rotationAxis = Vector3.Cross(lookAtDirection, forward) likely isn't).

MathUtilities.GetUnsignedAngle() seems to throw out the sign of the angle, but in the code that follows you recalculate it:

Vector3 right = Vector3.Normalize(transformComponent.Transform.Right);

float rightDot = (float)Math.Round()...
if (rightDot > 0){ rotationAngle *= -1; }

So, you should either use GetSignedAngle() (if it exists) or use angle = acos(forwardDot).

### #2eppo

Posted 26 January 2013 - 04:54 AM

Quaternion.CreateFromAxisAngle(rotationAxis, rotationAngle) calculates the difference in orientation between forward and lookAt, but when slerping you threat is as an absolute orientation.

Quaternion qSlerp = Quaternion.Slerp(qStart, qEnd, (float)gameTime.ElapsedGameTime.Milliseconds / 1000f);

should be:

Quaternion qSlerp = Quaternion.Slerp(qStart, qStart * qEnd, (float)gameTime.ElapsedGameTime.Milliseconds / 1000f);

I don't know the exact implementation of these math functions, but you should check whether CreateFromAxisAngle() requires a normalized vector as input (which rotationAxis = Vector3.Cross(lookAtDirection, forward) likely isn't).

MathUtilities.GetUnsignedAngle() seems to throw out the sign of the angle, but in the code that follows you recalculate it:

Vector3 right = Vector3.Normalize(transformComponent.Transform.Right);

float rightDot = (float)Math.Round()...
if (rightDot > 0){ rotationAngle *= -1; }

So, you should either use GetSignedAngle() (if it exists) or use angle = acos(forwardDot).

### #1eppo

Posted 26 January 2013 - 04:53 AM

<p><span style="background-color: rgb(250, 251, 252); color: rgb(40, 40, 40); font-family: helvetica, arial, verdana, tahoma, sans-serif; font-size: 13px; line-height: 20px;">Quaternion.CreateFromAxisAngle(rotationAxis, rotationAngle)</span>&nbsp;calculates the difference in orientation between forward and lookAt, but when slerping you threat is as an absolute orientation.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div style="margin: 0px; padding: 0px; color: rgb(40, 40, 40); font-family: helvetica, arial, verdana, tahoma, sans-serif; font-size: 13px; line-height: 20px; background-color: rgb(250, 251, 252);"><span style="color:#696969;">Quaternion qSlerp = Quaternion.Slerp(qStart, qEnd, (float)gameTime.ElapsedGameTime.Milliseconds / 1000f);</span></div>
<div style="margin: 0px; padding: 0px; color: rgb(40, 40, 40); font-family: helvetica, arial, verdana, tahoma, sans-serif; font-size: 13px; line-height: 20px; background-color: rgb(250, 251, 252);">&nbsp;</div>
<div style="margin: 0px; padding: 0px; color: rgb(40, 40, 40); font-family: helvetica, arial, verdana, tahoma, sans-serif; font-size: 13px; line-height: 20px; background-color: rgb(250, 251, 252);">should be:</div>
<div style="margin: 0px; padding: 0px; color: rgb(40, 40, 40); font-family: helvetica, arial, verdana, tahoma, sans-serif; font-size: 13px; line-height: 20px; background-color: rgb(250, 251, 252);">&nbsp;</div>
<div style="margin: 0px; padding: 0px; color: rgb(40, 40, 40); font-family: helvetica, arial, verdana, tahoma, sans-serif; font-size: 13px; line-height: 20px; background-color: rgb(250, 251, 252);"><span style="color:#696969;">Quaternion qSlerp = Quaternion.Slerp(qStart, qStart * qEnd, (float)gameTime.ElapsedGameTime.Milliseconds / 1000f);</span></div>
<div style="margin: 0px; padding: 0px; color: rgb(40, 40, 40); font-family: helvetica, arial, verdana, tahoma, sans-serif; font-size: 13px; line-height: 20px; background-color: rgb(250, 251, 252);">&nbsp;</div>
<div style="margin: 0px; padding: 0px; color: rgb(40, 40, 40); font-family: helvetica, arial, verdana, tahoma, sans-serif; font-size: 13px; line-height: 20px; background-color: rgb(250, 251, 252%2

PARTNERS