2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
gl_part.c
|
|
|
|
|
|
|
|
OpenGL particle rendering
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "r_shared.h"
|
|
|
|
#include "r_local.h"
|
|
|
|
#include "glquake.h"
|
|
|
|
#include "server.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cmd.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
#define MAX_FIRES 128 // rocket flames
|
|
|
|
fire_t r_fires[MAX_FIRES];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_DrawParticles
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_DrawParticles (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
particle_t *p, *kill;
|
|
|
|
float grav;
|
|
|
|
int i;
|
|
|
|
float time2, time3;
|
|
|
|
float time1;
|
|
|
|
float dvel;
|
|
|
|
float frametime;
|
|
|
|
|
|
|
|
vec3_t up, right;
|
|
|
|
float scale;
|
|
|
|
|
|
|
|
unsigned char *at;
|
|
|
|
unsigned char theAlpha;
|
|
|
|
qboolean alphaTestEnabled;
|
|
|
|
qboolean blendEnabled;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
glBindTexture (GL_TEXTURE_2D, particletexture);
|
|
|
|
// LordHavoc: particles should not affect zbuffer
|
|
|
|
glDepthMask (0);
|
|
|
|
|
|
|
|
if (!(blendEnabled = glIsEnabled (GL_BLEND))) {
|
|
|
|
glEnable (GL_BLEND);
|
|
|
|
}
|
|
|
|
if ((alphaTestEnabled = glIsEnabled (GL_ALPHA_TEST))) {
|
|
|
|
glDisable (GL_ALPHA_TEST);
|
|
|
|
}
|
|
|
|
glBegin (GL_TRIANGLES);
|
|
|
|
|
|
|
|
VectorScale (vup, 1.5, up);
|
|
|
|
VectorScale (vright, 1.5, right);
|
|
|
|
|
|
|
|
frametime = cl.time - cl.oldtime;
|
|
|
|
time3 = frametime * 15;
|
2001-02-26 06:48:02 +00:00
|
|
|
time2 = frametime * 10; // 15;
|
2001-02-19 21:15:25 +00:00
|
|
|
time1 = frametime * 5;
|
|
|
|
grav = frametime * sv_gravity->value * 0.05;
|
|
|
|
dvel = frametime * 4;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2001-02-19 21:15:25 +00:00
|
|
|
kill = active_particles;
|
2001-02-26 06:48:02 +00:00
|
|
|
if (kill && kill->die < cl.time) {
|
2001-02-19 21:15:25 +00:00
|
|
|
active_particles = kill->next;
|
|
|
|
kill->next = free_particles;
|
|
|
|
free_particles = kill;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (p = active_particles; p; p = p->next) {
|
|
|
|
for (;;) {
|
2001-02-19 21:15:25 +00:00
|
|
|
kill = p->next;
|
2001-02-26 06:48:02 +00:00
|
|
|
if (kill && kill->die < cl.time) {
|
2001-02-19 21:15:25 +00:00
|
|
|
p->next = kill->next;
|
|
|
|
kill->next = free_particles;
|
|
|
|
free_particles = kill;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hack a scale up to keep particles from disapearing
|
2001-02-26 06:48:02 +00:00
|
|
|
scale =
|
|
|
|
(p->org[0] - r_origin[0]) * vpn[0] + (p->org[1] -
|
|
|
|
r_origin[1]) * vpn[1] +
|
|
|
|
(p->org[2] - r_origin[2]) * vpn[2];
|
2001-02-19 21:15:25 +00:00
|
|
|
if (scale < 20)
|
|
|
|
scale = 1;
|
|
|
|
else
|
|
|
|
scale = 1 + scale * 0.004;
|
2001-02-26 06:48:02 +00:00
|
|
|
at = (byte *) & d_8to24table[(int) p->color];
|
|
|
|
if (p->type == pt_fire)
|
|
|
|
theAlpha = 255 * (6 - p->ramp) / 6;
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
|
|
|
theAlpha = 255;
|
|
|
|
if (lighthalf)
|
2001-02-26 06:48:02 +00:00
|
|
|
glColor4ub ((byte) ((int) at[0] >> 1), (byte) ((int) at[1] >> 1),
|
|
|
|
(byte) ((int) at[2] >> 1), theAlpha);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
glColor4ub (at[0], at[1], at[2], theAlpha);
|
|
|
|
glTexCoord2f (0, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
glVertex3fv (p->org);
|
2001-02-26 06:48:02 +00:00
|
|
|
glTexCoord2f (1, 0);
|
|
|
|
glVertex3f (p->org[0] + up[0] * scale, p->org[1] + up[1] * scale,
|
|
|
|
p->org[2] + up[2] * scale);
|
|
|
|
glTexCoord2f (0, 1);
|
|
|
|
glVertex3f (p->org[0] + right[0] * scale, p->org[1] + right[1] * scale,
|
|
|
|
p->org[2] + right[2] * scale);
|
|
|
|
|
|
|
|
p->org[0] += p->vel[0] * frametime;
|
|
|
|
p->org[1] += p->vel[1] * frametime;
|
|
|
|
p->org[2] += p->vel[2] * frametime;
|
|
|
|
|
|
|
|
switch (p->type) {
|
|
|
|
case pt_static:
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-02-26 06:48:02 +00:00
|
|
|
case pt_fire:
|
2001-02-19 21:15:25 +00:00
|
|
|
p->ramp += time1;
|
|
|
|
if (p->ramp >= 6)
|
|
|
|
p->die = -1;
|
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
p->color = ramp3[(int) p->ramp];
|
2001-02-19 21:15:25 +00:00
|
|
|
p->vel[2] += grav;
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case pt_explode:
|
2001-02-19 21:15:25 +00:00
|
|
|
p->ramp += time2;
|
2001-02-26 06:48:02 +00:00
|
|
|
if (p->ramp >= 8)
|
2001-02-19 21:15:25 +00:00
|
|
|
p->die = -1;
|
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
p->color = ramp1[(int) p->ramp];
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
p->vel[i] += p->vel[i] * dvel;
|
2001-02-19 21:15:25 +00:00
|
|
|
p->vel[2] -= grav;
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case pt_explode2:
|
2001-02-19 21:15:25 +00:00
|
|
|
p->ramp += time3;
|
2001-02-26 06:48:02 +00:00
|
|
|
if (p->ramp >= 8)
|
2001-02-19 21:15:25 +00:00
|
|
|
p->die = -1;
|
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
p->color = ramp2[(int) p->ramp];
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
p->vel[i] -= p->vel[i] * frametime;
|
2001-02-19 21:15:25 +00:00
|
|
|
p->vel[2] -= grav;
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case pt_blob:
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
p->vel[i] += p->vel[i] * dvel;
|
2001-02-19 21:15:25 +00:00
|
|
|
p->vel[2] -= grav;
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case pt_blob2:
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
p->vel[i] -= p->vel[i] * dvel;
|
2001-02-19 21:15:25 +00:00
|
|
|
p->vel[2] -= grav;
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case pt_grav:
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef QUAKE2
|
|
|
|
p->vel[2] -= grav * 20;
|
|
|
|
break;
|
|
|
|
#endif
|
2001-02-26 06:48:02 +00:00
|
|
|
case pt_slowgrav:
|
2001-02-19 21:15:25 +00:00
|
|
|
p->vel[2] -= grav;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
glEnd ();
|
|
|
|
if (alphaTestEnabled) {
|
|
|
|
glEnable (GL_ALPHA_TEST);
|
|
|
|
}
|
|
|
|
if (!blendEnabled) {
|
|
|
|
glDisable (GL_BLEND);
|
|
|
|
}
|
|
|
|
glDepthMask (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
R_AddFire
|
|
|
|
|
|
|
|
Nifty ball of fire GL effect. Kinda a meshing of the dlight and
|
|
|
|
particle engine code.
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
float r_firecolor_flame[3] = { 0.9, 0.7, 0.3 };
|
|
|
|
float r_firecolor_light[3] = { 0.9, 0.7, 0.3 };
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
R_AddFire (vec3_t start, vec3_t end, entity_t *ent)
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
float len;
|
|
|
|
fire_t *f;
|
|
|
|
dlight_t *dl;
|
|
|
|
vec3_t vec;
|
|
|
|
int key;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!gl_fires->int_val)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VectorSubtract (end, start, vec);
|
|
|
|
len = VectorNormalize (vec);
|
2001-02-26 06:48:02 +00:00
|
|
|
key = ent - cl_entities + 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (len) {
|
2001-02-19 21:15:25 +00:00
|
|
|
f = R_AllocFire (key);
|
|
|
|
VectorCopy (end, f->origin);
|
|
|
|
VectorCopy (start, f->owner);
|
2001-02-20 23:36:50 +00:00
|
|
|
f->size = 10;
|
2001-02-19 21:15:25 +00:00
|
|
|
f->die = cl.time + 0.5;
|
2001-02-20 23:36:50 +00:00
|
|
|
f->decay = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
f->color = r_firecolor_flame;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
dl = CL_AllocDlight (key);
|
|
|
|
VectorCopy (end, dl->origin);
|
|
|
|
dl->radius = 200;
|
|
|
|
dl->die = cl.time + 0.5;
|
2001-02-26 06:48:02 +00:00
|
|
|
dl->color = r_firecolor_light;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
R_AllocFire
|
|
|
|
|
|
|
|
Clears out and returns a new fireball
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
fire_t *
|
2001-02-19 21:15:25 +00:00
|
|
|
R_AllocFire (int key)
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
fire_t *f;
|
|
|
|
|
|
|
|
if (key) // first try to find/reuse a keyed
|
|
|
|
// spot
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
f = r_fires;
|
|
|
|
for (i = 0; i < MAX_FIRES; i++, f++)
|
2001-02-26 06:48:02 +00:00
|
|
|
if (f->key == key) {
|
|
|
|
memset (f, 0, sizeof (*f));
|
2001-02-19 21:15:25 +00:00
|
|
|
f->key = key;
|
|
|
|
f->color = f->_color;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
f = r_fires; // no match, look for a free spot
|
|
|
|
for (i = 0; i < MAX_FIRES; i++, f++) {
|
|
|
|
if (f->die < cl.time) {
|
|
|
|
memset (f, 0, sizeof (*f));
|
2001-02-19 21:15:25 +00:00
|
|
|
f->key = key;
|
|
|
|
f->color = f->_color;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f = &r_fires[0];
|
2001-02-26 06:48:02 +00:00
|
|
|
memset (f, 0, sizeof (*f));
|
2001-02-19 21:15:25 +00:00
|
|
|
f->key = key;
|
|
|
|
f->color = f->_color;
|
2001-02-26 06:48:02 +00:00
|
|
|
return f;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
R_DrawFire
|
|
|
|
|
|
|
|
draws one fireball - probably never need to call this directly
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
R_DrawFire (fire_t *f)
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, j;
|
|
|
|
vec3_t vec, vec2;
|
|
|
|
float radius;
|
|
|
|
float *b_sin, *b_cos;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
b_sin = bubble_sintable;
|
|
|
|
b_cos = bubble_costable;
|
|
|
|
|
2001-02-20 23:36:50 +00:00
|
|
|
radius = f->size - 0.5;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// figure out if we're inside the area of effect
|
|
|
|
VectorSubtract (f->origin, r_origin, vec);
|
2001-02-26 06:48:02 +00:00
|
|
|
if (Length (vec) < radius) {
|
2001-02-19 21:15:25 +00:00
|
|
|
AddLightBlend (1, 0.5, 0, f->size * 0.0003); // we are
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// we're not - draw it
|
|
|
|
glBegin (GL_TRIANGLE_FAN);
|
|
|
|
if (lighthalf)
|
2001-02-26 06:48:02 +00:00
|
|
|
glColor3f (f->color[0] * 0.5, f->color[1] * 0.5, f->color[2] * 0.5);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
glColor3fv (f->color);
|
|
|
|
for (i = 0; i < 3; i++)
|
2001-02-19 21:15:25 +00:00
|
|
|
vec[i] = f->origin[i] - vpn[i] * radius;
|
|
|
|
glVertex3fv (vec);
|
|
|
|
glColor3f (0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
// don't panic, this just draws a bubble...
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 16; i >= 0; i--) {
|
|
|
|
for (j = 0; j < 3; j++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
vec[j] = f->origin[j] + (*b_cos * vright[j]
|
2001-02-26 06:48:02 +00:00
|
|
|
+ vup[j] * (*b_sin)) * radius;
|
2001-02-19 21:15:25 +00:00
|
|
|
vec2[j] = f->owner[j] + (*b_cos * vright[j]
|
2001-02-26 06:48:02 +00:00
|
|
|
+ vup[j] * (*b_sin)) * radius;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
glVertex3fv (vec);
|
|
|
|
glVertex3fv (vec2);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
b_sin += 2;
|
|
|
|
b_cos += 2;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
glEnd ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
R_UpdateFires
|
|
|
|
|
|
|
|
Draws each fireball in sequence
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
R_UpdateFires (void)
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
fire_t *f;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!gl_fires->int_val)
|
|
|
|
return;
|
|
|
|
|
|
|
|
glDepthMask (0);
|
|
|
|
glDisable (GL_TEXTURE_2D);
|
|
|
|
glShadeModel (GL_SMOOTH);
|
|
|
|
glEnable (GL_BLEND);
|
|
|
|
glBlendFunc (GL_ONE, GL_ONE);
|
|
|
|
|
|
|
|
f = r_fires;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < MAX_FIRES; i++, f++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (f->die < cl.time || !f->size)
|
|
|
|
continue;
|
|
|
|
f->size += f->decay;
|
|
|
|
R_DrawFire (f);
|
|
|
|
}
|
|
|
|
|
|
|
|
glColor3f (1.0, 1.0, 1.0);
|
|
|
|
glDisable (GL_BLEND);
|
|
|
|
glEnable (GL_TEXTURE_2D);
|
|
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glDepthMask (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
R_FireColor_f (void)
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (Cmd_Argc () == 1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Con_Printf ("r_firecolor %f %f %f\n",
|
|
|
|
r_firecolor_flame[0],
|
2001-02-26 06:48:02 +00:00
|
|
|
r_firecolor_flame[1], r_firecolor_flame[2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
if (Cmd_Argc () == 5 || Cmd_Argc () == 6) {
|
|
|
|
Con_Printf
|
|
|
|
("Warning: obsolete 4th and 5th parameters to r_firecolor ignored\n");
|
|
|
|
} else if (Cmd_Argc () != 4) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Con_Printf ("Usage r_firecolor R G B\n");
|
|
|
|
return;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
r_firecolor_flame[i] = atof (Cmd_Argv (i + 1));
|
|
|
|
r_firecolor_light[i] = r_firecolor_flame[i];
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|