Jump to content
  • Advertisement
Sign in to follow this  
BearishSun

Quaternion rotation curve

This topic is 3084 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

i'm using Unity 3D engine for a certain project. In the project I need to create animation curves on-the-fly.

In Unity, animation curves are represented as keyframes containing (Time, Value, InTangent, OutTangent). Each component of each possible transformation is represented a single curve (for example, rotation is represented using 4 curves, one for each of the four quaternion components (x, y, z, w)). So, in total there are 10 curves(3 position(Vector3), 3 scale(Vector3), 4 rotation(Quaternion))

For example, if i wanted to create animation that moves an object on the x axis by 5 units in 1 time unit I would add a curve for "Position.x" with two keyframes (0, 0, 0, 0), and (1, 5, 0, 0). As you can see, InTangent and OutTangent are set to zero, as I simply want linear interpolation between the two keyframes.

However, when doing rotation, InTangent and OutTangent need to be set to some value, and I don't know how to calculate that value. What I want to know, is what could InTangent and OutTangent variables be, and how to calculate them? All I know, is that they are at 0 when I want linear interpolation.

Unity describes InTangent and OutTangent as:
InTangent - Describes the tangent when approaching this point from the previous point in the curve.
OutTangent - Describes the tangent when leaving this point towards the next point in the curve.

But I don't know how to calculate those tangents when I want rotation.

EDIT:

Just to make it easier to visualize:

I have curve on the left, and I want to get the curve on the right. And I get that curve by properly setting the InTangent and OutTangent values at each of the keyframes. (This is done using Unitys animation editor, that does this automatically).

Share this post


Link to post
Share on other sites
Advertisement
If the first point on your graph is A, then 2nd is B, and the third is C, you should be able to calculate this by:

1) Calculate vector AB and normalize it
2) Calculate vector BC and normalize it
3) Average the vectors and re-normalize to get one of the tangents
4) multiply by -1 to get the other tangent

I think that ought to work (:

Share this post


Link to post
Share on other sites
Good I'm glad

you might try playing around with the length of the normal vectors too if the curve isn't smooth enough.

IE at the end the vectors are normalized so they are a length of 1. If you multiply them by 2 (or other numbers > 1) it should make the curve smoother if you need it to be.

Or if it's too smooth, you can multiply by a number between 0 and 1 too (:

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!