Jump to content
  • Advertisement
Sign in to follow this  
Silex

interpolation between poses (transformation matrices)

This topic is 4683 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

I need to visually predict an objects path along a set of nodes, each node being associated with a particular position and orientation (pose). I take it position and rotation must be interpolated seperately, and that a linear interpolation from euler angles will not produce optimal results for the rotation, although linear will probably be sufficient for position. Is quaternion interpolation the way to go? How about for position? Linear? Any good references? I found the following pseudo-code on how to do quaternion interpolation:
interpolate_rotation(mat[n],t)

  t_int = int(t);

  t_fract = t - t_int;

  

  q_0 = mat2quat(mat[t_int-1]);

  q_1 = mat2quat(mat[t_int]);

  q_2 = mat2quat(mat[t_int+1]);

  q_3 = mat2quat(mat[t_int+2]);

  

  i_1 = inner_quad_point(q_0, q_1, q_2);

  i_2 = inner_quad_point(q_1, q_2, q_3);

  

  q_i = slerp(slerp(q_1, q_2, t_fract),

              slerp(i_1, i_2, t_fract),

              2*t_fract*(1-t_fract);

  

  return mat2quat(q_i); 


Which takes 4 rotation matrices as arguments. What do you do if you only have 2? Or for interpolating between the before-last and last nodes? mat[i+2] would go beyond that. edit: upon further reading it seems that cubic interpolation may be overkill for what I'm trying to accomplish, and that something similar to what i have below may be all i need?
m4_transpose(    mt, ms );                /* Inverse             */
    m4_mult(         ms, mt, mb );            /* Rotation matrix     */
    m4_to_axisangle( ms, axis, angle );       /* Rotation axis/angle */
    for ( t = 0; t < 1.0; t += 0.05 )
      {
      m4_from_axisangle( mi, axis, angle * t ); /* Final interpolation */
      ... whatever ...
      }

[Edited by - Silex on July 29, 2005 12:30:47 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Silex
[...]
Is quaternion interpolation the way to go? How about for position? Linear? Any good references?

I found the following pseudo-code on how to do quaternion interpolation:

*** Source Snippet Removed ***

Which takes 4 rotation matrices as arguments.


Yes, quat interpolation is designed exactly for that. Of cource, if you're going to represent your transform data as matrices all the time, it will be inefficient. Better to explicitly keep quaternion and vector, and transform to a matrix in the final stage only.

Al for linear/cubic... Performing linear interpolation via splines will do you no good. It completely looses information about derivatives. So the final spline will not have continous derivative. In other words, will look odd and artificial, with sudden changes of motion direction.

So it's cubic, then. The code you presented performs just that. The "inner_quad_point" results are control points, that can be precomputed, so it's not a big deal. As well as angles for slerp (in most cases).

Translation should also be cubic. Same reasons.

Quote:
Original post by Silex
What do you do if you only have 2? Or for interpolating between the before-last and last nodes? mat[i+2] would go beyond that.


Two options:
1 - use last quaternion as post-last too, and first as pre-first (like: q[0],q[0],q[1],q[2] and q[n-3],q[n-2],q[n-1],q[n-1])
2 - if the path is looping, use last as pre-first, and first as post-last (like: q[n-1],q[0],q[1],q[2] and q[n-3],q[n-2],q[n-1],q[0]).


Quote:
Original post by Silex
edit: upon further reading it seems that cubic interpolation may be overkill for what I'm trying to accomplish, and that something similar to what i have below may be all i need?

*** Source Snippet Removed ***


Heh... the rule of thumb says: there are barely few situation when you can cheat the mother nature. In all the other ones, you will get exactly the same that you were trying to escape from, only harder and more complicated.

In other words: interpolating matrices is just walking aroud the interpolation of quaternions. Compare the cost:
- matrix inversion, to-axisangle (as a precalculation) and from-axisangle (as interpolation).
- on the other hand: angle between quats (as a precalculation) and slerp (as interpolation).
- or for cubic: 2 control points, 2 angles between quats (as a precalculation) and 3 slerps, partially precomputed (as interpolation) - but the efect is much, much better.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!