Hello!
Mabye this is not the right place for this question....
Suppose we have a keyframe struct
typedef struct _kf
{
DWORD Time;
D3DMATRIX matTransformation;
} sKeyFrame;
Now suppose i've an array of this struct, defined in this mode (i remember that the D3DXMATRIX constructor takes also a float array...)
sKeyFrame Keyframes[4] =
{
// Keyframe 1, 0ms
{ 0, 1.000000f, 0.000000f, 0.000000f, 0.000000f,
0.000000f, 1.000000f, 0.000000f, 0.000000f,
0.000000f, 0.000000f, 1.000000f, 0.000000f,
0.000000f, 0.000000f, 0.000000f, 1.000000f },
// Keyframe 2, 40ms
{ 400, 0.000796f, 1.000000f, 0.000000f, 0.000000f,
-1.000000f, 0.000796f, 0.000000f, 0.000000f,
0.000000f, 0.000000f, 1.000000f, 0.000000f,
50.000000f, 0.000000f, 0.000000f, 1.000000f },
// Keyframe 3, 80ms
{ 800, -0.999999f, 0.001593f, 0.000000f, 0.000000f,
-0.001593f, -0.999999f, 0.000000f, 0.000000f,
0.000000f, 0.000000f, 1.000000f, 0.000000f,
25.000000f, 25.000000f, 0.000000f, 1.000000f },
// Keyframe 4, 120ms
{ 1200, 1.000000f, 0.000000f, 0.000000f, 0.000000f,
0.000000f, 1.000000f, 0.000000f, 0.000000f,
0.000000f, 0.000000f, 1.000000f, 0.000000f,
0.000000f, 0.000000f, 0.000000f, 1.000000f }
};
I've read by the jim adam's book about animation in DirectX that for animate the mesh with these keyframes in cyclical mode, we must do...
static DWORD StartTime = timeGetTime();
DWORD Time = timeGetTime() - StartTime;
DWORD KeyFrame = 0;
for (int i = 0; i < 4; i++)
{
if ( Time >= Keyframes.Time )
KeyFrame = i;
}
DWORD Keyframe2 = (KeyFrame==3) ? KeyFrame : KeyFrame + 1;
DWORD TimeDiff = Keyframes[Keyframe2].Time -
Keyframes[KeyFrame].Time;
if(!TimeDiff)
TimeDiff=1;
float Scalar = (float)(Time - Keyframes[KeyFrame].Time) / (float)TimeDiff;
D3DXMATRIX matInt = D3DXMATRIX(Keyframes[Keyframe2].matTransformation) -
D3DXMATRIX(Keyframes[KeyFrame].matTransformation);
matInt *= Scalar;
matInt += D3DXMATRIX(Keyframes[KeyFrame].matTransformation);
Now there are some things that i've not understood (also i've it's needed the past??? :D)
Why DWORD Keyframe2 = (KeyFrame==3) ? KeyFrame : KeyFrame + 1? I think that i should set KeyFrame2 to 0, to restart animation....
What is the scalar value?
Why i have to substract the two matrices to have the matInt? Why i've to mul matrix for the scalar value? why i've also to add matrix with the matTransformation of first keyframe?
And in all, when the animation it's complete, it does not continue, it stops..
Thank you!