*** empty log message ***

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@240 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
driAn
2006-04-12 18:00:57 +00:00
parent 7fd2ac4dea
commit 482237bdca
22 changed files with 4375 additions and 3994 deletions
+101 -101
View File
@@ -4,8 +4,8 @@
#include "cube.h"
const int FIRSTMD3 = 20;
enum { MDL_LOWER = 0, MDL_UPPER, MDL_HEAD };
enum { MDL_LOWER = 0, MDL_UPPER, MDL_HEAD };
enum { MDL_GUN_IDLE = 0, MDL_GUN_ATTACK, MDL_GUN_RELOAD, MDL_GUN_ATTACK2}; // attack2 is for grenade only
#define MD3_DEFAULT_SCALE 0.08f
@@ -79,7 +79,7 @@ struct md3model
md3tag *tags;
int numframes, numtags;
bool loaded;
vec scale;
vec scale;
void setanim(int anim);
bool link(md3model *link, char *tag);
bool load(char *path);
@@ -106,12 +106,12 @@ md3model::~md3model()
if(links) free(links);
if(tags) delete [] tags;
};
void md3model::setanim(int anim)
{
if(animstate->anim != anim) animstate->lastTime = lastmillis;
animstate->anim = anim;
};
void md3model::setanim(int anim)
{
if(animstate->anim != anim) animstate->lastTime = lastmillis;
animstate->anim = anim;
};
bool md3model::link(md3model *link, char *tag)
{
@@ -182,58 +182,58 @@ bool md3model::load(char *path)
loaded = true;
return true;
};
VAR(animdebug, 0, 0, 1);
VAR(animdebug, 0, 0, 1);
void md3model::render()
{
if(!loaded || meshes.length() <= 0) return;
float t = 0.0f;
int nextfrm;
md3state *a = animstate;
md3state *a = animstate;
if(a && animations.length() > a->anim)
{
md3animinfo *info = &animations[a->anim];
int time = lastmillis - a->lastTime;
float speed = 1000.0f / (float)info->fps;
a->frm = (int) (time / speed);
//printf("no loop %i > %i\n", a->frm, info->start + info->num-1);
if(!info->loop && a->frm >= info->num -1)
{
if(animdebug) printf("no loop %i > %i\n", a->frm, info->start + info->num-1);
a->frm = info->start + info->num-1;
nextfrm = a->frm;
}
else
md3animinfo *info = &animations[a->anim];
int time = lastmillis - a->lastTime;
float speed = 1000.0f / (float)info->fps;
a->frm = (int) (time / speed);
//printf("no loop %i > %i\n", a->frm, info->start + info->num-1);
if(!info->loop && a->frm >= info->num -1)
{
t = (time-a->frm*speed)/speed;
a->frm = info->start+(a->frm % info->num);
//if(a->frm>=info->start+info->num-1)
nextfrm = a->frm + 1;
//if(animdebug) printf("%i >= %i + %i", nextfrm, a->frm, info->num);
if(nextfrm>=info->start+info->num) nextfrm=a->frm;
};
if(animdebug) printf("no loop %i > %i\n", a->frm, info->start + info->num-1);
a->frm = info->start + info->num-1;
nextfrm = a->frm;
}
else
{
t = (time-a->frm*speed)/speed;
a->frm = info->start+(a->frm % info->num);
//if(a->frm>=info->start+info->num-1)
nextfrm = a->frm + 1;
//if(animdebug) printf("%i >= %i + %i", nextfrm, a->frm, info->num);
if(nextfrm>=info->start+info->num) nextfrm=a->frm;
};
//if(a->frm < info->start || a->frm > info->end) // we switched to a new animation, jump to the start
// a->frm = info->start;
//t = (float) (lastmillis - a->lastTime) / (1000.0f / (float) info->fps ); // t has a value from 0.0f to 1.0f - used for interpolation
if(animdebug) printf("lm:%i lt:%i fps:%i\t(%i %i)\n", lastmillis, a->lastTime, info->fps, info->start, info->num);
//t = (float) (lastmillis - a->lastTime) / (1000.0f / (float) info->fps ); // t has a value from 0.0f to 1.0f - used for interpolation
if(animdebug) printf("lm:%i lt:%i fps:%i\t(%i %i)\n", lastmillis, a->lastTime, info->fps, info->start, info->num);
/*if(t >= 1.0f) // jump to the next keyframe
{
a->frm++;
a->lastTime = lastmillis;
//t = 0.0f;
t = t % 1;
//t = 0.0f;
t = t % 1;
//printf("next keyframe\n");
};
if(a->frm >= info->end)
{
{
//printf("end\n");
if(info->loop)
a->frm = info->start;
@@ -245,14 +245,14 @@ void md3model::render()
};*/
}
else
{
if(animdebug) printf("overflow: curframe %i > maxframe %i\n", a->anim, animations.length());
{
if(animdebug) printf("overflow: curframe %i > maxframe %i\n", a->anim, animations.length());
if(!a) a = new md3state();
a->frm = 0;
a->frm = 0;
nextfrm = a->frm + 1;
}
}
if(animdebug) printf("interp. from frame %i to %i, %f percent done\n", a->frm, nextfrm, t*100.0f);
#define interpolate(p1,p2) ((p1) + t * ((p2) - (p1)))
@@ -363,10 +363,10 @@ COMMAND(md3skin, ARG_2STR);
void md3animation(char *first, char *nums, char *loopings, char *fps) /* configurable animations */
{
md3animinfo &a = tmp_animations.add();
a.start = atoi(first);
int n = atoi(nums);
a.start = atoi(first);
int n = atoi(nums);
if(n<=0) n = 1;
//a.end = a.start + n - 1;
//a.end = a.start + n - 1;
a.num = n;
(atoi(loopings) > 0) ? a.loop = true : a.loop = false;
a.fps = atoi(fps);
@@ -383,11 +383,11 @@ void loadweapons()
md3model *mdl = new md3model();
models.add(mdl);
sprintf_sd(mdl_path)("%s/tris_high.md3", basedir);
sprintf_sd(cfg_path)("%s/default.skin", basedir);
sprintf_sd(cfg_path)("%s/default.skin", basedir);
sprintf_sd(modelcfg_path) ("%s/animations.cfg", basedir);
mdl->load(mdl_path);
exec(cfg_path);
tmp_animations.setsize(0);
exec(cfg_path);
tmp_animations.setsize(0);
exec(modelcfg_path);
loopj(tmp_animations.length()) mdl->animations.add(tmp_animations[j]);
}
@@ -397,7 +397,7 @@ void rotatevec(vec &point, vec &rot)
{
point.x=point.z*sin(rot.x)+point.x*cos(rot.x);
point.y=point.y;
point.z=point.z*cos(rot.x)-point.x*sin(rot.x);
point.z=point.z*cos(rot.x)-point.x*sin(rot.x);
point.x=point.x;
point.y=point.y*cos(rot.y)-point.z*sin(rot.y);
@@ -406,17 +406,17 @@ void rotatevec(vec &point, vec &rot)
point.x=point.y*sin(rot.z)+point.x*cos(rot.z);
point.y=point.y*cos(rot.z)-point.x*sin(rot.z);
point.z=point.z;
};
VAR(swayspeeddiv, 1, 125, 1000);
VAR(swaymovediv, 1, 200, 1000);
VAR(swayupspeeddiv, 1, 125, 1000);
VAR(swayupmovediv, 1, 200, 1000);
VAR(x, 0, 0, 1000);
VAR(y, 0, 0, 1000);
VAR(z, 0, 0, 1000);
};
VAR(swayspeeddiv, 1, 125, 1000);
VAR(swaymovediv, 1, 200, 1000);
VAR(swayupspeeddiv, 1, 125, 1000);
VAR(swayupmovediv, 1, 200, 1000);
VAR(x, 0, 0, 1000);
VAR(y, 0, 0, 1000);
VAR(z, 0, 0, 1000);
void rendermd3gun()
{
@@ -434,16 +434,16 @@ void rendermd3gun()
light.x = s->r/ll+of;
light.y = s->g/ll+of;
light.z = s->b/ll+of;
};
};
md3model *weapon = models[firstweapon + player1->gunselect];
if(!weapon->animstate)
{
weapon->animstate = new md3state();
weapon->animstate->lastTime = lastmillis;
};
md3model *weapon = models[firstweapon + player1->gunselect];
if(!weapon->animstate)
{
weapon->animstate = new md3state();
weapon->animstate->lastTime = lastmillis;
};
int rtime = reloadtime(player1->gunselect);
int rtime = reloadtime(player1->gunselect);
if(player1->reloading)
{
@@ -454,50 +454,50 @@ void rendermd3gun()
}
else
{
float kick = 0.0f;
bool throwingnade = player1->gunselect==GUN_GRENADE && player1->thrownademillis;
float kick = 0.0f;
bool throwingnade = player1->gunselect==GUN_GRENADE && player1->thrownademillis;
if(player1->gunselect==player1->lastattackgun)
{
{
int timedifference = throwingnade ? (lastmillis-player1->thrownademillis) : (lastmillis-player1->lastaction);
int percent_done = timedifference*100/attackdelay(player1->gunselect);
if(percent_done > 100) percent_done = 100.0;
// f(x) = -sin(x-1.5)^3
kick = -sin(pow((1.5f/100*percent_done)-1.5f,3));
};
if(kick > 0.01f) throwingnade ? weapon->setanim(MDL_GUN_ATTACK2) : weapon->setanim(MDL_GUN_ATTACK);
else weapon->setanim(MDL_GUN_IDLE);
};
if(kick > 0.01f) throwingnade ? weapon->setanim(MDL_GUN_ATTACK2) : weapon->setanim(MDL_GUN_ATTACK);
else weapon->setanim(MDL_GUN_IDLE);
vdist(dist, unitv, player1->o, worldpos);
vdiv(unitv, dist);
float k_rot = kick_rot(player1->gunselect)*kick;
float k_back = kick_back(player1->gunselect)*kick/10;
vec sway(unitv);
vec sway(unitv);
int swayt = (lastmillis+1)/10 % 100;
float swayspeed = (float) (sin((float)lastmillis/swayspeeddiv))/(swaymovediv/10.0f);
float swayupspeed = (float) (sin((float)lastmillis/swayupspeeddiv-90))/(swayupmovediv/10.0f);
#define g0(x) ((x) < 0.0f ? -(x) : (x))
float plspeed = min(1.0f, sqrt(g0(player1->vel.x*player1->vel.x) + g0(player1->vel.y*player1->vel.y)));
swayspeed *= plspeed/2;
int swayt = (lastmillis+1)/10 % 100;
float swayspeed = (float) (sin((float)lastmillis/swayspeeddiv))/(swaymovediv/10.0f);
float swayupspeed = (float) (sin((float)lastmillis/swayupspeeddiv-90))/(swayupmovediv/10.0f);
#define g0(x) ((x) < 0.0f ? -(x) : (x))
float plspeed = min(1.0f, sqrt(g0(player1->vel.x*player1->vel.x) + g0(player1->vel.y*player1->vel.y)));
swayspeed *= plspeed/2;
swayupspeed *= plspeed/2;
// rotate 90° around z axis
float tmp = sway.x;
sway.x = sway.y;
sway.y = -tmp;
if(swayupspeed<0.0f)swayupspeed = -swayupspeed; // sway a semicirle only
sway.z = 1.0f;
sway.x *= swayspeed;
sway.y *= swayspeed;
sway.z *= swayupspeed;
// rotate 90° around z axis
float tmp = sway.x;
sway.x = sway.y;
sway.y = -tmp;
if(swayupspeed<0.0f)swayupspeed = -swayupspeed; // sway a semicirle only
sway.z = 1.0f;
sway.x *= swayspeed;
sway.y *= swayspeed;
sway.z *= swayupspeed;
weapon->draw( player1->o.x-unitv.x*k_back+sway.x,
player1->o.z-unitv.z*k_back+sway.z,