How do i implement linear interpolation

Started by
10 comments, last by cr88192 10 years, 11 months ago

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.

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.

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.

Learn all about my current projects and watch some of the game development videos that I've made.

Squared Programming Home

New Personal Journal

@Á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

@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))
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

@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

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".

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).

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.

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

This topic is closed to new replies.

Advertisement