• Advertisement
Sign in to follow this  

own animation controller

This topic is 4396 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 attempting to write my own animation controller, instead of using D3DX stuff. I had some bad experiences with it before (executed callbacks almost at random sometimes and the play-flags pingpong, once etc didn't seems to work). Anyway, i'm kinda stuck with the interpolation of the transformation matrices.
void Animation::Interpolate(float time)
{
	D3DXQUATERNION	rotResult;
	D3DXVECTOR3		transResult(0, 0, 0);
	D3DXVECTOR3		scaleResult(0, 0, 0);

	D3DXQuaternionIdentity(&rotResult);

	for(int i = 0; i < rotKeys.size(); i++)
	{
		D3DXKEY_QUATERNION	key = rotKeys;
		if(key.Time > time)
		{
			D3DXKEY_QUATERNION	begin = rotKeys[i - 1];
			D3DXKEY_QUATERNION	end = key;
			float				timeLerp = (time - begin.Time) / (end.Time - begin.Time);

			D3DXQuaternionSlerp(&rotResult, &begin.Value, &end.Value, timeLerp);
			break;
		}
	}

	for(int i = 0; i < transKeys.size(); i++)
	{
		D3DXKEY_VECTOR3	key = transKeys;
		if(key.Time > time)
		{
			D3DXKEY_VECTOR3	begin = transKeys[i - 1];
			D3DXKEY_VECTOR3	end = key;
			float			timeLerp = (time - begin.Time) / (end.Time - begin.Time);

			D3DXVec3Lerp(&transResult, &begin.Value, &end.Value, timeLerp);
			break;
		}
	}

	for(int i = 0; i < scaleKeys.size(); i++)
	{
		D3DXKEY_VECTOR3	key = scaleKeys;
		if(key.Time > time)
		{
			D3DXKEY_VECTOR3	begin = scaleKeys[i - 1];
			D3DXKEY_VECTOR3	end = key;
			float			timeLerp = (time - begin.Time) / (end.Time - begin.Time);

			D3DXVec3Lerp(&scaleResult, &begin.Value, &end.Value, timeLerp);
			break;
		}
	}

	D3DXMATRIX	T, S, R, L;
	D3DXMatrixTranslation(&T, transResult.x, transResult.y, transResult.z);
	D3DXMatrixScaling(&S, scaleResult.x, scaleResult.y, scaleResult.z);
	D3DXMatrixRotationQuaternion(&R, &rotResult);

	L = R * S * T;

	if(pTransformPtr)
		*pTransformPtr = L;
}


The model seems to be moving and all, but all it's bones seem to have lost their original places and are scattered on the ground.

Share this post


Link to post
Share on other sites
Advertisement
Maybe it's a GRU in disguise? Zorkies will hopefully get that one.

I don't understand the problem exactly. You say the model is moving, but the bones are scattered on the ground. Do you mean the model translates (pile of bones move around) but the heirarchy is not kept? Have they lost their original places completely (i.e. left arm is 10 feet in front of the right arm lying on the ground?) or did they just lose their height? Can you give a screen shot?

What happens when i=0, and you grab begin = rotKeys[i-1]? How do you handle time passed in beyond the last key frame (don't think it matters...seems like it would just stop moving).

I didn't see anything other than that wrong in the rotation portion, so it is likely in your heirarchy code. Can you post how you transform each bone?

Share this post


Link to post
Share on other sites
They seem to still have some coherecy as it almost looks like the model is laying down.

Image

I doubt it's the heirarchy, because i've tried using the ID3DXAnimationController and it animates the mesh like it should.

Share this post


Link to post
Share on other sites
This isn't right:

L = R * S * T;

If L is to become the TransformationMatrix for that bone, you have lost its initial/previous orientation. You need to add the new interpolations to it (and it should be SRT), like:

L *= S*R*T;

Share this post


Link to post
Share on other sites
Hmm.. I tried changing to that formula, but it just turned the mesh into soup. I also tried re-arranging without multiplying it with the previous transform.

By the way, there is a keyframe called a matrix key in the x animation format. What is it used for anyway? All i'm using now is the rotation, scaling and translation keys.

I'm starting to wonder if the animation data is correct. Maybe i'm doing something wrong when i read the data from the .X file.

Share this post


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

  • Advertisement