2001-10-23 17:20:56 +00:00
|
|
|
/*
|
|
|
|
gl_mod_sprite.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-01-15 15:31:36 +00:00
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2001-12-21 21:52:03 +00:00
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.h"
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
#include "QF/console.h"
|
2001-12-21 21:52:03 +00:00
|
|
|
#include "QF/model.h"
|
2001-10-23 17:20:56 +00:00
|
|
|
#include "QF/render.h"
|
|
|
|
|
2001-12-21 21:52:03 +00:00
|
|
|
#include "r_shared.h"
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
static mspriteframe_t *
|
|
|
|
R_GetSpriteFrame (entity_t *currententity)
|
|
|
|
{
|
|
|
|
float fullinterval, targettime, time;
|
|
|
|
float *pintervals;
|
|
|
|
int frame, numframes, i;
|
|
|
|
msprite_t *psprite;
|
|
|
|
mspriteframe_t *pspriteframe;
|
|
|
|
mspritegroup_t *pspritegroup;
|
|
|
|
|
|
|
|
psprite = currententity->model->cache.data;
|
|
|
|
frame = currententity->frame;
|
|
|
|
|
|
|
|
if ((frame >= psprite->numframes) || (frame < 0)) {
|
|
|
|
Con_Printf ("R_DrawSprite: no such frame %d\n", frame);
|
|
|
|
frame = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (psprite->frames[frame].type == SPR_SINGLE) {
|
|
|
|
pspriteframe = psprite->frames[frame].frameptr;
|
|
|
|
} else {
|
|
|
|
pspritegroup = (mspritegroup_t *) psprite->frames[frame].frameptr;
|
|
|
|
pintervals = pspritegroup->intervals;
|
|
|
|
numframes = pspritegroup->numframes;
|
|
|
|
fullinterval = pintervals[numframes - 1];
|
|
|
|
|
|
|
|
time = r_realtime + currententity->syncbase;
|
|
|
|
|
|
|
|
// when loading in Mod_LoadSpriteGroup, we guaranteed all interval
|
|
|
|
// values are positive, so we don't have to worry about division by 0
|
|
|
|
targettime = time - ((int) (time / fullinterval)) * fullinterval;
|
|
|
|
|
|
|
|
for (i = 0; i < (numframes - 1); i++) {
|
|
|
|
if (pintervals[i] > targettime)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pspriteframe = pspritegroup->frames[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return pspriteframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
R_DrawSpriteModel (entity_t *e)
|
|
|
|
{
|
2002-06-05 06:46:21 +00:00
|
|
|
float modelalpha, color[4];
|
2001-10-23 17:20:56 +00:00
|
|
|
float *up, *right;
|
|
|
|
msprite_t *psprite;
|
|
|
|
mspriteframe_t *frame;
|
|
|
|
vec3_t point, v_forward, v_right, v_up;
|
|
|
|
|
2001-12-19 18:32:26 +00:00
|
|
|
// don't bother culling, it's just a single polygon without a surface cache
|
2001-10-23 17:20:56 +00:00
|
|
|
frame = R_GetSpriteFrame (e);
|
2001-11-04 07:40:35 +00:00
|
|
|
psprite = e->model->cache.data;
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
if (psprite->type == SPR_ORIENTED) { // bullet marks on walls
|
2001-11-04 07:40:35 +00:00
|
|
|
AngleVectors (e->angles, v_forward, v_right, v_up);
|
2001-10-23 17:20:56 +00:00
|
|
|
up = v_up;
|
|
|
|
right = v_right;
|
2002-01-11 03:00:32 +00:00
|
|
|
} else if (psprite->type == SPR_VP_PARALLEL_UPRIGHT) {
|
|
|
|
v_up[0] = 0;
|
|
|
|
v_up[1] = 0;
|
|
|
|
v_up[2] = 1;
|
|
|
|
up = v_up;
|
|
|
|
right = vright;
|
2001-10-23 17:20:56 +00:00
|
|
|
} else { // normal sprite
|
|
|
|
up = vup;
|
|
|
|
right = vright;
|
|
|
|
}
|
2002-06-05 06:46:21 +00:00
|
|
|
if (e->scale != 1.0) {
|
|
|
|
VectorScale (up, e->scale, up);
|
|
|
|
VectorScale (right, e->scale, right);
|
|
|
|
}
|
|
|
|
|
2002-06-07 11:25:47 +00:00
|
|
|
modelalpha = e->colormod[3];
|
2002-06-05 06:46:21 +00:00
|
|
|
if (modelalpha < 1.0)
|
|
|
|
qfglDepthMask (GL_FALSE);
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, frame->gl_texturenum);
|
|
|
|
|
|
|
|
qfglBegin (GL_QUADS);
|
|
|
|
|
2002-06-05 05:56:13 +00:00
|
|
|
VectorCopy (e->colormod, color);
|
2002-06-14 06:23:11 +00:00
|
|
|
color[3] = e->colormod[3];
|
2002-06-05 05:56:13 +00:00
|
|
|
qfglColor4fv (color);
|
|
|
|
|
2001-10-23 17:20:56 +00:00
|
|
|
qfglTexCoord2f (0, 1);
|
|
|
|
VectorMA (e->origin, frame->down, up, point);
|
|
|
|
VectorMA (point, frame->left, right, point);
|
|
|
|
qfglVertex3fv (point);
|
|
|
|
|
|
|
|
qfglTexCoord2f (0, 0);
|
|
|
|
VectorMA (e->origin, frame->up, up, point);
|
|
|
|
VectorMA (point, frame->left, right, point);
|
|
|
|
qfglVertex3fv (point);
|
|
|
|
|
|
|
|
qfglTexCoord2f (1, 0);
|
|
|
|
VectorMA (e->origin, frame->up, up, point);
|
|
|
|
VectorMA (point, frame->right, right, point);
|
|
|
|
qfglVertex3fv (point);
|
|
|
|
|
|
|
|
qfglTexCoord2f (1, 1);
|
|
|
|
VectorMA (e->origin, frame->down, up, point);
|
|
|
|
VectorMA (point, frame->right, right, point);
|
|
|
|
qfglVertex3fv (point);
|
|
|
|
|
|
|
|
qfglEnd ();
|
2002-06-05 06:46:21 +00:00
|
|
|
|
|
|
|
if (modelalpha < 1.0)
|
|
|
|
qfglDepthMask (GL_TRUE);
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|