mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-06 13:11:20 +00:00
bf309fb554
their own files.
157 lines
3.8 KiB
C
157 lines
3.8 KiB
C
/*
|
|
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
|
|
|
|
*/
|
|
static const char rcsid[] =
|
|
"$Id$";
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
# include "config.h"
|
|
#endif
|
|
#ifdef HAVE_STRING_H
|
|
# include <string.h>
|
|
#endif
|
|
#ifdef HAVE_STRINGS_H
|
|
# include <strings.h>
|
|
#endif
|
|
|
|
#include <math.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "QF/console.h"
|
|
#include "QF/cvar.h"
|
|
#include "QF/locs.h"
|
|
#include "QF/mathlib.h"
|
|
#include "QF/qargs.h"
|
|
#include "QF/render.h"
|
|
#include "QF/skin.h"
|
|
#include "QF/sound.h"
|
|
#include "QF/sys.h"
|
|
#include "QF/vid.h"
|
|
#include "QF/GL/defines.h"
|
|
#include "QF/GL/funcs.h"
|
|
#include "QF/GL/qf_rlight.h"
|
|
#include "QF/GL/qf_rsurf.h"
|
|
#include "QF/GL/qf_screen.h"
|
|
#include "QF/GL/qf_vid.h"
|
|
|
|
#include "compat.h"
|
|
#include "r_cvar.h"
|
|
#include "r_dynamic.h"
|
|
#include "r_local.h"
|
|
#include "view.h"
|
|
|
|
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)
|
|
{
|
|
float *up, *right;
|
|
msprite_t *psprite;
|
|
mspriteframe_t *frame;
|
|
vec3_t point, v_forward, v_right, v_up;
|
|
|
|
// don't even bother culling, because it's just a single
|
|
// polygon without a surface cache
|
|
frame = R_GetSpriteFrame (e);
|
|
psprite = currententity->model->cache.data;
|
|
|
|
if (psprite->type == SPR_ORIENTED) { // bullet marks on walls
|
|
AngleVectors (currententity->angles, v_forward, v_right, v_up);
|
|
up = v_up;
|
|
right = v_right;
|
|
} else { // normal sprite
|
|
up = vup;
|
|
right = vright;
|
|
}
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, frame->gl_texturenum);
|
|
|
|
qfglBegin (GL_QUADS);
|
|
|
|
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 ();
|
|
}
|