• 15
• 15
• 11
• 9
• 10

# Animation Sequences

This topic is 4739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey I'm writing a 3D third person game. What I need to do is determine, from my current animation, and next animation, what intermediate animation to play to get a smooth transition. I'm using OGRE, so it will handle the interpolation. But I'm still gonna have like, RUN_FORWARD, RUN_FORWARD_STOP, and stuff like that. I wrote a small program to see if it works. Should I do it this way, or is there a better way altogether. Here are just a few animations to test, this should compile in any C/C++ compiler.
#include "stdio.h"

typedef enum
{
RUN_FORWARD,
RUN_BACKWARD,
JUMP_FORWARD,
JUMP_BACKWARD,
NUM_BASIC_ANIMS

}BASIC_ANIMS;

typedef enum
{
ANIM_CONTINUE,
ANIM_VOID,
RUN_FORWARD_RUN_BACKWARD_START,
RUN_BACKWARD_RUN_FORARD_START,
RUN_FORWARD_START,
RUN_FORWARD_STOP,
RUN_BACKWARD_START,
RUN_BACKWARD_STOP,
RUN_FORWARD_JUMP_START,
RUN_BACKWARD_JUMP_START,
NUM_SEQEUNCE_ANIMS

}SEQUENCE_ANIMS;

char* animNamesB[NUM_BASIC_ANIMS] = {"Run Forward",
"Run Backward",
"Jump Forward",
"Jump Backward"
};

char* animNamesS[NUM_SEQEUNCE_ANIMS] = {"Continue current anim",
"Run no anim",
"Run Forward Backward Start",
"Run Backward Forward Start",
"Run Forward Start",
"Run Forward Stop",
"Run Backward Start",
"Run Backward Stop",
"Run Forward Jump Start",
"Run Backward Jump Start"
};

int main()
{

int currentAnim = RUN_FORWARD;
int nextAnim = RUN_BACKWARD;

int anims[NUM_BASIC_ANIMS][NUM_BASIC_ANIMS] = {
/* RUN_FORWARD  */			{ANIM_CONTINUE, RUN_FORWARD_RUN_BACKWARD_START, RUN_FORWARD_JUMP_START, ANIM_VOID},
/* RUN_BACKWARD */			{RUN_BACKWARD_RUN_FORARD_START, ANIM_CONTINUE, ANIM_VOID, RUN_BACKWARD_JUMP_START},
/* JUMP FORWARD */			{ANIM_VOID, ANIM_VOID, ANIM_VOID, ANIM_VOID},
/* JUMP BACKWARD */			{ANIM_VOID, ANIM_VOID, ANIM_VOID, ANIM_VOID}
};

int anim = anims[currentAnim][nextAnim];

printf("\nCurrent Anim = %s\n", animNamesB[currentAnim]);
printf("Next Anim = %s\n", animNamesB[nextAnim]);
printf("Anim needed = %s\n", animNamesS[anim]);

currentAnim = nextAnim;
nextAnim = JUMP_BACKWARD;

anim = anims[currentAnim][nextAnim];

printf("\nCurrent Anim = %s\n", animNamesB[currentAnim]);
printf("Next Anim = %s\n", animNamesB[nextAnim]);
printf("Anim needed = %s\n", animNamesS[anim]);

return 0;
}


##### Share on other sites
I'm not sure what do you want to do, your code does not show anything ... do you want to smooth the the animation by interpoling the frames ? Well it can be done most of the time, but if the frames are too different it can look strange. I have no knowledge what can Ogre do, but I was interpolating few 3d animations myself .... you can interpolate the skeleton model (if model has it), or you can interpolate model vertices (if you interpolate skeleton it looks better)

The basic concept is: calculate current position of bone / vertex. It would go like this:
time_delta = position between previous and next frame
value_frame1 = value from previous frame
value_frame2 = value from next frame

value_frame2 - value_frame1 = value difference

formulae is:
value_result = value_frame1 + ( value_frame2 - value_frame1 ) * time_delta

Lets try an example in bone animation. If you are somewhere between frame 4 and 5 for example in time point 4.2, and bone rotation in frame 4 is of values (100, 120, 0) and in frame 5 values are (80, 120, 10 ) then calculations would be:
time_delta = (float) frame_time - (int) frame_time = 4.2 - 4.0 = 0.2
r1 = 100 + ( 80 - 100 ) * 0.2 = 96
r2 = 120 + ( 120 - 120 ) * 0.2 = 120
r3 = 0 + ( 10 - 0 ) * 0.2 = 2

so the result is that bone rotation in frame time 4.2 is ( 96, 120, 2 ) which is right somewhere between the frames 4 and 5

The same applies on the vertex animation.