///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////
MATERIAL* anim_copy_mat =
{
effect = "anim_copy_mat.fx";
flags = AUTORELOAD;
}
void ent_anim_copy(ENTITY* eTarget, ENTITY* eSource)
{
int i,numBones,hparent;
ANGLE angle,angle2,angle3,eSourceOldPan;
numBones = ent_bones(eSource);
ent_bonereset_all(eTarget);
vec_set(&eSourceOldPan,&(eSource->pan));
vec_set(&(eSource->pan),nullvector); // ang_for_bone returns global angles
for(i = 0; i < numBones; i++)
{
ang_for_bone(&angle,eSource,i+1); // use bone handles/ indices instead of names
hparent = ent_boneparent(eSource,NULL,i+1);
if(hparent > 0)
{
ang_for_bone(&angle2,eSource,hparent); // eTarget's bone is already rotated by parent bone's rotation => undo it!
ang_diff(&angle3,nullvector,&angle2); // best way to do this? I doubt it.
ang_add(&angle,&angle3);
}
ent_bonerotate(eTarget,i+1,&angle);
}
vec_set(&(eSource->pan),&eSourceOldPan);
}
void main()
{
fps_max = 60;
video_mode = 10;
d3d_antialias = 9;
level_load(NULL);
me = ent_create("robot.mdl",vector(450,120,0),NULL);
my.material = anim_copy_mat;
you = ent_create("robot.mdl",vector(450,-120,0),NULL);
your.material = anim_copy_mat;
while(1)
{
my.pan += time_step;
my.skill20 += 10*time_step;
my.skill20 %= 360;
my.skill21 = sinv(my.skill20)*50+50;
ent_animate(me,"bjump",my.skill20,0);
my.skill22 += 30*time_step;
my.skill22 %= 360;
my.skill23 = sinv(my.skill22)*50;
ent_bonerotate(my,"Bone6",vector(0,my.skill23,0));
ent_bonerotate(my,"Bone8",vector(0,-my.skill23,0));
ent_bonerotate(my,"Bone1",vector(my.skill20,0,0));
your.pan = my.pan;
ent_anim_copy(you,me);
time_factor = 1-0.9*key_ctrl;
wait(1);
}
}