2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2001-08-25 02:47:11 +00:00
|
|
|
sw_rsprite.c
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 04:50:53 +00:00
|
|
|
(description)
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2001-05-15 04:50:53 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <math.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-20 03:54:55 +00:00
|
|
|
#include "QF/render.h"
|
2001-05-15 04:50:53 +00:00
|
|
|
#include "QF/sys.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-07-24 05:19:52 +00:00
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2001-05-10 06:01:11 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int clip_current;
|
|
|
|
static vec5_t clip_verts[2][MAXWORKINGVERTS];
|
|
|
|
static int sprite_width, sprite_height;
|
|
|
|
|
|
|
|
spritedesc_t r_spritedesc;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
R_RotateSprite (float beamlength)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t vec;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (beamlength == 0.0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VectorScale (r_spritedesc.vpn, -beamlength, vec);
|
|
|
|
VectorAdd (r_entorigin, vec, r_entorigin);
|
|
|
|
VectorSubtract (modelorg, vec, modelorg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-05-15 04:50:53 +00:00
|
|
|
R_ClipSpriteFace
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 04:50:53 +00:00
|
|
|
Clips the winding at clip_verts[clip_current] and changes clip_current
|
|
|
|
Throws out the back side
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static int
|
2001-02-26 06:48:02 +00:00
|
|
|
R_ClipSpriteFace (int nump, clipplane_t *pclipplane)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, outcount;
|
|
|
|
float dists[MAXWORKINGVERTS + 1];
|
|
|
|
float frac, clipdist, *pclipnormal;
|
|
|
|
float *in, *instep, *outstep, *vert2;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
clipdist = pclipplane->dist;
|
|
|
|
pclipnormal = pclipplane->normal;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// calc dists
|
2001-02-26 06:48:02 +00:00
|
|
|
if (clip_current) {
|
2001-02-19 21:15:25 +00:00
|
|
|
in = clip_verts[1][0];
|
|
|
|
outstep = clip_verts[0][0];
|
|
|
|
clip_current = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
in = clip_verts[0][0];
|
|
|
|
outstep = clip_verts[1][0];
|
|
|
|
clip_current = 1;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
instep = in;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < nump; i++, instep += sizeof (vec5_t) / sizeof (float)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
dists[i] = DotProduct (instep, pclipnormal) - clipdist;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// handle wraparound case
|
2001-02-19 21:15:25 +00:00
|
|
|
dists[nump] = dists[0];
|
|
|
|
memcpy (instep, in, sizeof (vec5_t));
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// clip the winding
|
2001-02-19 21:15:25 +00:00
|
|
|
instep = in;
|
|
|
|
outcount = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < nump; i++, instep += sizeof (vec5_t) / sizeof (float)) {
|
|
|
|
if (dists[i] >= 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
memcpy (outstep, instep, sizeof (vec5_t));
|
|
|
|
outstep += sizeof (vec5_t) / sizeof (float);
|
|
|
|
outcount++;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dists[i] == 0 || dists[i + 1] == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2003-01-06 19:05:51 +00:00
|
|
|
#if __APPLE_CC__ <= 1175
|
2002-12-20 23:49:11 +00:00
|
|
|
// bug in gcc (GCC) 3.1 20020420 (prerelease) for darwin
|
|
|
|
if ((dists[i] > 0) && (dists[i + 1] > 0))
|
|
|
|
continue;
|
|
|
|
if ((dists[i] <= 0) && (dists[i + 1] <= 0))
|
|
|
|
continue;
|
|
|
|
#else
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((dists[i] > 0) == (dists[i + 1] > 0))
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2002-12-20 23:49:11 +00:00
|
|
|
#endif
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
// split it into a new vertex
|
|
|
|
frac = dists[i] / (dists[i] - dists[i + 1]);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
vert2 = instep + sizeof (vec5_t) / sizeof (float);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
outstep[0] = instep[0] + frac * (vert2[0] - instep[0]);
|
|
|
|
outstep[1] = instep[1] + frac * (vert2[1] - instep[1]);
|
|
|
|
outstep[2] = instep[2] + frac * (vert2[2] - instep[2]);
|
|
|
|
outstep[3] = instep[3] + frac * (vert2[3] - instep[3]);
|
|
|
|
outstep[4] = instep[4] + frac * (vert2[4] - instep[4]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
outstep += sizeof (vec5_t) / sizeof (float);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
outcount++;
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
return outcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-05-15 04:50:53 +00:00
|
|
|
R_SetupAndDrawSprite (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, nump;
|
|
|
|
float dot, scale, *pv;
|
|
|
|
vec5_t *pverts;
|
|
|
|
vec3_t left, up, right, down, transformed, local;
|
|
|
|
emitpoint_t outverts[MAXWORKINGVERTS + 1], *pout;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
dot = DotProduct (r_spritedesc.vpn, modelorg);
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// backface cull
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dot >= 0)
|
|
|
|
return;
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// build the sprite poster in worldspace
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorScale (r_spritedesc.vright, r_spritedesc.pspriteframe->right, right);
|
|
|
|
VectorScale (r_spritedesc.vup, r_spritedesc.pspriteframe->up, up);
|
|
|
|
VectorScale (r_spritedesc.vright, r_spritedesc.pspriteframe->left, left);
|
|
|
|
VectorScale (r_spritedesc.vup, r_spritedesc.pspriteframe->down, down);
|
|
|
|
|
|
|
|
pverts = clip_verts[0];
|
|
|
|
|
|
|
|
pverts[0][0] = r_entorigin[0] + up[0] + left[0];
|
|
|
|
pverts[0][1] = r_entorigin[1] + up[1] + left[1];
|
|
|
|
pverts[0][2] = r_entorigin[2] + up[2] + left[2];
|
|
|
|
pverts[0][3] = 0;
|
|
|
|
pverts[0][4] = 0;
|
|
|
|
|
|
|
|
pverts[1][0] = r_entorigin[0] + up[0] + right[0];
|
|
|
|
pverts[1][1] = r_entorigin[1] + up[1] + right[1];
|
|
|
|
pverts[1][2] = r_entorigin[2] + up[2] + right[2];
|
|
|
|
pverts[1][3] = sprite_width;
|
|
|
|
pverts[1][4] = 0;
|
|
|
|
|
|
|
|
pverts[2][0] = r_entorigin[0] + down[0] + right[0];
|
|
|
|
pverts[2][1] = r_entorigin[1] + down[1] + right[1];
|
|
|
|
pverts[2][2] = r_entorigin[2] + down[2] + right[2];
|
|
|
|
pverts[2][3] = sprite_width;
|
|
|
|
pverts[2][4] = sprite_height;
|
|
|
|
|
|
|
|
pverts[3][0] = r_entorigin[0] + down[0] + left[0];
|
|
|
|
pverts[3][1] = r_entorigin[1] + down[1] + left[1];
|
|
|
|
pverts[3][2] = r_entorigin[2] + down[2] + left[2];
|
|
|
|
pverts[3][3] = 0;
|
|
|
|
pverts[3][4] = sprite_height;
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// clip to the frustum in worldspace
|
2001-02-19 21:15:25 +00:00
|
|
|
nump = 4;
|
|
|
|
clip_current = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
nump = R_ClipSpriteFace (nump, &view_clipplanes[i]);
|
|
|
|
if (nump < 3)
|
|
|
|
return;
|
|
|
|
if (nump >= MAXWORKINGVERTS)
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error ("R_SetupAndDrawSprite: too many points");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// transform vertices into viewspace and project
|
2001-02-19 21:15:25 +00:00
|
|
|
pv = &clip_verts[clip_current][0][0];
|
|
|
|
r_spritedesc.nearzi = -999999;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < nump; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorSubtract (pv, r_origin, local);
|
|
|
|
TransformVector (local, transformed);
|
|
|
|
|
|
|
|
if (transformed[2] < NEAR_CLIP)
|
|
|
|
transformed[2] = NEAR_CLIP;
|
|
|
|
|
|
|
|
pout = &outverts[i];
|
|
|
|
pout->zi = 1.0 / transformed[2];
|
|
|
|
if (pout->zi > r_spritedesc.nearzi)
|
|
|
|
r_spritedesc.nearzi = pout->zi;
|
|
|
|
|
|
|
|
pout->s = pv[3];
|
|
|
|
pout->t = pv[4];
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
scale = xscale * pout->zi;
|
|
|
|
pout->u = (xcenter + scale * transformed[0]);
|
|
|
|
|
|
|
|
scale = yscale * pout->zi;
|
|
|
|
pout->v = (ycenter - scale * transformed[1]);
|
|
|
|
|
|
|
|
pv += sizeof (vec5_t) / sizeof (*pv);
|
|
|
|
}
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// draw it
|
2001-02-19 21:15:25 +00:00
|
|
|
r_spritedesc.nump = nump;
|
|
|
|
r_spritedesc.pverts = outverts;
|
|
|
|
D_DrawSprite ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static mspriteframe_t *
|
2001-02-26 06:48:02 +00:00
|
|
|
R_GetSpriteframe (msprite_t *psprite)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
mspritegroup_t *pspritegroup;
|
|
|
|
mspriteframe_t *pspriteframe;
|
|
|
|
int i, numframes, frame;
|
|
|
|
float *pintervals, fullinterval, targettime, time;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
frame = currententity->animation.frame;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((frame >= psprite->numframes) || (frame < 0)) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("R_DrawSprite: no such frame %d\n", frame);
|
2001-02-19 21:15:25 +00:00
|
|
|
frame = 0;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (psprite->frames[frame].type == SPR_SINGLE) {
|
2001-02-19 21:15:25 +00:00
|
|
|
pspriteframe = psprite->frames[frame].frameptr;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
pspritegroup = (mspritegroup_t *) psprite->frames[frame].frameptr;
|
2001-02-19 21:15:25 +00:00
|
|
|
pintervals = pspritegroup->intervals;
|
|
|
|
numframes = pspritegroup->numframes;
|
2001-02-26 06:48:02 +00:00
|
|
|
fullinterval = pintervals[numframes - 1];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
time = vr_data.realtime + currententity->animation.syncbase;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// when loading in Mod_LoadSpriteGroup, we guaranteed all interval
|
2001-05-15 21:13:07 +00:00
|
|
|
// values are positive, so we don't have to worry about division by 0
|
2001-02-26 06:48:02 +00:00
|
|
|
targettime = time - ((int) (time / fullinterval)) * fullinterval;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < (numframes - 1); i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (pintervals[i] > targettime)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pspriteframe = pspritegroup->frames[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return pspriteframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_DrawSprite (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
msprite_t *psprite;
|
|
|
|
vec3_t tvec;
|
2021-03-19 11:18:45 +00:00
|
|
|
float dot, sr, cr;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
psprite = currententity->renderer.model->cache.data;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
r_spritedesc.pspriteframe = R_GetSpriteframe (psprite);
|
|
|
|
|
|
|
|
sprite_width = r_spritedesc.pspriteframe->width;
|
|
|
|
sprite_height = r_spritedesc.pspriteframe->height;
|
|
|
|
|
2001-08-28 22:46:02 +00:00
|
|
|
// TODO: make this caller-selectable
|
2001-02-26 06:48:02 +00:00
|
|
|
if (psprite->type == SPR_FACING_UPRIGHT) {
|
2001-05-15 21:13:07 +00:00
|
|
|
// generate the sprite's axes, with vup straight up in worldspace, and
|
2001-02-26 06:48:02 +00:00
|
|
|
// r_spritedesc.vright perpendicular to modelorg.
|
2001-05-19 23:38:56 +00:00
|
|
|
// This will not work if the view direction is very close to straight
|
2001-05-15 21:13:07 +00:00
|
|
|
// up or down, because the cross product will be between two nearly
|
|
|
|
// parallel vectors and starts to approach an undefined state, so we
|
|
|
|
// don't draw if the two vectors are less than 1 degree apart
|
2001-02-19 21:15:25 +00:00
|
|
|
tvec[0] = -modelorg[0];
|
|
|
|
tvec[1] = -modelorg[1];
|
|
|
|
tvec[2] = -modelorg[2];
|
|
|
|
VectorNormalize (tvec);
|
2001-02-26 06:48:02 +00:00
|
|
|
dot = tvec[2]; // same as DotProduct (tvec,
|
2001-05-15 04:50:53 +00:00
|
|
|
// r_spritedesc.vup) because
|
2001-02-26 06:48:02 +00:00
|
|
|
// r_spritedesc.vup is 0, 0, 1
|
|
|
|
if ((dot > 0.999848) || (dot < -0.999848)) // cos(1 degree) =
|
2001-05-15 04:50:53 +00:00
|
|
|
// 0.999848
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
r_spritedesc.vup[0] = 0;
|
|
|
|
r_spritedesc.vup[1] = 0;
|
|
|
|
r_spritedesc.vup[2] = 1;
|
|
|
|
r_spritedesc.vright[0] = tvec[1];
|
2001-08-28 22:46:02 +00:00
|
|
|
//CrossProduct(r_spritedesc.vup, -modelorg, r_spritedesc.vright)
|
2001-02-19 21:15:25 +00:00
|
|
|
r_spritedesc.vright[1] = -tvec[0];
|
|
|
|
r_spritedesc.vright[2] = 0;
|
|
|
|
VectorNormalize (r_spritedesc.vright);
|
|
|
|
r_spritedesc.vpn[0] = -r_spritedesc.vright[1];
|
|
|
|
r_spritedesc.vpn[1] = r_spritedesc.vright[0];
|
|
|
|
r_spritedesc.vpn[2] = 0;
|
2001-05-19 23:38:56 +00:00
|
|
|
//CrossProduct (r_spritedesc.vright, r_spritedesc.vup, r_spritedesc.vpn)
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (psprite->type == SPR_VP_PARALLEL) {
|
|
|
|
// generate the sprite's axes, completely parallel to the viewplane.
|
2001-05-15 21:13:07 +00:00
|
|
|
// There are no problem situations, because the sprite is always in the
|
|
|
|
// same position relative to the viewer
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_spritedesc.vup[i] = vup[i];
|
|
|
|
r_spritedesc.vright[i] = vright[i];
|
|
|
|
r_spritedesc.vpn[i] = vpn[i];
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (psprite->type == SPR_VP_PARALLEL_UPRIGHT) {
|
2001-05-15 21:13:07 +00:00
|
|
|
// generate the sprite's axes, with vup straight up in worldspace, and
|
2001-02-26 06:48:02 +00:00
|
|
|
// r_spritedesc.vright parallel to the viewplane.
|
2012-05-21 23:23:22 +00:00
|
|
|
// This will not work if the view direction is very close to straight
|
2001-05-15 21:13:07 +00:00
|
|
|
// up or down, because the cross product will be between two nearly
|
|
|
|
// parallel vectors and starts to approach an undefined state, so we
|
|
|
|
// don't draw if the two vectors are less than 1 degree apart
|
2001-02-26 06:48:02 +00:00
|
|
|
dot = vpn[2]; // same as DotProduct (vpn,
|
2001-05-15 04:50:53 +00:00
|
|
|
// r_spritedesc.vup) because
|
2001-02-26 06:48:02 +00:00
|
|
|
// r_spritedesc.vup is 0, 0, 1
|
|
|
|
if ((dot > 0.999848) || (dot < -0.999848)) // cos(1 degree) =
|
2001-05-15 04:50:53 +00:00
|
|
|
// 0.999848
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
r_spritedesc.vup[0] = 0;
|
|
|
|
r_spritedesc.vup[1] = 0;
|
|
|
|
r_spritedesc.vup[2] = 1;
|
|
|
|
r_spritedesc.vright[0] = vpn[1];
|
2001-05-19 23:38:56 +00:00
|
|
|
//CrossProduct (r_spritedesc.vup, vpn,
|
2001-02-26 06:48:02 +00:00
|
|
|
r_spritedesc.vright[1] = -vpn[0]; // r_spritedesc.vright)
|
2001-02-19 21:15:25 +00:00
|
|
|
r_spritedesc.vright[2] = 0;
|
|
|
|
VectorNormalize (r_spritedesc.vright);
|
|
|
|
r_spritedesc.vpn[0] = -r_spritedesc.vright[1];
|
|
|
|
r_spritedesc.vpn[1] = r_spritedesc.vright[0];
|
|
|
|
r_spritedesc.vpn[2] = 0;
|
2001-05-19 23:38:56 +00:00
|
|
|
//CrossProduct (r_spritedesc.vright, r_spritedesc.vup, r_spritedesc.vpn)
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (psprite->type == SPR_ORIENTED) {
|
|
|
|
// generate the sprite's axes, according to the sprite's world
|
|
|
|
// orientation
|
2021-03-09 14:52:40 +00:00
|
|
|
mat4f_t mat;
|
|
|
|
Transform_GetWorldMatrix (currententity->transform, mat);
|
|
|
|
VectorCopy (mat[0], r_spritedesc.vpn);
|
|
|
|
VectorNegate (mat[1], r_spritedesc.vright);
|
|
|
|
VectorCopy (mat[2], r_spritedesc.vup);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (psprite->type == SPR_VP_PARALLEL_ORIENTED) {
|
2001-05-15 21:13:07 +00:00
|
|
|
// generate the sprite's axes, parallel to the viewplane, but rotated
|
|
|
|
// in that plane around the center according to the sprite entity's
|
|
|
|
// roll angle. So vpn stays the same, but vright and vup rotate
|
2021-03-19 11:18:45 +00:00
|
|
|
vec4f_t rot = Transform_GetLocalRotation (currententity->transform);
|
|
|
|
//FIXME assumes the entity is only rolled
|
|
|
|
sr = 2 * rot[0] * rot[3];
|
|
|
|
cr = rot[3] * rot[3] - rot[0] * rot[0];
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_spritedesc.vpn[i] = vpn[i];
|
|
|
|
r_spritedesc.vright[i] = vright[i] * cr + vup[i] * sr;
|
|
|
|
r_spritedesc.vup[i] = vright[i] * -sr + vup[i] * cr;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("R_DrawSprite: Bad sprite type %d", psprite->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
R_RotateSprite (psprite->beamlength);
|
|
|
|
|
|
|
|
R_SetupAndDrawSprite ();
|
|
|
|
}
|