HomeNewsFeaturesLicensingDownloadsScreenshotsFAQRoadmap Contact Us
Search:
9 Online

Community

Discussion Topics Recent Postings User Contributions General Articles Example Documentation Credits

Licensed Developer

Programmer's Manual Artists Manual Tutorials and Articles

Programming: Game Code

Game Code Overview Server Side Game Code Client Side Game Code

Programming: System

Alphabetical Function List Renderer File System Collision & Ray Casting Low Level Audio Game Audio The Console Console Variable List Multiplayer Localisation Maths Library Memory Manager Model File Formats Texture Formats

Art: Overviews

Specifications Shaders Particle Systems Lens Flares Cipher console Cipher file types Tutorials Reference

Art: Tools

Shader Designer Particle Designer 3dsmax tools Model Conversion Font Generator

Cipher Engine
Game Development Search Engine
GameDev.net
You are not signed in - [sign in] [register]

Applying/Restarting Character's Motions

Overview

Author: renos_h
Date Submitted: 2003-11-12 13:07:44
Downloads: screenshots.zip

Source Code

//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);
}


Screenshot

Description

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

Charles 22nd December, 2003 10:32
Hi there,

Could anyone help me with a (probably) simple C-question? I'm a starting C-programmer. I've copied the above code from renos_h into my project, and tried to create all the right type definitions.

However I'm getting a compile error:
c:\TestDLL\TestDLL\TestDLL.cpp(775): error C2664: 'cg_draw_character' : cannot convert parameter 1 from 'entity_t *__w64 ' to 'entity_t_t *'


The header of function 'cg_draw_character' reads "entity_t_t* ent". I defined that type as follows:
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;


...which is exactly the same as entity_s, which was already part of the Cipher code.

Thanks.


rikh 22nd December, 2003 12:20
Looks like you are passing an entity_t pointer to the function that is expecting an entity_t_t. In the code that calls the function, check the type of the parameter you are passing along.


Charles 22nd December, 2003 13:06
Yes, the parameter I'm passing comes from the code above:

cg_draw_character(&cg.player, v_framerate, v_first, v_last, v_restart_motion);


The 'cg.player' variable is passed, which uses an entity_t pointer. Did renos_h replace the entity_t definition completely by entity_t_t? I don't understand how to write it...
Edited 22nd December, 2003 13:13


rikh 22nd December, 2003 14:44
It looks that way. Renos_h?




Register and Sign In to discuss this article