Jump to content
  • Advertisement
Sign in to follow this  
Ronan085

How do i implement linear interpolation

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

Hey 

 

Does anybody know how to properly implement linear interpolation for skeletal animation i just cant seem to get it to work

Ive been getting some very interesting results when ive tried different ways eg model exploding apart when the animations starts, random translations and rotations happening

If anybody wants to see any of the codes from my attempts at it just ask smile.png

 

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
Advertisement
How are you representing the transformation that brings you from the frame of reference of the parent bone to the frame of reference of this bone? You probably want to use quaternions for the rotation part, and then use slerp or nlerp.

Share this post


Link to post
Share on other sites

The equation for linear interpolation is quite easy.

 

x = x_start + ((x_final - x_start) * time) 

 

 

where time is a number between 0 and 1.

 

However; as Alvaro said, this equation doesn't work well with rotations. For rotations, you should look into quaternions.

 

Here's an article with some information. 

Edited by Squared'D

Share this post


Link to post
Share on other sites

@Álvaro The file format im using is based off collada so the transformations are represented by 4x4 matrixs

 

@Squared'D ya ive been using that equation but the result are not what im expecting, my file file format has specified that all transformation interpolation should be linear

Share this post


Link to post
Share on other sites

@Squared'D ya ive been using that equation but the result are not what im expecting, my file file format has specified that all transformation interpolation should be linear

rotating around something is not linear, since a rotation imply's movement in an arc around a point, rather than a straight line. doing slerp(sperhical linear interpolation) isn't easy with matrixs, quaternions simplify the mathematics(but are a bit hard to understand if you don't know complex numbers(still it can be a bit difficult to comprehend even then imo)) Edited by slicer4ever

Share this post


Link to post
Share on other sites

@Squared'D ya ive been using that equation but the result are not what im expecting, my file file format has specified that all transformation interpolation should be linear

rotating around something is not linear, since a rotation imply's movement in an arc around a point, rather than a straight line. doing slerp(sperhical linear interpolation) isn't easy with matrixs, quaternions simplify the mathematics(but are a bit hard to understand if you don't know complex numbers(still it can be a bit difficult to comprehend even then imo))

 

 

How are you representing the transformation that brings you from the frame of reference of the parent bone to the frame of reference of this bone? You probably want to use quaternions for the rotation part, and then use slerp or nlerp.

 

Ok so where do i get this rotation information if the only transformation information i have is stored in one matrix

Share this post


Link to post
Share on other sites

Ok so where do i get this rotation information if the only transformation information i have is stored in one matrix

The 4x4 matrix of an affine transformation is compose of a 3x3 matrix that represents a linear mapping (in the case of posture data this is a rotation) and a translation vector (a column to the right of the 3x3 matrix or a row below it, depending on whether you are using column vectors or row vectors). The other four components are always "0 0 0 1".

Extract the rotation and the translation separately and convert the rotation to a quaternion (see JTippetts's post above).

Share this post


Link to post
Share on other sites

I have noobish questions if you don't mind me learn something, since this is somehow related.

 

1.

Affine transformation matrix is like "world" matrix used to transform vertices?

For example i want to transform some point with that kind of matrix (dx, row major):

pout->x = pm->m[0][0] * pin->x + pm->m[1][0] * pin->y + pm->m[2][0] * pin->z + pm->m[3][0];
pout->y = pm->m[0][1] * pin->x + pm->m[1][1] * pin->y + pm->m[2][1] * pin->z + pm->m[3][1];
pout->z = pm->m[0][2] * pin->x + pm->m[1][2] * pin->y + pm->m[2][2] * pin->z + pm->m[3][2];

 

2.

Non-affine is like projection (and view?) matrix?

So to transform point with that it is bit different:

FLOAT norm;
norm = 1.0f / (pm->m[0][3] * pin->x + pm->m[1][3] * pin->y + pm->m[2][3] *pin->z + pm->m[3][3]);
pout->x = (pm->m[0][0] * pin->x + pm->m[1][0] * pin->y + pm->m[2][0] * pin->z + pm->m[3][0]) * norm;
pout->y = (pm->m[0][1] * pin->x + pm->m[1][1] * pin->y + pm->m[2][1] * pin->z + pm->m[3][1]) * norm;
pout->z = (pm->m[0][2] * pin->x + pm->m[1][2] * pin->y + pm->m[2][2] * pin->z + pm->m[3][2]) * norm;

 

3. For directions/vectors i can remove adding translation part of matrix?

 

Thank you for your time.

Share this post


Link to post
Share on other sites

Some googling for "matrix to quaternion conversion" turned up http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/ which goes through the math and presents Java and C++ code for building a quaternion from a rotation matrix. Similar googling can be performed for "quaternion slerp" and "quaternion to matrix conversion".

 

really nice article thanks, thankfully XNAMath has a nice function XMQuaternionSlerp() so that will save me a ton of work;

 

Ok so where do i get this rotation information if the only transformation information i have is stored in one matrix

The 4x4 matrix of an affine transformation is compose of a 3x3 matrix that represents a linear mapping (in the case of posture data this is a rotation) and a translation vector (a column to the right of the 3x3 matrix or a row below it, depending on whether you are using column vectors or row vectors). The other four components are always "0 0 0 1".

Extract the rotation and the translation separately and convert the rotation to a quaternion (see JTippetts's post above).

 

thanks i was very clueless about how the different information was sorted in the matrix, any idea where the scaling information is

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!