weapon animation switching fix

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@3351 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2008-10-30 23:38:53 +00:00
parent 90adb6dd6e
commit e47978c3e1
2 changed files with 14 additions and 16 deletions
+13 -9
View File
@@ -11,15 +11,14 @@ struct weaponmove
float k_rot, kick;
vec pos;
int anim;
int anim, basetime;
weaponmove() : k_rot(0), kick(0), anim(0) { pos.x = pos.y = pos.z = 0.0f; }
weaponmove() : k_rot(0), kick(0), anim(0), basetime(0) { pos.x = pos.y = pos.z = 0.0f; }
void calcmove(vec base, int basetime)
void calcmove(vec aimdir, int lastaction)
{
kick = k_rot = 0.0f;
pos = player1->o;
anim = ANIM_GUN_IDLE;
if(!nosway)
{
@@ -40,20 +39,25 @@ struct weaponmove
if(player1->weaponchanging)
{
anim = ANIM_GUN_RELOAD;
basetime = player1->weaponchanging;
float progress = max(0.0f, min(1.0f, (lastmillis - player1->weaponchanging)/(float) weapon::weaponchangetime));
k_rot = -(sinf((float)(progress*2*90.0f)*PI/180.0f)*90);
}
else if(player1->weaponsel->reloading)
{
anim = ANIM_GUN_RELOAD;
basetime = player1->weaponsel->reloading;
float progress = max(0.0f, min(1.0f, (lastmillis - player1->weaponsel->reloading)/(float)player1->weaponsel->info.reloadtime));
k_rot = -(sinf((float)(progress*2*90.0f)*PI/180.0f)*90);
}
else
{
int timediff = lastmillis-basetime,
anim = ANIM_GUN_IDLE;
basetime = lastaction;
int timediff = lastmillis-lastaction,
animtime = min(player1->weaponsel->gunwait, (int)player1->weaponsel->info.attackdelay);
vec sway = base;
vec sway = aimdir;
float progress = 0.0f;
float k_back = 0.0f;
@@ -96,9 +100,9 @@ struct weaponmove
if(player1->crouching) sway.mul(0.75f);
}
pos.x -= base.x*k_back+sway.x;
pos.y -= base.y*k_back+sway.y;
pos.z -= base.z*k_back+sway.z;
pos.x -= aimdir.x*k_back+sway.x;
pos.y -= aimdir.y*k_back+sway.y;
pos.z -= aimdir.z*k_back+sway.z;
}
}
};
+1 -7
View File
@@ -623,14 +623,8 @@ void weapon::renderhudmodel(int lastaction, int index)
weaponmove wm;
if(!intermission) wm.calcmove(unitv, lastaction);
s_sprintfd(path)("weapons/%s", info.modelname);
static int lastanim[2], lastswitch[2];
bool emit = (wm.anim&ANIM_INDEX)==ANIM_GUN_SHOOT && (lastmillis - lastaction) < flashtime();
if(lastanim[index]!=(wm.anim|(type<<24)))
{
lastanim[index] = wm.anim|(type<<24);
lastswitch[index] = lastmillis;
}
rendermodel(path, wm.anim|ANIM_DYNALLOC|(index ? ANIM_MIRROR : 0)|(emit ? ANIM_PARTICLE : 0), 0, -1, wm.pos, player1->yaw+90, player1->pitch+wm.k_rot, 40.0f, lastswitch[index], NULL, NULL, 1.28f);
rendermodel(path, wm.anim|ANIM_DYNALLOC|(index ? ANIM_MIRROR : 0)|(emit ? ANIM_PARTICLE : 0), 0, -1, wm.pos, player1->yaw+90, player1->pitch+wm.k_rot, 40.0f, wm.basetime, NULL, NULL, 1.28f);
}
void weapon::updatetimers()