![]() |
![]() |



Author: renos_h
Date Submitted: 2003-11-12 13:07:44
Downloads: screenshots.zip
//Initializations of the motion timing
int cg_DrawFrame(int time)
{
// remember the time
cg.frametime = time - cg.time;
cg.time = time;
cg.motion_time += cg.frametime;
........
}
//Calling of the cg_draw_player()
void cg_Draw3D(void)
{
cg_draw_player();
....
}
//figuring out the motions based on action.
//if action is not the same as the motion then the
//motion should begin from it's first frame by reseting
//the cg.motion_time variable
void cg_draw_player(void)
{
int v_first, v_last;
float v_framerate;
rbool v_restart_motion;
v_restart_motion = rfalse;
if (cg.player.action == 2)
{
v_first = 252;
v_last = 313;
v_framerate = 30;
if (cg.player.motion == 1)
v_restart_motion = rtrue;
cg.player.motion = 2;
}
else if (cg.player.action == 1)
{
v_first = 1;
v_last = 251;
v_framerate = 30;
if (cg.player.motion == 2)
v_restart_motion = rtrue;
cg.player.motion = 1;
}
cg_draw_character(&cg.player, v_framerate, v_first, v_last, v_restart_motion);
}
//the drawing function
void cg_draw_character(entity_t_t* ent, float framerate, int first, int last, rbool restart_motion)
{
iteminfo_t character;
float frame;
com_zeromem(&character, sizeof(character));
vec3_Copy(ent->axis[0], character.axis[0]);
vec3_Copy(ent->axis[1], character.axis[1]);
vec3_Copy(ent->axis[2], character.axis[2]);
vec3_Copy(ent->origin, character.origin);
//item.flags = ITEMFLAG_CASTSHADOW;
character.type = ITEMTYPE_MODEL;
character.model = ent->modelindex;
frame = cg.motion_time * 0.001f * framerate;
if(restart_motion)
cg.motion_time = 0;
ent->from = (int) frame;
ent->to = (int) frame + 1;
ent->lerp = frame - ent->from;
ent->from = (first + ent->from) % (last-first);
ent->to = (first + ent->to) % (last-first);
character.from = ent->from + first;
character.to = ent->to + first;
character.lerp = ent->lerp + first;
ent->from = character.from;
ent->to = character.to;
ent->lerp = character.lerp;
cipher_r_AddItemToScene(&character);
}
I had to make these functions in order to have full control of a character's motions.
The problem I basically had was that my character's motion were based on a timing that was sequential.
When I wanted the loiter motion to stop and start the walking motion or vice versa, the new motion
wasn't beginning from it's first frame that I 've assigned to.
For examlpe, my character has 2 motions in its framecount which is 313 frames. From 1 to 251 it's the loiter/idle
motion and from 252 to 313 it's the walking motion. When my character was moving, the walking motion is applied
and when it's not moving the loiter motion is applied. The problem was that when my character stopped moving and
the loiter motion was applied, the specific motion was not always beginning from its first frame but from another
frame instead.This din't make my character look natural.
This was happenning because when I was trying to figure out the current frame of my model I used the cg.time:
frame = cg.time * 0.001f * framerate;
cg.time is a sequential timing that cipher gives. In order to make my character's motion starting from it's first
frame I used another time variable which is based on cg.time BUT it's reset to zero when a new motion is applied
so that the new motion is beginning from its first frame. Basically to make sure that the current frame is the
first frame.
frame = cg.motion_time * 0.001f * framerate;
Now my character's motions are based on an independable timing instead of a sequential timing.
You can also see http://www.cipherengine.com/discuss/viewthread.php?t=557 for a more detailed
explanation about cg.time by rikh
rikh, correct if I mentioned anything wrong. :)
I just had to post this, it was bugging me for days.
[Recent Contributions] [Recent Source Code]
User Contributed Comments
c:\TestDLL\TestDLL\TestDLL.cpp(775): error C2664: 'cg_draw_character' : cannot convert parameter 1 from 'entity_t *__w64 ' to 'entity_t_t *'
typedef struct entity_t_s
{
vec3_t origin;
vec3_t velocity;
vec3_t axis[3];
vec3_t size;
int modelindex;
ushort_t event;
ushort_t event_seq; // incremented each time a new event is set
int event_data; // any data an event needs to tag on
int from; // the frame we are moving away from
int to; // the frame we are heading towwards
float lerp; // 0-1. 0=from, 1=to, 0.5=midway between from and to
int action;
int motion;
} entity_t_t;
cg_draw_character(&cg.player, v_framerate, v_first, v_last, v_restart_motion);