2001-10-23 17:20:56 +00:00
|
|
|
/*
|
|
|
|
gl_mod_alias.c
|
|
|
|
|
2004-02-08 02:49:38 +00:00
|
|
|
Draw Alias Model
|
2001-10-23 17:20:56 +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
|
|
|
|
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2001-10-23 17:20:56 +00:00
|
|
|
#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_rmain.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"
|
|
|
|
|
|
|
|
typedef struct {
|
2004-03-10 08:14:38 +00:00
|
|
|
vec3_t vert;
|
|
|
|
vec3_t normal;
|
2001-10-23 17:20:56 +00:00
|
|
|
} blended_vert_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2004-03-15 21:32:19 +00:00
|
|
|
blended_vert_t *verts;
|
|
|
|
int *order;
|
|
|
|
tex_coord_t *tex_coord;
|
|
|
|
int count;
|
2001-10-23 17:20:56 +00:00
|
|
|
} vert_order_t;
|
|
|
|
|
|
|
|
float r_avertexnormals[NUMVERTEXNORMALS][3] = {
|
|
|
|
#include "anorms.h"
|
|
|
|
};
|
|
|
|
|
|
|
|
// precalculated dot products for quantized angles
|
|
|
|
#define SHADEDOT_QUANT 16
|
2003-08-26 07:00:13 +00:00
|
|
|
float r_avertexnormal_dots[SHADEDOT_QUANT][256] = {
|
|
|
|
#include "anorm_dots.h"
|
|
|
|
};
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
vec3_t shadevector;
|
|
|
|
|
2003-04-08 04:13:49 +00:00
|
|
|
|
2003-08-11 06:05:07 +00:00
|
|
|
static inline void
|
2003-04-08 04:13:49 +00:00
|
|
|
GL_DrawAliasFrameTri (vert_order_t *vo)
|
|
|
|
{
|
2004-03-15 21:32:19 +00:00
|
|
|
int count = vo->count;
|
|
|
|
blended_vert_t *verts = vo->verts;
|
|
|
|
tex_coord_t *tex_coord = vo->tex_coord;
|
2004-03-10 08:14:38 +00:00
|
|
|
|
2003-04-08 04:13:49 +00:00
|
|
|
qfglBegin (GL_TRIANGLES);
|
|
|
|
do {
|
2004-03-10 08:14:38 +00:00
|
|
|
// texture coordinates come from the draw list
|
2003-04-08 04:13:49 +00:00
|
|
|
qfglTexCoord2fv (tex_coord->st);
|
|
|
|
tex_coord++;
|
2004-02-08 02:49:38 +00:00
|
|
|
|
2004-03-15 21:32:19 +00:00
|
|
|
// normals and vertices come from the frame list
|
2004-03-10 08:14:38 +00:00
|
|
|
qfglNormal3fv (verts->normal);
|
2003-04-08 04:13:49 +00:00
|
|
|
qfglVertex3fv (verts->vert);
|
|
|
|
verts++;
|
2004-03-10 08:14:38 +00:00
|
|
|
} while (count--);
|
|
|
|
qfglEnd ();
|
2003-04-08 04:13:49 +00:00
|
|
|
}
|
|
|
|
|
2003-08-11 06:05:07 +00:00
|
|
|
static inline void
|
2003-04-08 04:13:49 +00:00
|
|
|
GL_DrawAliasFrameTriMulti (vert_order_t *vo)
|
|
|
|
{
|
2004-03-15 21:32:19 +00:00
|
|
|
int count = vo->count;
|
|
|
|
blended_vert_t *verts = vo->verts;
|
|
|
|
tex_coord_t *tex_coord = vo->tex_coord;
|
2003-04-08 04:13:49 +00:00
|
|
|
|
|
|
|
qfglBegin (GL_TRIANGLES);
|
|
|
|
do {
|
|
|
|
// texture coordinates come from the draw list
|
|
|
|
qglMultiTexCoord2fv (gl_mtex_enum + 0, tex_coord->st);
|
|
|
|
qglMultiTexCoord2fv (gl_mtex_enum + 1, tex_coord->st);
|
|
|
|
tex_coord++;
|
|
|
|
|
2004-03-15 21:32:19 +00:00
|
|
|
// normals and vertices come from the frame list
|
2004-03-10 08:14:38 +00:00
|
|
|
qfglNormal3fv (verts->normal);
|
2003-04-08 04:13:49 +00:00
|
|
|
qfglVertex3fv (verts->vert);
|
|
|
|
verts++;
|
|
|
|
} while (--count);
|
|
|
|
qfglEnd ();
|
|
|
|
}
|
|
|
|
|
2003-08-11 06:05:07 +00:00
|
|
|
static inline void
|
2002-01-02 19:23:09 +00:00
|
|
|
GL_DrawAliasFrame (vert_order_t *vo)
|
|
|
|
{
|
|
|
|
int count;
|
2004-03-15 21:32:19 +00:00
|
|
|
int *order = vo->order;
|
|
|
|
blended_vert_t *verts = vo->verts;
|
2002-01-02 19:23:09 +00:00
|
|
|
|
|
|
|
while ((count = *order++)) {
|
|
|
|
// get the vertex count and primitive type
|
|
|
|
if (count < 0) {
|
|
|
|
count = -count;
|
|
|
|
qfglBegin (GL_TRIANGLE_FAN);
|
|
|
|
} else {
|
|
|
|
qfglBegin (GL_TRIANGLE_STRIP);
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
// texture coordinates come from the draw list
|
|
|
|
qfglTexCoord2fv ((float *) order);
|
|
|
|
order += 2;
|
|
|
|
|
2004-03-15 21:32:19 +00:00
|
|
|
// normals and vertices come from the frame list
|
2004-03-10 08:14:38 +00:00
|
|
|
qfglNormal3fv (verts->normal);
|
2002-01-02 19:23:09 +00:00
|
|
|
qfglVertex3fv (verts->vert);
|
|
|
|
verts++;
|
|
|
|
} while (--count);
|
|
|
|
|
|
|
|
qfglEnd ();
|
|
|
|
}
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|
|
|
|
|
2003-08-11 06:05:07 +00:00
|
|
|
static inline void
|
2002-04-16 16:51:35 +00:00
|
|
|
GL_DrawAliasFrameMulti (vert_order_t *vo)
|
|
|
|
{
|
|
|
|
int count;
|
2004-03-15 21:32:19 +00:00
|
|
|
int *order = vo->order;
|
|
|
|
blended_vert_t *verts = vo->verts;
|
2002-04-16 16:51:35 +00:00
|
|
|
|
|
|
|
while ((count = *order++)) {
|
|
|
|
// get the vertex count and primitive type
|
|
|
|
if (count < 0) {
|
|
|
|
count = -count;
|
|
|
|
qfglBegin (GL_TRIANGLE_FAN);
|
|
|
|
} else {
|
|
|
|
qfglBegin (GL_TRIANGLE_STRIP);
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
// texture coordinates come from the draw list
|
|
|
|
qglMultiTexCoord2fv (gl_mtex_enum + 0, (float *) order);
|
|
|
|
qglMultiTexCoord2fv (gl_mtex_enum + 1, (float *) order);
|
|
|
|
order += 2;
|
|
|
|
|
2004-03-15 21:32:19 +00:00
|
|
|
// normals and vertices come from the frame list
|
2004-03-10 08:14:38 +00:00
|
|
|
qfglNormal3fv (verts->normal);
|
2002-04-16 16:51:35 +00:00
|
|
|
qfglVertex3fv (verts->vert);
|
|
|
|
verts++;
|
|
|
|
} while (--count);
|
|
|
|
|
|
|
|
qfglEnd ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-23 17:20:56 +00:00
|
|
|
/*
|
|
|
|
GL_DrawAliasShadow
|
|
|
|
|
|
|
|
Standard shadow drawing
|
|
|
|
*/
|
|
|
|
static void
|
2001-12-30 04:16:25 +00:00
|
|
|
GL_DrawAliasShadow (aliashdr_t *paliashdr, vert_order_t *vo)
|
2001-10-23 17:20:56 +00:00
|
|
|
{
|
|
|
|
float height, lheight;
|
|
|
|
int count;
|
2004-03-15 21:32:19 +00:00
|
|
|
int *order = vo->order;
|
2001-10-23 17:20:56 +00:00
|
|
|
vec3_t point;
|
2004-03-15 21:32:19 +00:00
|
|
|
blended_vert_t *verts = vo->verts;
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2002-01-02 19:23:09 +00:00
|
|
|
lheight = currententity->origin[2] - lightspot[2];
|
2001-10-23 17:20:56 +00:00
|
|
|
height = -lheight + 1.0;
|
|
|
|
|
|
|
|
while ((count = *order++)) {
|
|
|
|
// get the vertex count and primitive type
|
|
|
|
if (count < 0) {
|
|
|
|
count = -count;
|
|
|
|
qfglBegin (GL_TRIANGLE_FAN);
|
|
|
|
} else
|
|
|
|
qfglBegin (GL_TRIANGLE_STRIP);
|
|
|
|
|
|
|
|
do {
|
2002-01-02 19:23:09 +00:00
|
|
|
order += 2; // skip texture coords
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2004-03-15 21:32:19 +00:00
|
|
|
// normals and vertices come from the frame list
|
2001-10-23 17:20:56 +00:00
|
|
|
point[0] =
|
2001-12-30 04:16:25 +00:00
|
|
|
verts->vert[0] * paliashdr->mdl.scale[0] +
|
2001-10-23 17:20:56 +00:00
|
|
|
paliashdr->mdl.scale_origin[0];
|
|
|
|
point[1] =
|
2001-12-30 04:16:25 +00:00
|
|
|
verts->vert[1] * paliashdr->mdl.scale[1] +
|
2001-10-23 17:20:56 +00:00
|
|
|
paliashdr->mdl.scale_origin[1];
|
|
|
|
point[2] =
|
2001-12-30 04:16:25 +00:00
|
|
|
verts->vert[2] * paliashdr->mdl.scale[2] +
|
2002-08-20 00:48:59 +00:00
|
|
|
paliashdr->mdl.scale_origin[2] + lheight;
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2002-08-20 00:48:59 +00:00
|
|
|
point[0] -= shadevector[0] * point[2];
|
|
|
|
point[1] -= shadevector[1] * point[2];
|
2001-10-23 17:20:56 +00:00
|
|
|
point[2] = height;
|
|
|
|
qfglVertex3fv (point);
|
|
|
|
|
|
|
|
verts++;
|
|
|
|
} while (--count);
|
|
|
|
|
|
|
|
qfglEnd ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-11 06:05:07 +00:00
|
|
|
static inline vert_order_t *
|
2002-01-07 03:46:56 +00:00
|
|
|
GL_GetAliasFrameVerts16 (int frame, aliashdr_t *paliashdr, entity_t *e)
|
2001-10-23 17:20:56 +00:00
|
|
|
{
|
2004-03-15 21:32:19 +00:00
|
|
|
float interval;
|
|
|
|
int count, numposes, pose, i;
|
|
|
|
trivertx16_t *verts;
|
|
|
|
vert_order_t *vo;
|
2001-12-18 05:50:57 +00:00
|
|
|
blended_vert_t *vo_v;
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
if ((frame >= paliashdr->mdl.numframes) || (frame < 0)) {
|
2001-12-08 20:58:09 +00:00
|
|
|
if (developer->int_val)
|
|
|
|
Con_Printf ("R_AliasSetupFrame: no such frame %d %s\n", frame,
|
|
|
|
currententity->model->name);
|
2001-10-23 17:20:56 +00:00
|
|
|
frame = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pose = paliashdr->frames[frame].firstpose;
|
|
|
|
numposes = paliashdr->frames[frame].numposes;
|
2002-01-07 06:32:46 +00:00
|
|
|
verts = (trivertx16_t *) ((byte *) paliashdr + paliashdr->posedata);
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
count = paliashdr->poseverts;
|
|
|
|
vo = Hunk_TempAlloc (sizeof (*vo) + count * sizeof (blended_vert_t));
|
|
|
|
vo->order = (int *) ((byte *) paliashdr + paliashdr->commands);
|
2002-08-20 00:48:59 +00:00
|
|
|
vo->verts = (blended_vert_t *) &vo[1];
|
2003-04-08 04:13:49 +00:00
|
|
|
if (paliashdr->tex_coord) {
|
2004-03-10 08:14:38 +00:00
|
|
|
vo->tex_coord = (tex_coord_t *) ((byte *) paliashdr
|
|
|
|
+ paliashdr->tex_coord);
|
2003-04-08 04:13:49 +00:00
|
|
|
} else {
|
|
|
|
vo->tex_coord = NULL;
|
|
|
|
}
|
|
|
|
vo->count = count;
|
2001-10-23 17:20:56 +00:00
|
|
|
if (numposes > 1) {
|
|
|
|
interval = paliashdr->frames[frame].interval;
|
|
|
|
pose += (int) (r_realtime / interval) % numposes;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
One tenth of a second is good for most Quake animations. If
|
|
|
|
the nextthink is longer then the animation is usually meant
|
|
|
|
to pause (e.g. check out the shambler magic animation in
|
|
|
|
shambler.qc). If its shorter then things will still be
|
|
|
|
smoothed partly, and the jumps will be less noticable
|
|
|
|
because of the shorter time. So, this is probably a good
|
|
|
|
assumption.
|
|
|
|
*/
|
|
|
|
interval = 0.1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_lerp_anim->int_val) {
|
2002-01-07 06:32:46 +00:00
|
|
|
trivertx16_t *verts1, *verts2;
|
2001-12-21 21:52:03 +00:00
|
|
|
float blend;
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
e->frame_interval = interval;
|
|
|
|
|
|
|
|
if (e->pose2 != pose) {
|
|
|
|
e->frame_start_time = r_realtime;
|
|
|
|
if (e->pose2 == -1) {
|
|
|
|
e->pose1 = pose;
|
|
|
|
} else {
|
|
|
|
e->pose1 = e->pose2;
|
|
|
|
}
|
|
|
|
e->pose2 = pose;
|
2002-06-14 06:08:45 +00:00
|
|
|
blend = 0.0;
|
2004-03-15 21:32:19 +00:00
|
|
|
} else if (r_paused) {
|
|
|
|
blend = 1.0;
|
2001-10-23 17:20:56 +00:00
|
|
|
} else {
|
|
|
|
blend = (r_realtime - e->frame_start_time) / e->frame_interval;
|
2004-03-15 21:32:19 +00:00
|
|
|
blend = min (blend, 1.0);
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|
|
|
|
|
2002-08-02 18:07:53 +00:00
|
|
|
if (blend == 0.0) {
|
2002-08-03 07:07:23 +00:00
|
|
|
verts = verts + e->pose1 * count;
|
2002-08-02 18:07:53 +00:00
|
|
|
} else if (blend == 1.0) {
|
2002-08-03 07:07:23 +00:00
|
|
|
verts = verts + e->pose2 * count;
|
2001-10-23 17:20:56 +00:00
|
|
|
} else {
|
2002-08-03 07:07:23 +00:00
|
|
|
verts1 = verts + e->pose1 * count;
|
|
|
|
verts2 = verts + e->pose2 * count;
|
|
|
|
|
2002-01-07 03:46:56 +00:00
|
|
|
for (i = 0, vo_v = vo->verts; i < count;
|
|
|
|
i++, vo_v++, verts1++, verts2++) {
|
2002-08-12 06:14:55 +00:00
|
|
|
float *n1, *n2;
|
2002-08-20 00:48:59 +00:00
|
|
|
|
2004-03-10 08:14:38 +00:00
|
|
|
VectorBlend (verts1->v, verts2->v, blend, vo_v->vert);
|
2002-08-12 06:14:55 +00:00
|
|
|
n1 = r_avertexnormals[verts1->lightnormalindex];
|
|
|
|
n2 = r_avertexnormals[verts2->lightnormalindex];
|
2004-03-10 08:14:38 +00:00
|
|
|
VectorBlend (n1, n2, blend, vo_v->normal);
|
2004-03-15 21:32:19 +00:00
|
|
|
if (VectorIsZero (vo_v->normal)) {
|
2004-03-10 08:14:38 +00:00
|
|
|
if (blend < 0.5) {
|
|
|
|
VectorCopy (n1, vo_v->normal);
|
|
|
|
} else {
|
|
|
|
VectorCopy (n2, vo_v->normal);
|
|
|
|
}
|
|
|
|
}
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|
|
|
|
return vo;
|
|
|
|
}
|
2001-10-29 19:38:20 +00:00
|
|
|
} else {
|
2002-01-07 06:32:46 +00:00
|
|
|
verts += pose * count;
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|
2002-08-12 06:14:55 +00:00
|
|
|
|
2004-03-10 08:14:38 +00:00
|
|
|
for (i = 0, vo_v = vo->verts; i < count; i++, vo_v++, verts++) {
|
|
|
|
VectorCopy (verts->v, vo_v->vert);
|
|
|
|
VectorCopy (r_avertexnormals[verts->lightnormalindex], vo_v->normal);
|
2002-01-07 03:46:56 +00:00
|
|
|
}
|
|
|
|
return vo;
|
|
|
|
}
|
|
|
|
|
2003-08-11 06:05:07 +00:00
|
|
|
static inline vert_order_t *
|
2002-01-07 03:46:56 +00:00
|
|
|
GL_GetAliasFrameVerts (int frame, aliashdr_t *paliashdr, entity_t *e)
|
|
|
|
{
|
|
|
|
float interval;
|
|
|
|
int count, numposes, pose, i;
|
|
|
|
trivertx_t *verts;
|
|
|
|
vert_order_t *vo;
|
|
|
|
blended_vert_t *vo_v;
|
|
|
|
|
|
|
|
if ((frame >= paliashdr->mdl.numframes) || (frame < 0)) {
|
|
|
|
if (developer->int_val)
|
|
|
|
Con_Printf ("R_AliasSetupFrame: no such frame %d %s\n", frame,
|
|
|
|
currententity->model->name);
|
|
|
|
frame = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pose = paliashdr->frames[frame].firstpose;
|
|
|
|
numposes = paliashdr->frames[frame].numposes;
|
|
|
|
|
|
|
|
verts = (trivertx_t *) ((byte *) paliashdr + paliashdr->posedata);
|
|
|
|
|
|
|
|
count = paliashdr->poseverts;
|
|
|
|
vo = Hunk_TempAlloc (sizeof (*vo) + count * sizeof (blended_vert_t));
|
|
|
|
vo->order = (int *) ((byte *) paliashdr + paliashdr->commands);
|
2002-08-20 00:48:59 +00:00
|
|
|
vo->verts = (blended_vert_t *) &vo[1];
|
2003-04-08 04:13:49 +00:00
|
|
|
if (paliashdr->tex_coord) {
|
|
|
|
vo->tex_coord = (tex_coord_t *) ((byte *) paliashdr + paliashdr->tex_coord);
|
|
|
|
} else {
|
|
|
|
vo->tex_coord = NULL;
|
|
|
|
}
|
|
|
|
vo->count = count;
|
2002-01-07 03:46:56 +00:00
|
|
|
|
|
|
|
if (numposes > 1) {
|
|
|
|
interval = paliashdr->frames[frame].interval;
|
|
|
|
pose += (int) (r_realtime / interval) % numposes;
|
2002-01-05 19:03:36 +00:00
|
|
|
} else {
|
2002-01-07 03:46:56 +00:00
|
|
|
/*
|
|
|
|
One tenth of a second is good for most Quake animations. If
|
|
|
|
the nextthink is longer then the animation is usually meant
|
|
|
|
to pause (e.g. check out the shambler magic animation in
|
|
|
|
shambler.qc). If its shorter then things will still be
|
|
|
|
smoothed partly, and the jumps will be less noticable
|
|
|
|
because of the shorter time. So, this is probably a good
|
|
|
|
assumption.
|
|
|
|
*/
|
|
|
|
interval = 0.1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_lerp_anim->int_val) {
|
|
|
|
trivertx_t *verts1, *verts2;
|
|
|
|
float blend;
|
|
|
|
|
|
|
|
e->frame_interval = interval;
|
|
|
|
|
|
|
|
if (e->pose2 != pose) {
|
|
|
|
e->frame_start_time = r_realtime;
|
|
|
|
if (e->pose2 == -1) {
|
|
|
|
e->pose1 = pose;
|
|
|
|
} else {
|
|
|
|
e->pose1 = e->pose2;
|
|
|
|
}
|
|
|
|
e->pose2 = pose;
|
2004-03-15 21:32:19 +00:00
|
|
|
blend = 0.0;
|
|
|
|
} else if (r_paused) {
|
|
|
|
blend = 1.0;
|
2002-01-07 03:46:56 +00:00
|
|
|
} else {
|
|
|
|
blend = (r_realtime - e->frame_start_time) / e->frame_interval;
|
2004-03-15 21:32:19 +00:00
|
|
|
blend = min (blend, 1.0);
|
2002-01-07 03:46:56 +00:00
|
|
|
}
|
|
|
|
|
2002-08-03 06:13:35 +00:00
|
|
|
if (blend == 0.0) {
|
2002-08-03 07:07:23 +00:00
|
|
|
verts = verts + e->pose1 * count;
|
2002-08-02 18:07:53 +00:00
|
|
|
} else if (blend == 1.0) {
|
2002-08-03 07:07:23 +00:00
|
|
|
verts = verts + e->pose2 * count;
|
2002-01-07 03:46:56 +00:00
|
|
|
} else {
|
2002-08-03 07:07:23 +00:00
|
|
|
verts1 = verts + e->pose1 * count;
|
|
|
|
verts2 = verts + e->pose2 * count;
|
|
|
|
|
2002-01-07 03:46:56 +00:00
|
|
|
for (i = 0, vo_v = vo->verts; i < count;
|
|
|
|
i++, vo_v++, verts1++, verts2++) {
|
2002-08-12 06:14:55 +00:00
|
|
|
float *n1, *n2;
|
|
|
|
|
2002-01-07 03:46:56 +00:00
|
|
|
VectorBlend (verts1->v, verts2->v, blend, vo_v->vert);
|
2002-08-12 06:14:55 +00:00
|
|
|
n1 = r_avertexnormals[verts1->lightnormalindex];
|
|
|
|
n2 = r_avertexnormals[verts2->lightnormalindex];
|
2004-03-10 08:14:38 +00:00
|
|
|
VectorBlend (n1, n2, blend, vo_v->normal);
|
2004-03-15 21:32:19 +00:00
|
|
|
if (VectorIsZero (vo_v->normal)) {
|
2004-03-10 08:14:38 +00:00
|
|
|
if (blend < 0.5) {
|
|
|
|
VectorCopy (n1, vo_v->normal);
|
|
|
|
} else {
|
|
|
|
VectorCopy (n2, vo_v->normal);
|
|
|
|
}
|
|
|
|
}
|
2002-01-07 03:46:56 +00:00
|
|
|
}
|
|
|
|
return vo;
|
2002-01-07 01:05:44 +00:00
|
|
|
}
|
2002-01-07 03:46:56 +00:00
|
|
|
} else {
|
|
|
|
verts += pose * count;
|
|
|
|
}
|
2002-08-12 06:14:55 +00:00
|
|
|
|
2004-03-10 08:14:38 +00:00
|
|
|
for (i = 0, vo_v = vo->verts; i < count; i++, vo_v++, verts++) {
|
2002-01-07 03:46:56 +00:00
|
|
|
VectorCopy (verts->v, vo_v->vert);
|
2004-03-10 08:14:38 +00:00
|
|
|
VectorCopy (r_avertexnormals[verts->lightnormalindex], vo_v->normal);
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|
|
|
|
return vo;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static maliasskindesc_t *
|
2001-11-21 08:14:05 +00:00
|
|
|
R_AliasGetSkindesc (int skinnum, aliashdr_t *ahdr)
|
|
|
|
{
|
|
|
|
maliasskindesc_t *pskindesc;
|
|
|
|
maliasskingroup_t *paliasskingroup;
|
|
|
|
|
|
|
|
if ((skinnum >= ahdr->mdl.numskins) || (skinnum < 0)) {
|
|
|
|
Con_DPrintf ("R_AliasSetupSkin: no such skin # %d\n", skinnum);
|
|
|
|
skinnum = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pskindesc = ((maliasskindesc_t *)
|
|
|
|
((byte *) ahdr + ahdr->skindesc)) + skinnum;
|
|
|
|
|
|
|
|
if (pskindesc->type == ALIAS_SKIN_GROUP) {
|
2004-02-27 08:51:26 +00:00
|
|
|
int numskins, i;
|
|
|
|
float fullskininterval, skintargettime, skintime;
|
2001-11-21 08:14:05 +00:00
|
|
|
float *pskinintervals;
|
|
|
|
|
|
|
|
paliasskingroup = (maliasskingroup_t *) ((byte *) ahdr +
|
|
|
|
pskindesc->skin);
|
|
|
|
pskinintervals = (float *)
|
|
|
|
((byte *) ahdr + paliasskingroup->intervals);
|
|
|
|
numskins = paliasskingroup->numskins;
|
|
|
|
fullskininterval = pskinintervals[numskins - 1];
|
|
|
|
|
|
|
|
skintime = r_realtime + currententity->syncbase;
|
|
|
|
|
|
|
|
skintargettime = skintime -
|
|
|
|
((int) (skintime / fullskininterval)) * fullskininterval;
|
|
|
|
for (i = 0; i < (numskins - 1); i++) {
|
|
|
|
if (pskinintervals[i] > skintargettime)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pskindesc = &paliasskingroup->skindescs[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return pskindesc;
|
|
|
|
}
|
|
|
|
|
2001-10-23 17:20:56 +00:00
|
|
|
void
|
2002-08-20 00:48:59 +00:00
|
|
|
R_DrawAliasModel (entity_t *e)
|
2001-10-23 17:20:56 +00:00
|
|
|
{
|
2004-03-10 08:14:38 +00:00
|
|
|
float radius, d;
|
|
|
|
float position[4] = {0.0, 0.0, 0.0, 1.0},
|
|
|
|
color[4] = {0.0, 0.0, 0.0, 1.0},
|
2004-03-15 21:32:19 +00:00
|
|
|
dark[4] = {0.0, 0.0, 0.0, 1.0},
|
2004-03-10 08:14:38 +00:00
|
|
|
emission[4] = {0.0, 0.0, 0.0, 1.0};
|
|
|
|
int gl_light, texture;
|
|
|
|
int fb_texture = 0, used_lights = 0;
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int lnum;
|
2001-10-23 17:20:56 +00:00
|
|
|
aliashdr_t *paliashdr;
|
2004-03-10 08:14:38 +00:00
|
|
|
dlight_t *l;
|
2002-08-19 04:15:46 +00:00
|
|
|
model_t *model;
|
2002-08-23 04:09:00 +00:00
|
|
|
vec3_t dist, scale;
|
2001-10-23 17:20:56 +00:00
|
|
|
vert_order_t *vo;
|
|
|
|
|
2002-08-19 04:15:46 +00:00
|
|
|
model = e->model;
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2002-08-23 04:09:00 +00:00
|
|
|
radius = model->radius;
|
|
|
|
if (e->scale != 1.0)
|
|
|
|
radius *= e->scale;
|
|
|
|
if (R_CullSphere (e->origin, radius))
|
2001-12-19 18:32:26 +00:00
|
|
|
return;
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2002-04-15 03:26:08 +00:00
|
|
|
VectorSubtract (r_origin, e->origin, modelorg);
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2004-03-10 08:14:38 +00:00
|
|
|
modelalpha = e->colormod[3];
|
|
|
|
|
2002-08-19 04:15:46 +00:00
|
|
|
if (!model->fullbright) {
|
2001-10-23 17:20:56 +00:00
|
|
|
// get lighting information
|
2002-08-14 05:45:50 +00:00
|
|
|
R_LightPoint (e->origin);
|
|
|
|
VectorScale (ambientcolor, 0.005, ambientcolor);
|
2002-08-12 06:14:55 +00:00
|
|
|
|
2004-03-10 08:14:38 +00:00
|
|
|
for (l = r_dlights, lnum = 0; lnum < r_maxdlights; lnum++, l++) {
|
|
|
|
if (l->die >= r_realtime) {
|
|
|
|
VectorSubtract (l->origin, e->origin, dist);
|
2004-03-15 21:32:19 +00:00
|
|
|
if ((d = DotProduct (dist, dist)) >
|
|
|
|
((l->radius + radius) * (l->radius + radius))) {
|
|
|
|
continue; // Out of range
|
2004-03-10 08:14:38 +00:00
|
|
|
}
|
2004-03-15 21:32:19 +00:00
|
|
|
if (d < (radius * radius * 0.25)) { // Inside the model
|
2004-03-10 08:14:38 +00:00
|
|
|
VectorMultAdd (emission, 1.5, l->color, emission);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (used_lights >= gl_max_lights) { // too many, use emission
|
|
|
|
VectorMultAdd (emission,
|
|
|
|
1.5 * (1 - (d / (l->radius * l->radius))),
|
|
|
|
l->color, emission);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
VectorCopy (l->origin, position);
|
|
|
|
|
2004-03-15 21:32:19 +00:00
|
|
|
VectorCopy (l->color, color);
|
2004-03-10 08:14:38 +00:00
|
|
|
color[3] = 1.0;
|
|
|
|
|
|
|
|
gl_light = GL_LIGHT0 + used_lights;
|
|
|
|
qfglEnable (gl_light);
|
|
|
|
qfglLightfv (gl_light, GL_POSITION, position);
|
2004-03-15 21:32:19 +00:00
|
|
|
qfglLightfv (gl_light, GL_AMBIENT, color);
|
2004-03-10 08:14:38 +00:00
|
|
|
qfglLightfv (gl_light, GL_DIFFUSE, color);
|
|
|
|
qfglLightfv (gl_light, GL_SPECULAR, color);
|
|
|
|
qfglLightf (gl_light, GL_QUADRATIC_ATTENUATION,
|
2004-03-15 21:32:19 +00:00
|
|
|
5.0 / (l->radius * l->radius));
|
2004-03-10 08:14:38 +00:00
|
|
|
used_lights++;
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-10 08:14:38 +00:00
|
|
|
VectorAdd (ambientcolor, emission, emission);
|
|
|
|
d = max (emission[0], max (emission[1], emission[2]));
|
2004-03-15 21:32:19 +00:00
|
|
|
if (d > 1.0) {
|
2004-03-10 08:14:38 +00:00
|
|
|
VectorScale (emission, 1.0 / d, emission);
|
2004-03-15 21:32:19 +00:00
|
|
|
} else if (d < model->min_light && !used_lights) {
|
|
|
|
ambientcolor[2] = ambientcolor[1] =
|
|
|
|
ambientcolor[0] = model->min_light;
|
|
|
|
}
|
|
|
|
|
2004-03-10 08:14:38 +00:00
|
|
|
qfglMaterialfv (GL_FRONT, GL_EMISSION, emission);
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// locate the proper data
|
2001-11-04 07:40:35 +00:00
|
|
|
paliashdr = Cache_Get (&e->model->cache);
|
2001-10-23 17:20:56 +00:00
|
|
|
c_alias_polys += paliashdr->mdl.numtris;
|
|
|
|
|
2002-01-02 19:23:09 +00:00
|
|
|
// if the model has a colorised/external skin, use it, otherwise use
|
|
|
|
// the skin embedded in the model data
|
2001-11-04 07:40:35 +00:00
|
|
|
if (e->skin && !gl_nocolors->int_val) {
|
|
|
|
skin_t *skin = e->skin;
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
texture = skin->texture;
|
|
|
|
if (gl_fb_models->int_val) {
|
|
|
|
fb_texture = skin->fb_texture;
|
|
|
|
}
|
2001-11-21 08:14:05 +00:00
|
|
|
} else {
|
|
|
|
maliasskindesc_t *skindesc;
|
|
|
|
|
|
|
|
skindesc = R_AliasGetSkindesc (e->skinnum, paliashdr);
|
|
|
|
texture = skindesc->texnum;
|
2002-08-19 04:15:46 +00:00
|
|
|
if (gl_fb_models->int_val && !model->fullbright)
|
2001-11-21 08:14:05 +00:00
|
|
|
fb_texture = skindesc->fb_texnum;
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|
|
|
|
|
2004-02-08 02:49:38 +00:00
|
|
|
if (paliashdr->mdl.ident == HEADER_MDL16) {
|
2003-04-03 23:09:43 +00:00
|
|
|
VectorScale (paliashdr->mdl.scale, e->scale / 256.0, scale);
|
2002-01-07 03:46:56 +00:00
|
|
|
vo = GL_GetAliasFrameVerts16 (e->frame, paliashdr, e);
|
2003-04-03 23:09:43 +00:00
|
|
|
} else {
|
|
|
|
VectorScale (paliashdr->mdl.scale, e->scale, scale);
|
2002-01-07 03:46:56 +00:00
|
|
|
vo = GL_GetAliasFrameVerts (e->frame, paliashdr, e);
|
2003-04-03 23:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setup the transform
|
|
|
|
qfglPushMatrix ();
|
|
|
|
R_RotateForEntity (e);
|
|
|
|
|
|
|
|
qfglTranslatef (paliashdr->mdl.scale_origin[0],
|
|
|
|
paliashdr->mdl.scale_origin[1],
|
|
|
|
paliashdr->mdl.scale_origin[2]);
|
|
|
|
qfglScalef (scale[0], scale[1], scale[2]);
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2002-06-05 06:46:21 +00:00
|
|
|
if (modelalpha < 1.0)
|
2002-01-02 19:23:09 +00:00
|
|
|
qfglDepthMask (GL_FALSE);
|
2004-03-10 08:14:38 +00:00
|
|
|
qfglColor4fv (e->colormod);
|
2002-01-02 19:23:09 +00:00
|
|
|
|
2003-04-03 23:09:43 +00:00
|
|
|
// draw all the triangles
|
2002-08-19 04:15:46 +00:00
|
|
|
if (model->fullbright) {
|
2002-08-12 06:14:55 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, texture);
|
2004-03-15 21:32:19 +00:00
|
|
|
qfglDisable (GL_LIGHTING);
|
|
|
|
if (!tess)
|
|
|
|
qfglDisable (GL_NORMALIZE);
|
2003-04-08 04:13:49 +00:00
|
|
|
if (vo->tex_coord)
|
2004-03-10 08:14:38 +00:00
|
|
|
GL_DrawAliasFrameTri (vo);
|
2003-04-08 04:13:49 +00:00
|
|
|
else
|
2004-03-10 08:14:38 +00:00
|
|
|
GL_DrawAliasFrame (vo);
|
2004-03-15 21:32:19 +00:00
|
|
|
if (!tess)
|
|
|
|
qfglEnable (GL_NORMALIZE);
|
|
|
|
qfglEnable (GL_LIGHTING);
|
2002-08-12 06:14:55 +00:00
|
|
|
} else if (!fb_texture) {
|
|
|
|
// Model has no fullbrights, don't bother with multi
|
2002-04-16 16:51:35 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, texture);
|
2003-04-08 04:13:49 +00:00
|
|
|
if (vo->tex_coord)
|
|
|
|
GL_DrawAliasFrameTri (vo);
|
|
|
|
else
|
|
|
|
GL_DrawAliasFrame (vo);
|
2002-04-16 16:51:35 +00:00
|
|
|
} else { // try multitexture
|
2004-02-24 20:50:55 +00:00
|
|
|
if (gl_mtex_active_tmus >= 2) { // set up the textures
|
2002-04-16 16:51:35 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, texture);
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2002-04-16 16:51:35 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
2004-02-21 05:36:19 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, fb_texture);
|
2002-04-16 16:51:35 +00:00
|
|
|
|
2003-04-08 04:13:49 +00:00
|
|
|
// do the heavy lifting
|
|
|
|
if (vo->tex_coord)
|
|
|
|
GL_DrawAliasFrameTriMulti (vo);
|
2004-02-21 05:36:19 +00:00
|
|
|
else
|
2003-04-08 04:13:49 +00:00
|
|
|
GL_DrawAliasFrameMulti (vo);
|
2002-04-16 16:51:35 +00:00
|
|
|
|
|
|
|
// restore the settings
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
} else {
|
2003-04-08 04:13:49 +00:00
|
|
|
if (vo->tex_coord) {
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, texture);
|
|
|
|
GL_DrawAliasFrameTri (vo);
|
2004-03-10 08:14:38 +00:00
|
|
|
|
|
|
|
qfglDisable (GL_LIGHTING);
|
|
|
|
if (!tess)
|
|
|
|
qfglDisable (GL_NORMALIZE);
|
2003-04-08 04:13:49 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, fb_texture);
|
2004-03-10 08:14:38 +00:00
|
|
|
GL_DrawAliasFrameTri (vo);
|
2004-03-15 21:32:19 +00:00
|
|
|
if (!tess)
|
|
|
|
qfglEnable (GL_NORMALIZE);
|
|
|
|
qfglEnable (GL_LIGHTING);
|
2003-04-08 04:13:49 +00:00
|
|
|
} else {
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, texture);
|
|
|
|
GL_DrawAliasFrame (vo);
|
2004-03-10 08:14:38 +00:00
|
|
|
|
|
|
|
qfglDisable (GL_LIGHTING);
|
|
|
|
if (!tess)
|
|
|
|
qfglDisable (GL_NORMALIZE);
|
2003-04-08 04:13:49 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, fb_texture);
|
2004-03-10 08:14:38 +00:00
|
|
|
GL_DrawAliasFrame (vo);
|
2004-03-15 21:32:19 +00:00
|
|
|
if (!tess)
|
|
|
|
qfglEnable (GL_NORMALIZE);
|
|
|
|
qfglEnable (GL_LIGHTING);
|
2003-04-08 04:13:49 +00:00
|
|
|
}
|
2002-04-16 16:51:35 +00:00
|
|
|
}
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qfglPopMatrix ();
|
|
|
|
|
2001-12-19 18:32:26 +00:00
|
|
|
// torches, grenades, and lightning bolts do not have shadows
|
2002-08-19 04:15:46 +00:00
|
|
|
if (r_shadows->int_val && model->shadow_alpha) {
|
2001-10-23 17:20:56 +00:00
|
|
|
qfglPushMatrix ();
|
|
|
|
R_RotateForEntity (e);
|
|
|
|
|
2004-03-15 21:32:19 +00:00
|
|
|
if (!tess)
|
|
|
|
qfglDisable (GL_NORMALIZE);
|
|
|
|
qfglDisable (GL_LIGHTING);
|
2001-10-23 17:20:56 +00:00
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
2002-06-14 04:14:52 +00:00
|
|
|
qfglDepthMask (GL_FALSE);
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2004-03-15 21:32:19 +00:00
|
|
|
if (modelalpha < 1.0) {
|
|
|
|
VectorBlend (e->colormod, dark, 0.5, color);
|
|
|
|
color[3] = modelalpha * (model->shadow_alpha / 255.0);
|
|
|
|
qfglColor4fv (color);
|
|
|
|
} else {
|
|
|
|
color_black[3] = model->shadow_alpha;
|
|
|
|
qfglColor4ubv (color_black);
|
|
|
|
}
|
2001-12-30 04:16:25 +00:00
|
|
|
GL_DrawAliasShadow (paliashdr, vo);
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2002-06-14 04:14:52 +00:00
|
|
|
qfglDepthMask (GL_TRUE);
|
2001-10-23 17:20:56 +00:00
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
2004-03-15 21:32:19 +00:00
|
|
|
qfglEnable (GL_LIGHTING);
|
|
|
|
if (!tess)
|
|
|
|
qfglEnable (GL_NORMALIZE);
|
2001-10-23 17:20:56 +00:00
|
|
|
qfglPopMatrix ();
|
2004-02-21 05:36:19 +00:00
|
|
|
} else if (modelalpha < 1.0) {
|
2002-06-14 04:14:52 +00:00
|
|
|
qfglDepthMask (GL_TRUE);
|
2004-02-21 05:36:19 +00:00
|
|
|
}
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2004-03-10 08:14:38 +00:00
|
|
|
while (used_lights--) {
|
|
|
|
qfglDisable (GL_LIGHT0 + used_lights);
|
|
|
|
}
|
|
|
|
|
2001-11-04 07:40:35 +00:00
|
|
|
Cache_Release (&e->model->cache);
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|