2001-12-31 16:16:59 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
2001-12-31 16:28:42 +00:00
|
|
|
// $Log$
|
2002-12-02 19:52:05 +00:00
|
|
|
// Revision 1.21 2002/12/02 19:52:05 niceass
|
|
|
|
// water pressure & shell ejection stuff
|
|
|
|
//
|
2002-08-25 07:09:20 +00:00
|
|
|
// Revision 1.20 2002/08/25 07:08:18 niceass
|
|
|
|
// added "life" setting to func_pressure
|
|
|
|
//
|
2002-07-02 07:24:56 +00:00
|
|
|
// Revision 1.19 2002/07/02 07:22:10 niceass
|
|
|
|
// kill pressures at LCA
|
|
|
|
//
|
2002-06-16 20:06:15 +00:00
|
|
|
// Revision 1.18 2002/06/16 20:06:13 jbravo
|
|
|
|
// Reindented all the source files with "indent -kr -ut -i8 -l120 -lc120 -sob -bad -bap"
|
|
|
|
//
|
2002-06-16 19:12:52 +00:00
|
|
|
// Revision 1.17 2002/06/16 19:12:52 jbravo
|
|
|
|
// Removed the MISSIONPACK ifdefs and missionpack only code.
|
|
|
|
//
|
2002-06-09 05:16:58 +00:00
|
|
|
// Revision 1.16 2002/06/09 05:15:40 niceass
|
|
|
|
// pressure change
|
|
|
|
//
|
2002-06-06 01:54:26 +00:00
|
|
|
// Revision 1.15 2002/06/06 01:54:07 niceass
|
|
|
|
// pressure change
|
|
|
|
//
|
2002-05-26 05:14:14 +00:00
|
|
|
// Revision 1.14 2002/05/26 05:14:14 niceass
|
|
|
|
// pressure stuff
|
|
|
|
//
|
2002-05-18 03:55:35 +00:00
|
|
|
// Revision 1.13 2002/05/18 03:55:35 niceass
|
|
|
|
// many misc. changes
|
|
|
|
//
|
2002-05-09 06:45:14 +00:00
|
|
|
// Revision 1.12 2002/05/09 06:42:06 niceass
|
|
|
|
// New tracers
|
|
|
|
//
|
2002-04-29 06:11:56 +00:00
|
|
|
// Revision 1.11 2002/04/29 06:11:56 niceass
|
|
|
|
// pressure stuff
|
|
|
|
//
|
2002-04-23 06:09:18 +00:00
|
|
|
// Revision 1.10 2002/04/23 06:07:23 niceass
|
|
|
|
// pressure stuff
|
|
|
|
//
|
2002-03-31 02:02:15 +00:00
|
|
|
// Revision 1.9 2002/03/31 02:02:15 niceass
|
|
|
|
// more random shell bouncing
|
|
|
|
//
|
2002-03-16 21:50:09 +00:00
|
|
|
// Revision 1.8 2002/03/16 21:49:45 niceass
|
|
|
|
// All new shell ejection code
|
|
|
|
//
|
2002-01-14 01:19:23 +00:00
|
|
|
// Revision 1.7 2002/01/14 01:19:23 niceass
|
|
|
|
// No more default 800 gravity on items - NiceAss
|
|
|
|
//
|
2002-01-11 19:48:33 +00:00
|
|
|
// Revision 1.6 2002/01/11 19:48:29 jbravo
|
|
|
|
// Formatted the source in non DOS format.
|
|
|
|
//
|
2001-12-31 16:28:42 +00:00
|
|
|
// Revision 1.5 2001/12/31 16:28:41 jbravo
|
|
|
|
// I made a Booboo with the Log tag.
|
|
|
|
//
|
2001-12-31 16:16:59 +00:00
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
2001-05-06 20:50:27 +00:00
|
|
|
// Copyright (C) 1999-2000 Id Software, Inc.
|
|
|
|
//
|
|
|
|
|
|
|
|
// cg_localents.c -- every frame, generate renderer commands for locally
|
|
|
|
// processed entities, like smoke puffs, gibs, shells, etc.
|
|
|
|
|
|
|
|
#include "cg_local.h"
|
|
|
|
|
|
|
|
#define MAX_LOCAL_ENTITIES 512
|
2002-06-16 20:06:15 +00:00
|
|
|
localEntity_t cg_localEntities[MAX_LOCAL_ENTITIES];
|
|
|
|
localEntity_t cg_activeLocalEntities; // double linked list
|
|
|
|
localEntity_t *cg_freeLocalEntities; // single linked list
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
CG_InitLocalEntities
|
|
|
|
|
|
|
|
This is called at startup and for tournement restarts
|
|
|
|
===================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_InitLocalEntities(void)
|
|
|
|
{
|
|
|
|
int i;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
memset(cg_localEntities, 0, sizeof(cg_localEntities));
|
2001-05-06 20:50:27 +00:00
|
|
|
cg_activeLocalEntities.next = &cg_activeLocalEntities;
|
|
|
|
cg_activeLocalEntities.prev = &cg_activeLocalEntities;
|
|
|
|
cg_freeLocalEntities = cg_localEntities;
|
2002-06-16 20:06:15 +00:00
|
|
|
for (i = 0; i < MAX_LOCAL_ENTITIES - 1; i++) {
|
|
|
|
cg_localEntities[i].next = &cg_localEntities[i + 1];
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
CG_FreeLocalEntity
|
|
|
|
==================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_FreeLocalEntity(localEntity_t * le)
|
|
|
|
{
|
|
|
|
if (!le->prev) {
|
|
|
|
CG_Error("CG_FreeLocalEntity: not active");
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
// remove from the doubly linked active list
|
|
|
|
le->prev->next = le->next;
|
|
|
|
le->next->prev = le->prev;
|
|
|
|
|
|
|
|
// the free list is only singly linked
|
|
|
|
le->next = cg_freeLocalEntities;
|
|
|
|
cg_freeLocalEntities = le;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
CG_AllocLocalEntity
|
|
|
|
|
|
|
|
Will allways succeed, even if it requires freeing an old active entity
|
|
|
|
===================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
localEntity_t *CG_AllocLocalEntity(void)
|
|
|
|
{
|
|
|
|
localEntity_t *le;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
if (!cg_freeLocalEntities) {
|
2001-05-06 20:50:27 +00:00
|
|
|
// no free entities, so free the one at the end of the chain
|
|
|
|
// remove the oldest active entity
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_FreeLocalEntity(cg_activeLocalEntities.prev);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
le = cg_freeLocalEntities;
|
|
|
|
cg_freeLocalEntities = cg_freeLocalEntities->next;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
memset(le, 0, sizeof(*le));
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
// link into the active list
|
|
|
|
le->next = cg_activeLocalEntities.next;
|
|
|
|
le->prev = &cg_activeLocalEntities;
|
|
|
|
cg_activeLocalEntities.next->prev = le;
|
|
|
|
cg_activeLocalEntities.next = le;
|
|
|
|
return le;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================================================================================
|
|
|
|
|
|
|
|
FRAGMENT PROCESSING
|
|
|
|
|
|
|
|
A fragment localentity interacts with the environment in some way (hitting walls),
|
|
|
|
or generates more localentities along a trail.
|
|
|
|
|
|
|
|
====================================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
CG_BloodTrail
|
|
|
|
|
|
|
|
Leave expanding blood puffs behind gibs
|
|
|
|
================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_BloodTrail(localEntity_t * le)
|
|
|
|
{
|
|
|
|
int t;
|
|
|
|
int t2;
|
|
|
|
int step;
|
|
|
|
vec3_t newOrigin;
|
|
|
|
localEntity_t *blood;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
step = 150;
|
2002-06-16 20:06:15 +00:00
|
|
|
t = step * ((cg.time - cg.frametime + step) / step);
|
|
|
|
t2 = step * (cg.time / step);
|
|
|
|
|
|
|
|
for (; t <= t2; t += step) {
|
|
|
|
CG_EvaluateTrajectory(&le->pos, t, newOrigin);
|
|
|
|
|
|
|
|
blood = CG_SmokePuff(newOrigin, vec3_origin, 20, // radius
|
|
|
|
1, 1, 1, 1, // color
|
|
|
|
2000, // trailTime
|
|
|
|
t, // startTime
|
|
|
|
0, // fadeInTime
|
|
|
|
0, // flags
|
|
|
|
cgs.media.bloodTrailShader);
|
2001-05-06 20:50:27 +00:00
|
|
|
// use the optimized version
|
|
|
|
blood->leType = LE_FALL_SCALE_FADE;
|
|
|
|
// drop a total of 40 units over its lifetime
|
|
|
|
blood->pos.trDelta[2] = 40;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
CG_FragmentBounceMark
|
|
|
|
================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_FragmentBounceMark(localEntity_t * le, trace_t * trace)
|
|
|
|
{
|
|
|
|
int radius;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
if (le->leMarkType == LEMT_BLOOD) {
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
radius = 16 + (rand() & 31);
|
|
|
|
CG_ImpactMark(cgs.media.bloodMarkShader, trace->endpos, trace->plane.normal, random() * 360,
|
|
|
|
1, 1, 1, 1, qtrue, radius, qfalse);
|
|
|
|
} else if (le->leMarkType == LEMT_BURN) {
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
radius = 8 + (rand() & 15);
|
|
|
|
CG_ImpactMark(cgs.media.burnMarkShader, trace->endpos, trace->plane.normal, random() * 360,
|
|
|
|
1, 1, 1, 1, qtrue, radius, qfalse);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// don't allow a fragment to make multiple marks, or they
|
|
|
|
// pile up while settling
|
|
|
|
le->leMarkType = LEMT_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
CG_FragmentBounceSound
|
|
|
|
================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_FragmentBounceSound(localEntity_t * le, trace_t * trace)
|
|
|
|
{
|
|
|
|
if (le->leBounceSoundType == LEBS_BLOOD) {
|
2001-05-06 20:50:27 +00:00
|
|
|
// half the gibs will make splat sounds
|
2002-06-16 20:06:15 +00:00
|
|
|
if (rand() & 1) {
|
|
|
|
int r = rand() & 3;
|
|
|
|
sfxHandle_t s;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
if (r == 0) {
|
2001-05-06 20:50:27 +00:00
|
|
|
s = cgs.media.gibBounce1Sound;
|
2002-06-16 20:06:15 +00:00
|
|
|
} else if (r == 1) {
|
2001-05-06 20:50:27 +00:00
|
|
|
s = cgs.media.gibBounce2Sound;
|
|
|
|
} else {
|
|
|
|
s = cgs.media.gibBounce3Sound;
|
|
|
|
}
|
2002-06-16 20:06:15 +00:00
|
|
|
trap_S_StartSound(trace->endpos, ENTITYNUM_WORLD, CHAN_AUTO, s);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
2002-06-16 20:06:15 +00:00
|
|
|
} else if (le->leBounceSoundType == LEBS_BRASS) {
|
2001-11-08 02:37:11 +00:00
|
|
|
// Elder: play bounce sound
|
2002-06-16 20:06:15 +00:00
|
|
|
trap_S_StartSound(trace->endpos, ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.sfx_shelltumble);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
// don't allow a fragment to make multiple bounce sounds,
|
|
|
|
// or it gets too noisy as they settle
|
|
|
|
le->leBounceSoundType = LEBS_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
CG_ReflectVelocity
|
|
|
|
================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_ReflectVelocity(localEntity_t * le, trace_t * trace)
|
|
|
|
{
|
|
|
|
vec3_t velocity, normal;
|
|
|
|
float dot;
|
|
|
|
int hitTime;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-05-26 05:14:14 +00:00
|
|
|
// NiceAss: Make the reflection less perfect (for brass)
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorCopy(trace->plane.normal, normal);
|
2002-03-31 02:02:15 +00:00
|
|
|
|
2002-03-16 21:50:09 +00:00
|
|
|
if (le->leFlags == LEF_TUMBLE) {
|
2002-03-31 02:02:15 +00:00
|
|
|
normal[0] += crandom() * 0.15;
|
|
|
|
normal[1] += crandom() * 0.15;
|
|
|
|
normal[2] += crandom() * 0.15;
|
2002-03-16 21:50:09 +00:00
|
|
|
VectorNormalize(normal);
|
|
|
|
}
|
2001-05-06 20:50:27 +00:00
|
|
|
// reflect the velocity on the trace plane
|
|
|
|
hitTime = cg.time - cg.frametime + cg.frametime * trace->fraction;
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_LE_EvaluateTrajectoryDelta(&le->pos, hitTime, velocity);
|
|
|
|
dot = DotProduct(velocity, normal);
|
|
|
|
VectorMA(velocity, -2 * dot, normal, le->pos.trDelta);
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorScale(le->pos.trDelta, le->bounceFactor, le->pos.trDelta);
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorCopy(trace->endpos, le->pos.trBase);
|
2001-05-06 20:50:27 +00:00
|
|
|
le->pos.trTime = cg.time;
|
|
|
|
|
|
|
|
// check for stop, making sure that even on low FPS systems it doesn't bobble
|
2002-06-16 20:06:15 +00:00
|
|
|
if (trace->allsolid || VectorLength(le->pos.trDelta) < 30.0) {
|
2002-12-02 19:52:05 +00:00
|
|
|
// NiceAss: I don't know what this crap is, but it didn't work too well on sloped surfaces
|
2002-03-16 21:50:09 +00:00
|
|
|
/*( trace->plane.normal[2] > 0 &&
|
2002-06-16 20:06:15 +00:00
|
|
|
( le->pos.trDelta[2] < 40 || le->pos.trDelta[2] < -cg.frametime * le->pos.trDelta[2] ) ) ) {
|
|
|
|
*/
|
2001-05-06 20:50:27 +00:00
|
|
|
le->pos.trType = TR_STATIONARY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
CG_AddFragment
|
|
|
|
================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_AddFragment(localEntity_t * le)
|
|
|
|
{
|
|
|
|
vec3_t newOrigin;
|
|
|
|
trace_t trace;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
if (le->pos.trType == TR_STATIONARY) {
|
2001-05-06 20:50:27 +00:00
|
|
|
// sink into the ground if near the removal time
|
2002-06-16 20:06:15 +00:00
|
|
|
int t;
|
|
|
|
float oldZ;
|
|
|
|
|
2001-05-06 20:50:27 +00:00
|
|
|
t = le->endTime - cg.time;
|
2002-06-16 20:06:15 +00:00
|
|
|
if (t < SINK_TIME) {
|
2001-05-06 20:50:27 +00:00
|
|
|
// we must use an explicit lighting origin, otherwise the
|
|
|
|
// lighting would be lost as soon as the origin went
|
|
|
|
// into the ground
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorCopy(le->refEntity.origin, le->refEntity.lightingOrigin);
|
2001-05-06 20:50:27 +00:00
|
|
|
le->refEntity.renderfx |= RF_LIGHTING_ORIGIN;
|
|
|
|
oldZ = le->refEntity.origin[2];
|
2002-06-16 20:06:15 +00:00
|
|
|
le->refEntity.origin[2] -= 16 * (1.0 - (float) t / SINK_TIME);
|
|
|
|
trap_R_AddRefEntityToScene(&le->refEntity);
|
2001-05-06 20:50:27 +00:00
|
|
|
le->refEntity.origin[2] = oldZ;
|
|
|
|
} else {
|
2002-06-16 20:06:15 +00:00
|
|
|
trap_R_AddRefEntityToScene(&le->refEntity);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// calculate new position
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_LE_EvaluateTrajectory(&le->pos, cg.time, newOrigin);
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
// trace a line from previous position to new position
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_Trace(&trace, le->refEntity.origin, NULL, NULL, newOrigin, -1, CONTENTS_SOLID);
|
|
|
|
if (trace.fraction == 1.0) {
|
2001-05-06 20:50:27 +00:00
|
|
|
// still in free fall
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorCopy(newOrigin, le->refEntity.origin);
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
if (le->leFlags & LEF_TUMBLE) {
|
2001-05-06 20:50:27 +00:00
|
|
|
vec3_t angles;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_LE_EvaluateTrajectory(&le->angles, cg.time, angles);
|
|
|
|
AnglesToAxis(angles, le->refEntity.axis);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
trap_R_AddRefEntityToScene(&le->refEntity);
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
// add a blood trail
|
2002-06-16 20:06:15 +00:00
|
|
|
if (le->leBounceSoundType == LEBS_BLOOD) {
|
|
|
|
CG_BloodTrail(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// if it is in a nodrop zone, remove it
|
|
|
|
// this keeps gibs from waiting at the bottom of pits of death
|
|
|
|
// and floating levels
|
2012-01-13 21:27:15 +00:00
|
|
|
if ( CG_PointContents( trace.endpos, 0 ) & CONTENTS_NODROP ) {
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_FreeLocalEntity(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// leave a mark
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_FragmentBounceMark(le, &trace);
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
// do a bouncy sound
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_FragmentBounceSound(le, &trace);
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
// reflect the velocity on the trace plane
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_ReflectVelocity(le, &trace);
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
trap_R_AddRefEntityToScene(&le->refEntity);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================================================================
|
|
|
|
|
|
|
|
TRIVIAL LOCAL ENTITIES
|
|
|
|
|
|
|
|
These only do simple scaling or modulation before passing to the renderer
|
|
|
|
=====================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
CG_AddFadeRGB
|
|
|
|
====================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_AddFadeRGB(localEntity_t * le)
|
|
|
|
{
|
2001-05-06 20:50:27 +00:00
|
|
|
refEntity_t *re;
|
|
|
|
float c;
|
|
|
|
|
|
|
|
re = &le->refEntity;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
c = (le->endTime - cg.time) * le->lifeRate;
|
2001-05-06 20:50:27 +00:00
|
|
|
c *= 0xff;
|
|
|
|
|
|
|
|
re->shaderRGBA[0] = le->color[0] * c;
|
|
|
|
re->shaderRGBA[1] = le->color[1] * c;
|
|
|
|
re->shaderRGBA[2] = le->color[2] * c;
|
|
|
|
re->shaderRGBA[3] = le->color[3] * c;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
trap_R_AddRefEntityToScene(re);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
CG_AddMoveScaleFade
|
|
|
|
==================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
static void CG_AddMoveScaleFade(localEntity_t * le)
|
|
|
|
{
|
|
|
|
refEntity_t *re;
|
|
|
|
float c;
|
|
|
|
vec3_t delta;
|
|
|
|
float len;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
re = &le->refEntity;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
if (le->fadeInTime > le->startTime && cg.time < le->fadeInTime) {
|
2001-05-06 20:50:27 +00:00
|
|
|
// fade / grow time
|
2002-06-16 20:06:15 +00:00
|
|
|
c = 1.0 - (float) (le->fadeInTime - cg.time) / (le->fadeInTime - le->startTime);
|
|
|
|
} else {
|
2001-05-06 20:50:27 +00:00
|
|
|
// fade / grow time
|
2002-06-16 20:06:15 +00:00
|
|
|
c = (le->endTime - cg.time) * le->lifeRate;
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
re->shaderRGBA[3] = 0xff * c * le->color[3];
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
if (!(le->leFlags & LEF_PUFF_DONT_SCALE)) {
|
|
|
|
re->radius = le->radius * (1.0 - c) + 8;
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_EvaluateTrajectory(&le->pos, cg.time, re->origin);
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
// if the view would be "inside" the sprite, kill the sprite
|
|
|
|
// so it doesn't add too much overdraw
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorSubtract(re->origin, cg.refdef.vieworg, delta);
|
|
|
|
len = VectorLength(delta);
|
|
|
|
if (len < le->radius) {
|
|
|
|
CG_FreeLocalEntity(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
trap_R_AddRefEntityToScene(re);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
CG_AddScaleFade
|
|
|
|
|
|
|
|
For rocket smokes that hang in place, fade out, and are
|
|
|
|
removed if the view passes through them.
|
|
|
|
There are often many of these, so it needs to be simple.
|
|
|
|
===================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
static void CG_AddScaleFade(localEntity_t * le)
|
|
|
|
{
|
|
|
|
refEntity_t *re;
|
|
|
|
float c;
|
|
|
|
vec3_t delta;
|
|
|
|
float len;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
re = &le->refEntity;
|
|
|
|
|
|
|
|
// fade / grow time
|
2002-06-16 20:06:15 +00:00
|
|
|
c = (le->endTime - cg.time) * le->lifeRate;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
re->shaderRGBA[3] = 0xff * c * le->color[3];
|
2002-06-16 20:06:15 +00:00
|
|
|
re->radius = le->radius * (1.0 - c) + 8;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
// if the view would be "inside" the sprite, kill the sprite
|
|
|
|
// so it doesn't add too much overdraw
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorSubtract(re->origin, cg.refdef.vieworg, delta);
|
|
|
|
len = VectorLength(delta);
|
|
|
|
if (len < le->radius) {
|
|
|
|
CG_FreeLocalEntity(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
trap_R_AddRefEntityToScene(re);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
CG_AddFallScaleFade
|
|
|
|
|
|
|
|
This is just an optimized CG_AddMoveScaleFade
|
|
|
|
For blood mists that drift down, fade out, and are
|
|
|
|
removed if the view passes through them.
|
|
|
|
There are often 100+ of these, so it needs to be simple.
|
|
|
|
=================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
static void CG_AddFallScaleFade(localEntity_t * le)
|
|
|
|
{
|
|
|
|
refEntity_t *re;
|
|
|
|
float c;
|
|
|
|
vec3_t delta;
|
|
|
|
float len;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
re = &le->refEntity;
|
|
|
|
|
|
|
|
// fade time
|
2002-06-16 20:06:15 +00:00
|
|
|
c = (le->endTime - cg.time) * le->lifeRate;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
re->shaderRGBA[3] = 0xff * c * le->color[3];
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
re->origin[2] = le->pos.trBase[2] - (1.0 - c) * le->pos.trDelta[2];
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
re->radius = le->radius * (1.0 - c) + 16;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
// if the view would be "inside" the sprite, kill the sprite
|
|
|
|
// so it doesn't add too much overdraw
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorSubtract(re->origin, cg.refdef.vieworg, delta);
|
|
|
|
len = VectorLength(delta);
|
|
|
|
if (len < le->radius) {
|
|
|
|
CG_FreeLocalEntity(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
trap_R_AddRefEntityToScene(re);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
CG_AddExplosion
|
|
|
|
================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
static void CG_AddExplosion(localEntity_t * ex)
|
|
|
|
{
|
|
|
|
refEntity_t *ent;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
ent = &ex->refEntity;
|
|
|
|
|
|
|
|
// add the entity
|
|
|
|
trap_R_AddRefEntityToScene(ent);
|
|
|
|
|
|
|
|
// add the dlight
|
2002-06-16 20:06:15 +00:00
|
|
|
if (ex->light) {
|
|
|
|
float light;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
light = (float) (cg.time - ex->startTime) / (ex->endTime - ex->startTime);
|
|
|
|
if (light < 0.5) {
|
2001-05-06 20:50:27 +00:00
|
|
|
light = 1.0;
|
|
|
|
} else {
|
2002-06-16 20:06:15 +00:00
|
|
|
light = 1.0 - (light - 0.5) * 2;
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
light = ex->light * light;
|
2002-06-16 20:06:15 +00:00
|
|
|
trap_R_AddLightToScene(ent->origin, light, ex->lightColor[0], ex->lightColor[1], ex->lightColor[2]);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
CG_AddSpriteExplosion
|
|
|
|
================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
static void CG_AddSpriteExplosion(localEntity_t * le)
|
|
|
|
{
|
|
|
|
refEntity_t re;
|
2001-05-06 20:50:27 +00:00
|
|
|
float c;
|
|
|
|
|
|
|
|
re = le->refEntity;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
c = (le->endTime - cg.time) / (float) (le->endTime - le->startTime);
|
|
|
|
if (c > 1) {
|
2001-05-06 20:50:27 +00:00
|
|
|
c = 1.0; // can happen during connection problems
|
|
|
|
}
|
|
|
|
|
|
|
|
re.shaderRGBA[0] = 0xff;
|
|
|
|
re.shaderRGBA[1] = 0xff;
|
|
|
|
re.shaderRGBA[2] = 0xff;
|
|
|
|
re.shaderRGBA[3] = 0xff * c * 0.33;
|
|
|
|
|
|
|
|
re.reType = RT_SPRITE;
|
2002-06-16 20:06:15 +00:00
|
|
|
re.radius = 42 * (1.0 - c) + 30;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
trap_R_AddRefEntityToScene(&re);
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
// add the dlight
|
2002-06-16 20:06:15 +00:00
|
|
|
if (le->light) {
|
|
|
|
float light;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
light = (float) (cg.time - le->startTime) / (le->endTime - le->startTime);
|
|
|
|
if (light < 0.5) {
|
2001-05-06 20:50:27 +00:00
|
|
|
light = 1.0;
|
|
|
|
} else {
|
2002-06-16 20:06:15 +00:00
|
|
|
light = 1.0 - (light - 0.5) * 2;
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
light = le->light * light;
|
2002-06-16 20:06:15 +00:00
|
|
|
trap_R_AddLightToScene(re.origin, light, le->lightColor[0], le->lightColor[1], le->lightColor[2]);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
CG_AddScorePlum
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
#define NUMBER_SIZE 8
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_AddScorePlum(localEntity_t * le)
|
|
|
|
{
|
|
|
|
refEntity_t *re;
|
|
|
|
vec3_t origin, delta, dir, vec, up = { 0, 0, 1 };
|
|
|
|
float c, len;
|
|
|
|
int i, score, digits[10], numdigits, negative;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
re = &le->refEntity;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
c = (le->endTime - cg.time) * le->lifeRate;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
score = le->radius;
|
|
|
|
if (score < 0) {
|
|
|
|
re->shaderRGBA[0] = 0xff;
|
|
|
|
re->shaderRGBA[1] = 0x11;
|
|
|
|
re->shaderRGBA[2] = 0x11;
|
2002-06-16 20:06:15 +00:00
|
|
|
} else {
|
2001-05-06 20:50:27 +00:00
|
|
|
re->shaderRGBA[0] = 0xff;
|
|
|
|
re->shaderRGBA[1] = 0xff;
|
|
|
|
re->shaderRGBA[2] = 0xff;
|
|
|
|
if (score >= 50) {
|
|
|
|
re->shaderRGBA[1] = 0;
|
|
|
|
} else if (score >= 20) {
|
|
|
|
re->shaderRGBA[0] = re->shaderRGBA[1] = 0;
|
|
|
|
} else if (score >= 10) {
|
|
|
|
re->shaderRGBA[2] = 0;
|
|
|
|
} else if (score >= 2) {
|
|
|
|
re->shaderRGBA[0] = re->shaderRGBA[2] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (c < 0.25)
|
|
|
|
re->shaderRGBA[3] = 0xff * 4 * c;
|
|
|
|
else
|
|
|
|
re->shaderRGBA[3] = 0xff;
|
|
|
|
|
|
|
|
re->radius = NUMBER_SIZE / 2;
|
|
|
|
|
|
|
|
VectorCopy(le->pos.trBase, origin);
|
|
|
|
origin[2] += 110 - c * 100;
|
|
|
|
|
|
|
|
VectorSubtract(cg.refdef.vieworg, origin, dir);
|
|
|
|
CrossProduct(dir, up, vec);
|
|
|
|
VectorNormalize(vec);
|
|
|
|
|
|
|
|
VectorMA(origin, -10 + 20 * sin(c * 2 * M_PI), vec, origin);
|
|
|
|
|
|
|
|
// if the view would be "inside" the sprite, kill the sprite
|
|
|
|
// so it doesn't add too much overdraw
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorSubtract(origin, cg.refdef.vieworg, delta);
|
|
|
|
len = VectorLength(delta);
|
|
|
|
if (len < 20) {
|
|
|
|
CG_FreeLocalEntity(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
negative = qfalse;
|
|
|
|
if (score < 0) {
|
|
|
|
negative = qtrue;
|
|
|
|
score = -score;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (numdigits = 0; !(numdigits && !score); numdigits++) {
|
|
|
|
digits[numdigits] = score % 10;
|
|
|
|
score = score / 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (negative) {
|
|
|
|
digits[numdigits] = 10;
|
|
|
|
numdigits++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < numdigits; i++) {
|
|
|
|
VectorMA(origin, (float) (((float) numdigits / 2) - i) * NUMBER_SIZE, vec, re->origin);
|
2002-06-16 20:06:15 +00:00
|
|
|
re->customShader = cgs.media.numberShaders[digits[numdigits - 1 - i]];
|
|
|
|
trap_R_AddRefEntityToScene(re);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_AddPressureEntity(localEntity_t * le)
|
|
|
|
{
|
|
|
|
vec3_t velocity;
|
2012-01-13 21:27:15 +00:00
|
|
|
// vec3_t origin;
|
2002-06-16 20:06:15 +00:00
|
|
|
float alpha;
|
2002-04-23 06:09:18 +00:00
|
|
|
|
2002-07-02 07:24:56 +00:00
|
|
|
// Kill it if LCA.
|
|
|
|
if (cg.lca)
|
|
|
|
CG_FreeLocalEntity(le);
|
|
|
|
|
2002-04-23 06:09:18 +00:00
|
|
|
alpha = -(cg.time - le->startTime) + (le->endTime - le->startTime);
|
|
|
|
alpha /= (le->endTime - le->startTime);
|
|
|
|
|
2002-05-26 05:14:14 +00:00
|
|
|
//steamSound!!!
|
|
|
|
|
2002-06-09 05:16:58 +00:00
|
|
|
// steam:
|
2002-12-02 19:52:05 +00:00
|
|
|
if ( le->leFlags != LEF_AIR && le->leFlags != LEF_WATER ) {
|
2002-05-26 05:14:14 +00:00
|
|
|
VectorScale(le->pos.trDelta, le->size + rand() % 30, velocity);
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-04-23 06:09:18 +00:00
|
|
|
velocity[0] += rand() % 40 - 20;
|
|
|
|
velocity[1] += rand() % 40 - 20;
|
2002-06-16 20:06:15 +00:00
|
|
|
} else
|
2002-06-09 05:16:58 +00:00
|
|
|
VectorScale(le->pos.trDelta, le->size, velocity);
|
2002-04-23 06:09:18 +00:00
|
|
|
|
2012-01-13 21:27:15 +00:00
|
|
|
// VectorCopy(le->pos.trBase, origin);
|
2002-04-23 06:09:18 +00:00
|
|
|
|
2002-06-09 05:16:58 +00:00
|
|
|
if (le->leFlags == LEF_AIR)
|
2002-08-25 07:09:20 +00:00
|
|
|
CG_ParticleAir(le->pos.trBase, velocity, le->life + rand() % 120, alpha, 2, 1);
|
2002-06-09 05:16:58 +00:00
|
|
|
else if (le->leFlags == LEF_FLAME)
|
2002-08-25 07:09:20 +00:00
|
|
|
CG_ParticleSteam(le->pos.trBase, velocity, le->life + rand() % 120, alpha, 2, 1,
|
|
|
|
cgs.media.flamePressureShader);
|
2002-12-02 19:52:05 +00:00
|
|
|
else if (le->leFlags == LEF_WATER)
|
|
|
|
CG_ParticleWater(le->pos.trBase, velocity, le->life + rand() % 120, alpha, 1, 2);
|
2002-06-16 20:06:15 +00:00
|
|
|
else
|
2002-08-25 07:09:20 +00:00
|
|
|
CG_ParticleSteam(le->pos.trBase, velocity, le->life + rand() % 120, alpha, 2, 1,
|
|
|
|
cgs.media.smokePuffShader);
|
2002-04-23 06:09:18 +00:00
|
|
|
}
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-05-09 06:45:14 +00:00
|
|
|
/*
|
|
|
|
================
|
|
|
|
CG_AddMovingTracer
|
2002-05-18 03:55:35 +00:00
|
|
|
- NiceAss
|
2002-05-09 06:45:14 +00:00
|
|
|
================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_AddTracer(localEntity_t * le)
|
|
|
|
{
|
2002-05-09 06:45:14 +00:00
|
|
|
vec3_t start, end, dir;
|
|
|
|
|
2002-05-18 03:55:35 +00:00
|
|
|
//BG_EvaluateTrajectory( &le->pos, cg.time, start );
|
|
|
|
VectorMA(le->pos.trBase, (cg.time - le->pos.trTime) / 1000.0f, le->pos.trDelta, start);
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorNormalize2(le->pos.trDelta, dir);
|
|
|
|
VectorMA(start, cg_tracerLength.value, dir, end);
|
2002-05-09 06:45:14 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_Tracer(start, end);
|
2002-05-09 06:45:14 +00:00
|
|
|
}
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
CG_AddLocalEntities
|
|
|
|
|
|
|
|
===================
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_AddLocalEntities(void)
|
|
|
|
{
|
|
|
|
localEntity_t *le, *next;
|
2001-05-06 20:50:27 +00:00
|
|
|
|
|
|
|
// walk the list backwards, so any new local entities generated
|
|
|
|
// (trails, marks, etc) will be present this frame
|
|
|
|
le = cg_activeLocalEntities.prev;
|
2002-06-16 20:06:15 +00:00
|
|
|
for (; le != &cg_activeLocalEntities; le = next) {
|
2001-05-06 20:50:27 +00:00
|
|
|
// grab next now, so if the local entity is freed we
|
|
|
|
// still have it
|
|
|
|
next = le->prev;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
if (cg.time >= le->endTime) {
|
|
|
|
CG_FreeLocalEntity(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
2002-06-16 20:06:15 +00:00
|
|
|
switch (le->leType) {
|
2001-05-06 20:50:27 +00:00
|
|
|
default:
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_Error("Bad leType: %i", le->leType);
|
2001-05-06 20:50:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LE_MARK:
|
|
|
|
break;
|
|
|
|
|
2002-05-18 03:55:35 +00:00
|
|
|
case LE_TRACER:
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_AddTracer(le);
|
2002-05-09 06:45:14 +00:00
|
|
|
break;
|
|
|
|
|
2001-05-06 20:50:27 +00:00
|
|
|
case LE_SPRITE_EXPLOSION:
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_AddSpriteExplosion(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LE_EXPLOSION:
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_AddExplosion(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
break;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
case LE_FRAGMENT: // gibs and brass
|
|
|
|
CG_AddFragment(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
break;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
case LE_MOVE_SCALE_FADE: // water bubbles
|
|
|
|
CG_AddMoveScaleFade(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
break;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
case LE_FADE_RGB: // teleporters, railtrails
|
|
|
|
CG_AddFadeRGB(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
break;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
case LE_FALL_SCALE_FADE: // gib blood trails
|
|
|
|
CG_AddFallScaleFade(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
break;
|
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
case LE_SCALE_FADE: // rocket trails
|
|
|
|
CG_AddScaleFade(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LE_SCOREPLUM:
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_AddScorePlum(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
break;
|
2001-08-01 21:07:48 +00:00
|
|
|
|
2002-04-29 06:11:56 +00:00
|
|
|
case LE_PRESSURE:
|
2002-06-16 20:06:15 +00:00
|
|
|
CG_AddPressureEntity(le);
|
2001-05-06 20:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-16 21:50:09 +00:00
|
|
|
/*
|
|
|
|
The only difference is that this will account for water friction
|
|
|
|
*/
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_LE_EvaluateTrajectory(const trajectory_t * tr, int atTime, vec3_t result)
|
|
|
|
{
|
|
|
|
float deltaTime;
|
|
|
|
float phase;
|
|
|
|
float friction = 1.0f;
|
2002-03-16 21:50:09 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
switch (tr->trType) {
|
2002-03-16 21:50:09 +00:00
|
|
|
case TR_STATIONARY:
|
|
|
|
case TR_INTERPOLATE:
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorCopy(tr->trBase, result);
|
2002-03-16 21:50:09 +00:00
|
|
|
break;
|
|
|
|
case TR_LINEAR:
|
2002-06-16 20:06:15 +00:00
|
|
|
deltaTime = (atTime - tr->trTime) * 0.001; // milliseconds to seconds
|
|
|
|
VectorMA(tr->trBase, deltaTime, tr->trDelta, result);
|
2002-03-16 21:50:09 +00:00
|
|
|
break;
|
|
|
|
case TR_SINE:
|
2002-06-16 20:06:15 +00:00
|
|
|
deltaTime = (atTime - tr->trTime) / (float) tr->trDuration;
|
|
|
|
phase = sin(deltaTime * M_PI * 2);
|
|
|
|
VectorMA(tr->trBase, phase, tr->trDelta, result);
|
2002-03-16 21:50:09 +00:00
|
|
|
break;
|
|
|
|
case TR_LINEAR_STOP:
|
2002-06-16 20:06:15 +00:00
|
|
|
if (atTime > tr->trTime + tr->trDuration) {
|
2002-03-16 21:50:09 +00:00
|
|
|
atTime = tr->trTime + tr->trDuration;
|
|
|
|
}
|
2002-06-16 20:06:15 +00:00
|
|
|
deltaTime = (atTime - tr->trTime) * 0.001; // milliseconds to seconds
|
|
|
|
if (deltaTime < 0) {
|
2002-03-16 21:50:09 +00:00
|
|
|
deltaTime = 0;
|
|
|
|
}
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorMA(tr->trBase, deltaTime, tr->trDelta, result);
|
2002-03-16 21:50:09 +00:00
|
|
|
break;
|
|
|
|
case TR_GRAVITY:
|
2002-06-16 20:06:15 +00:00
|
|
|
if (trap_CM_PointContents(tr->trBase, 0) & CONTENTS_WATER)
|
|
|
|
friction = 0.3f;
|
|
|
|
deltaTime = (atTime - tr->trTime) * 0.001; // milliseconds to seconds
|
|
|
|
VectorMA(tr->trBase, deltaTime * friction, tr->trDelta, result);
|
2002-03-16 21:50:09 +00:00
|
|
|
result[2] -= 0.5 * cg_gravity.value * friction * deltaTime * deltaTime;
|
|
|
|
break;
|
|
|
|
default:
|
2002-06-16 20:06:15 +00:00
|
|
|
Com_Error(ERR_DROP, "CG_LE_EvaluateTrajectory: unknown trType: %i", tr->trTime);
|
2002-03-16 21:50:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-05-06 20:50:27 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
void CG_LE_EvaluateTrajectoryDelta(const trajectory_t * tr, int atTime, vec3_t result)
|
|
|
|
{
|
|
|
|
float deltaTime;
|
|
|
|
float phase;
|
|
|
|
float friction = 1.0f;
|
2002-03-16 21:50:09 +00:00
|
|
|
|
2002-06-16 20:06:15 +00:00
|
|
|
switch (tr->trType) {
|
2002-03-16 21:50:09 +00:00
|
|
|
case TR_STATIONARY:
|
|
|
|
case TR_INTERPOLATE:
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorClear(result);
|
2002-03-16 21:50:09 +00:00
|
|
|
break;
|
|
|
|
case TR_LINEAR:
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorCopy(tr->trDelta, result);
|
2002-03-16 21:50:09 +00:00
|
|
|
break;
|
|
|
|
case TR_SINE:
|
2002-06-16 20:06:15 +00:00
|
|
|
deltaTime = (atTime - tr->trTime) / (float) tr->trDuration;
|
|
|
|
phase = cos(deltaTime * M_PI * 2); // derivative of sin = cos
|
2002-03-16 21:50:09 +00:00
|
|
|
phase *= 0.5;
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorScale(tr->trDelta, phase, result);
|
2002-03-16 21:50:09 +00:00
|
|
|
break;
|
|
|
|
case TR_LINEAR_STOP:
|
2002-06-16 20:06:15 +00:00
|
|
|
if (atTime > tr->trTime + tr->trDuration) {
|
|
|
|
VectorClear(result);
|
2002-03-16 21:50:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-06-16 20:06:15 +00:00
|
|
|
VectorCopy(tr->trDelta, result);
|
2002-03-16 21:50:09 +00:00
|
|
|
break;
|
|
|
|
case TR_GRAVITY:
|
2002-06-16 20:06:15 +00:00
|
|
|
if (trap_CM_PointContents(tr->trBase, 0) & CONTENTS_WATER)
|
|
|
|
friction = 0.3f;
|
|
|
|
deltaTime = (atTime - tr->trTime) * 0.001; // milliseconds to seconds
|
|
|
|
VectorScale(tr->trDelta, friction, result);
|
|
|
|
result[2] -= cg_gravity.value * friction * deltaTime;
|
2002-03-16 21:50:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-06-16 20:06:15 +00:00
|
|
|
Com_Error(ERR_DROP, "CG_LE_EvaluateTrajectoryDelta: unknown trType: %i", tr->trTime);
|
2002-03-16 21:50:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|