codemp/cgame/cg_effects.c File Reference

#include "cg_local.h"

Go to the source code of this file.

Defines

#define FX_ALPHA_NONLINEAR   0x00000004
#define FX_APPLY_PHYSICS   0x02000000
#define FX_USE_ALPHA   0x08000000
#define TIME_DECAY_SLOW   0.1f
#define TIME_DECAY_MED   0.04f
#define TIME_DECAY_FAST   0.009f
#define DEBRIS_SPECIALCASE_ROCK   -1
#define DEBRIS_SPECIALCASE_CHUNKS   -2
#define DEBRIS_SPECIALCASE_WOOD   -3
#define DEBRIS_SPECIALCASE_GLASS   -4
#define NUM_DEBRIS_MODELS_GLASS   8
#define NUM_DEBRIS_MODELS_WOOD   8
#define NUM_DEBRIS_MODELS_CHUNKS   3
#define NUM_DEBRIS_MODELS_ROCKS   4
#define NUM_SPARKS   12
#define NUM_PUFFS   1
#define NUM_EXPLOSIONS   4

Functions

void CG_BubbleTrail (vec3_t start, vec3_t end, float spacing)
localEntity_tCG_SmokePuff (const vec3_t p, const vec3_t vel, float radius, float r, float g, float b, float a, float duration, int startTime, int fadeInTime, int leFlags, qhandle_t hShader)
int CGDEBUG_SaberColor (int saberColor)
void CG_TestLine (vec3_t start, vec3_t end, int time, unsigned int color, int radius)
void CG_ThrowChunk (vec3_t origin, vec3_t velocity, qhandle_t hModel, int optionalSound, int startalpha)
void CG_InitGlass (void)
void Vector2Set (vec2_t a, float b, float c)
void CG_DoGlass (vec3_t verts[4], vec3_t normal, vec3_t dmgPt, vec3_t dmgDir, float dmgRadius, int maxShards)
void CG_GlassShatter (int entnum, vec3_t dmgPt, vec3_t dmgDir, float dmgRadius, int maxShards)
void CG_GlassShatter_Old (int entnum, vec3_t org, vec3_t mins, vec3_t maxs)
void CG_CreateDebris (int entnum, vec3_t org, vec3_t mins, vec3_t maxs, int debrissound, int debrismodel)
void CG_ExplosionEffects (vec3_t origin, float intensity, int radius, int time)
void CG_MiscModelExplosion (vec3_t mins, vec3_t maxs, int size, material_t chunkType)
void CG_Chunks (int owner, vec3_t origin, const vec3_t normal, const vec3_t mins, const vec3_t maxs, float speed, int numChunks, material_t chunkType, int customChunk, float baseScale)
void CG_ScorePlum (int client, vec3_t org, int score)
localEntity_tCG_MakeExplosion (vec3_t origin, vec3_t dir, qhandle_t hModel, int numFrames, qhandle_t shader, int msec, qboolean isSprite, float scale, int flags)
void CG_SurfaceExplosion (vec3_t origin, vec3_t normal, float radius, float shake_speed, qboolean smoke)
void CG_Bleed (vec3_t origin, int entityNum)
void CG_LaunchGib (vec3_t origin, vec3_t velocity, qhandle_t hModel)

Variables

int dbModels_Glass [NUM_DEBRIS_MODELS_GLASS]
int dbModels_Wood [NUM_DEBRIS_MODELS_WOOD]
int dbModels_Chunks [NUM_DEBRIS_MODELS_CHUNKS]
int dbModels_Rocks [NUM_DEBRIS_MODELS_ROCKS]


Define Documentation

#define DEBRIS_SPECIALCASE_CHUNKS   -2
 

Definition at line 757 of file cg_effects.c.

Referenced by CG_CreateDebris().

#define DEBRIS_SPECIALCASE_GLASS   -4
 

Definition at line 759 of file cg_effects.c.

Referenced by CG_CreateDebris().

#define DEBRIS_SPECIALCASE_ROCK   -1
 

Definition at line 756 of file cg_effects.c.

Referenced by CG_CreateDebris().

#define DEBRIS_SPECIALCASE_WOOD   -3
 

Definition at line 758 of file cg_effects.c.

Referenced by CG_CreateDebris().

#define FX_ALPHA_NONLINEAR   0x00000004
 

Definition at line 257 of file cg_effects.c.

#define FX_APPLY_PHYSICS   0x02000000
 

Definition at line 258 of file cg_effects.c.

#define FX_USE_ALPHA   0x08000000
 

Definition at line 259 of file cg_effects.c.

Referenced by CG_AddSaberBlade().

#define NUM_DEBRIS_MODELS_CHUNKS   3
 

Definition at line 763 of file cg_effects.c.

Referenced by CG_CreateDebris().

#define NUM_DEBRIS_MODELS_GLASS   8
 

Definition at line 761 of file cg_effects.c.

Referenced by CG_CreateDebris().

#define NUM_DEBRIS_MODELS_ROCKS   4
 

Definition at line 764 of file cg_effects.c.

Referenced by CG_CreateDebris().

#define NUM_DEBRIS_MODELS_WOOD   8
 

Definition at line 762 of file cg_effects.c.

Referenced by CG_CreateDebris().

#define NUM_EXPLOSIONS   4
 

Definition at line 1386 of file cg_effects.c.

Referenced by CG_SurfaceExplosion().

#define NUM_PUFFS   1
 

Definition at line 1385 of file cg_effects.c.

#define NUM_SPARKS   12
 

Definition at line 1384 of file cg_effects.c.

#define TIME_DECAY_FAST   0.009f
 

Definition at line 454 of file cg_effects.c.

Referenced by CG_DoGlass().

#define TIME_DECAY_MED   0.04f
 

Definition at line 453 of file cg_effects.c.

Referenced by CG_DoGlass().

#define TIME_DECAY_SLOW   0.1f
 

Definition at line 452 of file cg_effects.c.

Referenced by CG_DoGlass().


Function Documentation

void CG_Bleed vec3_t  origin,
int  entityNum
 

Definition at line 1489 of file cg_effects.c.

References cg, CG_AllocLocalEntity(), cg_blood, playerState_s::clientNum, refEntity_t::customShader, localEntity_s::endTime, vmCvar_t::integer, LE_EXPLOSION, localEntity_s::leType, localEntity_t, refEntity_t::origin, snapshot_t::ps, refEntity_t::radius, rand(), localEntity_s::refEntity, refEntity_t::renderfx, refEntity_t::reType, RF_THIRD_PERSON, refEntity_t::rotation, RT_SPRITE, cg_t::snap, localEntity_s::startTime, cg_t::time, vec3_t, and VectorCopy.

01489                                               {
01490         localEntity_t   *ex;
01491 
01492         if ( !cg_blood.integer ) {
01493                 return;
01494         }
01495 
01496         ex = CG_AllocLocalEntity();
01497         ex->leType = LE_EXPLOSION;
01498 
01499         ex->startTime = cg.time;
01500         ex->endTime = ex->startTime + 500;
01501         
01502         VectorCopy ( origin, ex->refEntity.origin);
01503         ex->refEntity.reType = RT_SPRITE;
01504         ex->refEntity.rotation = rand() % 360;
01505         ex->refEntity.radius = 24;
01506 
01507         ex->refEntity.customShader = 0;//cgs.media.bloodExplosionShader;
01508 
01509         // don't show player's own blood in view
01510         if ( entityNum == cg.snap->ps.clientNum ) {
01511                 ex->refEntity.renderfx |= RF_THIRD_PERSON;
01512         }
01513 }

void CG_BubbleTrail vec3_t  start,
vec3_t  end,
float  spacing
 

Definition at line 15 of file cg_effects.c.

References cg, CG_AllocLocalEntity(), cg_noProjectileTrail, localEntity_s::color, crandom, refEntity_t::customShader, localEntity_s::endTime, vmCvar_t::integer, LE_MOVE_SCALE_FADE, LEF_PUFF_DONT_SCALE, localEntity_s::leFlags, localEntity_s::leType, localEntity_s::lifeRate, localEntity_t, localEntity_s::pos, refEntity_t::radius, rand(), random, localEntity_s::refEntity, refEntity_t::reType, refEntity_t::rotation, RT_SPRITE, refEntity_t::shaderRGBA, refEntity_t::shaderTime, localEntity_s::startTime, cg_t::time, TR_LINEAR, trajectory_t::trBase, trajectory_t::trDelta, trajectory_t::trTime, trajectory_t::trType, vec3_t, VectorAdd, VectorCopy, VectorMA, VectorNormalize(), VectorScale, and VectorSubtract.

00015                                                                {
00016         vec3_t          move;
00017         vec3_t          vec;
00018         float           len;
00019         int                     i;
00020 
00021         if ( cg_noProjectileTrail.integer ) {
00022                 return;
00023         }
00024 
00025         VectorCopy (start, move);
00026         VectorSubtract (end, start, vec);
00027         len = VectorNormalize (vec);
00028 
00029         // advance a random amount first
00030         i = rand() % (int)spacing;
00031         VectorMA( move, i, vec, move );
00032 
00033         VectorScale (vec, spacing, vec);
00034 
00035         for ( ; i < len; i += spacing ) {
00036                 localEntity_t   *le;
00037                 refEntity_t             *re;
00038 
00039                 le = CG_AllocLocalEntity();
00040                 le->leFlags = LEF_PUFF_DONT_SCALE;
00041                 le->leType = LE_MOVE_SCALE_FADE;
00042                 le->startTime = cg.time;
00043                 le->endTime = cg.time + 1000 + random() * 250;
00044                 le->lifeRate = 1.0 / ( le->endTime - le->startTime );
00045 
00046                 re = &le->refEntity;
00047                 re->shaderTime = cg.time / 1000.0f;
00048 
00049                 re->reType = RT_SPRITE;
00050                 re->rotation = 0;
00051                 re->radius = 3;
00052                 re->customShader = 0;//cgs.media.waterBubbleShader;
00053                 re->shaderRGBA[0] = 0xff;
00054                 re->shaderRGBA[1] = 0xff;
00055                 re->shaderRGBA[2] = 0xff;
00056                 re->shaderRGBA[3] = 0xff;
00057 
00058                 le->color[3] = 1.0;
00059 
00060                 le->pos.trType = TR_LINEAR;
00061                 le->pos.trTime = cg.time;
00062                 VectorCopy( move, le->pos.trBase );
00063                 le->pos.trDelta[0] = crandom()*5;
00064                 le->pos.trDelta[1] = crandom()*5;
00065                 le->pos.trDelta[2] = crandom()*5 + 6;
00066 
00067                 VectorAdd (move, vec, move);
00068         }
00069 }

void CG_Chunks int  owner,
vec3_t  origin,
const vec3_t  normal,
const vec3_t  mins,
const vec3_t  maxs,
float  speed,
int  numChunks,
material_t  chunkType,
int  customChunk,
float  baseScale
 

Definition at line 1061 of file cg_effects.c.

References localEntity_s::angles, refEntity_t::axis, AxisCopy(), axisDefault, localEntity_s::bounceFactor, cg, CG_AllocLocalEntity(), cgs, CHAN_BODY, CHUNK_CRATE1, CHUNK_CRATE2, CHUNK_METAL1, CHUNK_METAL2, CHUNK_ROCK1, CHUNK_ROCK2, CHUNK_ROCK3, CHUNK_WHITE_METAL, cgMedia_t::chunkModels, cgMedia_t::chunkSound, crandom, cgMedia_t::crateBreakSound, localEntity_s::endTime, flrand(), cgs_t::gameModels, cgMedia_t::glassChunkSound, cgMedia_t::grateSound, refEntity_t::hModel, LE_FRAGMENT, localEntity_s::leBounceSoundType, leBounceSoundType_t, LEBS_METAL, LEBS_NONE, LEBS_ROCK, LEF_TUMBLE, localEntity_s::leFlags, localEntity_s::leType, localEntity_t, MAT_CRATE1, MAT_CRATE2, MAT_DRK_STONE, MAT_ELEC_METAL, MAT_ELECTRICAL, MAT_GLASS, MAT_GLASS_METAL, MAT_GRATE1, MAT_GREY_STONE, MAT_LT_STONE, MAT_METAL, MAT_METAL2, MAT_METAL3, MAT_NONE, MAT_ROPE, MAT_SNOWY_ROCK, MAT_WHITE_METAL, material_t, cgs_t::media, refEntity_t::modelScale, refEntity_t::nonNormalizedAxes, NULL, refEntity_t::origin, localEntity_s::pos, Q_irand(), qboolean, qfalse, qtrue, localEntity_s::radius, rand(), random, localEntity_s::refEntity, cgMedia_t::rockBreakSound, ScaleModelAxis(), cg_t::time, TR_GRAVITY, TR_LINEAR, trap_S_RegisterSound(), trap_S_StartSound(), trajectory_t::trBase, trajectory_t::trDelta, trajectory_t::trTime, trajectory_t::trType, va(), vec3_t, VectorCopy, VectorNormalize(), VectorScale, VectorSet, and VectorSubtract.

Referenced by CG_EntityEvent().

01063 {
01064         localEntity_t   *le;
01065         refEntity_t             *re;
01066         vec3_t                  dir;
01067         int                             i, j, k;
01068         int                             chunkModel = 0;
01069         leBounceSoundType_t     bounce = LEBS_NONE;
01070         float                   r, speedMod = 1.0f;
01071         qboolean                chunk = qfalse;
01072 
01073         if ( chunkType == MAT_NONE )
01074         {
01075                 // Well, we should do nothing
01076                 return;
01077         }
01078 
01079         // Set up our chunk sound info...breaking sounds are done here so they are done once on breaking..some return instantly because the chunks are done with effects instead of models
01080         switch( chunkType )
01081         {
01082         case MAT_GLASS:
01083                 trap_S_StartSound( NULL, owner, CHAN_BODY, cgs.media.glassChunkSound );
01084                 return;
01085                 break;
01086         case MAT_GRATE1:
01087                 trap_S_StartSound( NULL, owner, CHAN_BODY, cgs.media.grateSound );
01088                 return;
01089                 break;
01090         case MAT_ELECTRICAL:// (sparks)
01091                 trap_S_StartSound( NULL, owner, CHAN_BODY, trap_S_RegisterSound (va("sound/ambience/spark%d.wav", Q_irand(1, 6))) );
01092                 return;
01093                 break;
01094         case MAT_DRK_STONE:
01095         case MAT_LT_STONE:
01096         case MAT_GREY_STONE:
01097         case MAT_WHITE_METAL:  // not quite sure what this stuff is supposed to be...it's for Stu
01098         case MAT_SNOWY_ROCK:
01099                 trap_S_StartSound( NULL, owner, CHAN_BODY, cgs.media.rockBreakSound );
01100                 bounce = LEBS_ROCK;
01101                 speedMod = 0.5f; // rock blows up less
01102                 break;
01103         case MAT_GLASS_METAL:
01104                 trap_S_StartSound( NULL, owner, CHAN_BODY, cgs.media.glassChunkSound ); // FIXME: should probably have a custom sound
01105                 bounce = LEBS_METAL;
01106                 break;
01107         case MAT_CRATE1:
01108         case MAT_CRATE2:
01109                 trap_S_StartSound( NULL, owner, CHAN_BODY, cgs.media.crateBreakSound[Q_irand(0,1)] );
01110                 break;
01111         case MAT_METAL:
01112         case MAT_METAL2:
01113         case MAT_METAL3:
01114         case MAT_ELEC_METAL:// FIXME: maybe have its own sound?
01115                 trap_S_StartSound( NULL, owner, CHAN_BODY, cgs.media.chunkSound );
01116                 bounce = LEBS_METAL;
01117                 speedMod = 0.8f; // metal blows up a bit more
01118                 break;
01119         case MAT_ROPE:
01120 //              trap_S_StartSound( NULL, owner, CHAN_BODY, cgi_S_RegisterSound( "" ));  FIXME:  needs a sound
01121                 return;
01122                 break;
01123         }
01124 
01125         if ( baseScale <= 0.0f )
01126         {
01127                 baseScale = 1.0f;
01128         }
01129 
01130         // Chunks
01131         for( i = 0; i < numChunks; i++ )
01132         {
01133                 if ( customChunk > 0 )
01134                 {
01135                         // Try to use a custom chunk.
01136                         if ( cgs.gameModels[customChunk] )
01137                         {
01138                                 chunk = qtrue;
01139                                 chunkModel = cgs.gameModels[customChunk];
01140                         }
01141                 }
01142 
01143                 if ( !chunk )
01144                 {
01145                         // No custom chunk.  Pick a random chunk type at run-time so we don't get the same chunks
01146                         switch( chunkType )
01147                         {
01148                         case MAT_METAL2: //bluegrey
01149                                 chunkModel = cgs.media.chunkModels[CHUNK_METAL2][Q_irand(0, 3)];
01150                                 break;
01151                         case MAT_GREY_STONE://gray
01152                                 chunkModel = cgs.media.chunkModels[CHUNK_ROCK1][Q_irand(0, 3)];
01153                                 break;
01154                         case MAT_LT_STONE: //tan
01155                                 chunkModel = cgs.media.chunkModels[CHUNK_ROCK2][Q_irand(0, 3)];
01156                                 break;
01157                         case MAT_DRK_STONE://brown
01158                                 chunkModel = cgs.media.chunkModels[CHUNK_ROCK3][Q_irand(0, 3)];
01159                                 break;
01160                         case MAT_SNOWY_ROCK://gray & brown
01161                                 if ( Q_irand( 0, 1 ) )
01162                                 {
01163                                         chunkModel = cgs.media.chunkModels[CHUNK_ROCK1][Q_irand(0, 3)];
01164                                 }
01165                                 else
01166                                 {
01167                                         chunkModel = cgs.media.chunkModels[CHUNK_ROCK3][Q_irand(0, 3)];
01168                                 }
01169                                 break;
01170                         case MAT_WHITE_METAL:
01171                                 chunkModel = cgs.media.chunkModels[CHUNK_WHITE_METAL][Q_irand(0, 3)];
01172                                 break;
01173                         case MAT_CRATE1://yellow multi-colored crate chunks
01174                                 chunkModel = cgs.media.chunkModels[CHUNK_CRATE1][Q_irand(0, 3)];
01175                                 break;
01176                         case MAT_CRATE2://red multi-colored crate chunks
01177                                 chunkModel = cgs.media.chunkModels[CHUNK_CRATE2][Q_irand(0, 3)];
01178                                 break;
01179                         case MAT_ELEC_METAL:
01180                         case MAT_GLASS_METAL:
01181                         case MAT_METAL://grey
01182                                 chunkModel = cgs.media.chunkModels[CHUNK_METAL1][Q_irand(0, 3)];
01183                                 break;
01184                         case MAT_METAL3:
01185                                 if ( rand() & 1 )
01186                                 {
01187                                         chunkModel = cgs.media.chunkModels[CHUNK_METAL1][Q_irand(0, 3)];
01188                                 }
01189                                 else
01190                                 {
01191                                         chunkModel = cgs.media.chunkModels[CHUNK_METAL2][Q_irand(0, 3)];
01192                                 }
01193                                 break;
01194                         }
01195                 }
01196 
01197                 // It wouldn't look good to throw a bunch of RGB axis models...so make sure we have something to work with.
01198                 if ( chunkModel )
01199                 {
01200                         le = CG_AllocLocalEntity();
01201                         re = &le->refEntity;
01202 
01203                         re->hModel = chunkModel;
01204                         le->leType = LE_FRAGMENT;
01205                         le->endTime = cg.time + 1300 + random() * 900;
01206 
01207                         // spawn chunk roughly in the bbox of the thing...bias towards center in case thing blowing up doesn't complete fill its bbox.
01208                         for( j = 0; j < 3; j++ )
01209                         {
01210                                 r = random() * 0.8f + 0.1f;
01211                                 re->origin[j] = ( r * mins[j] + ( 1 - r ) * maxs[j] );
01212                         }
01213                         VectorCopy( re->origin, le->pos.trBase );
01214 
01215                         // Move out from center of thing, otherwise you can end up things moving across the brush in an undesirable direction.  Visually looks wrong
01216                         VectorSubtract( re->origin, origin, dir );
01217                         VectorNormalize( dir );
01218                         VectorScale( dir, flrand( speed * 0.5f, speed * 1.25f ) * speedMod, le->pos.trDelta );
01219 
01220                         // Angular Velocity
01221                         VectorSet( le->angles.trBase, random() * 360, random() * 360, random() * 360 );
01222 
01223                         le->angles.trDelta[0] = crandom();
01224                         le->angles.trDelta[1] = crandom();
01225                         le->angles.trDelta[2] = 0; // don't do roll
01226 
01227                         VectorScale( le->angles.trDelta, random() * 600.0f + 200.0f, le->angles.trDelta );
01228 
01229                         le->pos.trType = TR_GRAVITY;
01230                         le->angles.trType = TR_LINEAR;
01231                         le->pos.trTime = le->angles.trTime = cg.time;
01232                         le->bounceFactor = 0.2f + random() * 0.2f;
01233                         le->leFlags |= LEF_TUMBLE;
01234                         //le->ownerGentNum = owner;
01235                         le->leBounceSoundType = bounce; 
01236 
01237                         // Make sure that we have the desired start size set
01238                         le->radius = flrand( baseScale * 0.75f, baseScale * 1.25f );
01239                         re->nonNormalizedAxes = qtrue;
01240                         AxisCopy( axisDefault, re->axis ); // could do an angles to axis, but this is cheaper and works ok
01241                         for( k = 0; k < 3; k++ )
01242                         {
01243                                 re->modelScale[k] = le->radius;
01244                         }
01245                         ScaleModelAxis(re);
01246                         /*
01247                         for( k = 0; k < 3; k++ )
01248                         {
01249                                 VectorScale( re->axis[k], le->radius, re->axis[k] );
01250                         }
01251                         */
01252                 }
01253         }
01254 }

void CG_CreateDebris int  entnum,
vec3_t  org,
vec3_t  mins,
vec3_t  maxs,
int  debrissound,
int  debrismodel
 

Definition at line 771 of file cg_effects.c.

References CG_ThrowChunk(), crandom, dbModels_Chunks, dbModels_Glass, dbModels_Rocks, dbModels_Wood, DEBRIS_SPECIALCASE_CHUNKS, DEBRIS_SPECIALCASE_GLASS, DEBRIS_SPECIALCASE_ROCK, DEBRIS_SPECIALCASE_WOOD, NUM_DEBRIS_MODELS_CHUNKS, NUM_DEBRIS_MODELS_GLASS, NUM_DEBRIS_MODELS_ROCKS, NUM_DEBRIS_MODELS_WOOD, Q_irand(), trap_R_RegisterModel(), vec3_t, VectorCopy, and VectorSubtract.

00772 {
00773         vec3_t velocity, a, shardorg, dif, difx;
00774         float windowmass;
00775         float shardsthrow = 0;
00776         int omodel = debrismodel;
00777 
00778         if (omodel == DEBRIS_SPECIALCASE_GLASS && !dbModels_Glass[0])
00779         { //glass no longer exists, using it for metal.
00780                 dbModels_Glass[0] = trap_R_RegisterModel("models/chunks/metal/metal1_1.md3");
00781                 dbModels_Glass[1] = trap_R_RegisterModel("models/chunks/metal/metal1_2.md3");
00782                 dbModels_Glass[2] = trap_R_RegisterModel("models/chunks/metal/metal1_3.md3");
00783                 dbModels_Glass[3] = trap_R_RegisterModel("models/chunks/metal/metal1_4.md3");
00784                 dbModels_Glass[4] = trap_R_RegisterModel("models/chunks/metal/metal2_1.md3");
00785                 dbModels_Glass[5] = trap_R_RegisterModel("models/chunks/metal/metal2_2.md3");
00786                 dbModels_Glass[6] = trap_R_RegisterModel("models/chunks/metal/metal2_3.md3");
00787                 dbModels_Glass[7] = trap_R_RegisterModel("models/chunks/metal/metal2_4.md3");
00788         }
00789         if (omodel == DEBRIS_SPECIALCASE_WOOD && !dbModels_Wood[0])
00790         {
00791                 dbModels_Wood[0] = trap_R_RegisterModel("models/chunks/crate/crate1_1.md3");
00792                 dbModels_Wood[1] = trap_R_RegisterModel("models/chunks/crate/crate1_2.md3");
00793                 dbModels_Wood[2] = trap_R_RegisterModel("models/chunks/crate/crate1_3.md3");
00794                 dbModels_Wood[3] = trap_R_RegisterModel("models/chunks/crate/crate1_4.md3");
00795                 dbModels_Wood[4] = trap_R_RegisterModel("models/chunks/crate/crate2_1.md3");
00796                 dbModels_Wood[5] = trap_R_RegisterModel("models/chunks/crate/crate2_2.md3");
00797                 dbModels_Wood[6] = trap_R_RegisterModel("models/chunks/crate/crate2_3.md3");
00798                 dbModels_Wood[7] = trap_R_RegisterModel("models/chunks/crate/crate2_4.md3");
00799         }
00800         if (omodel == DEBRIS_SPECIALCASE_CHUNKS && !dbModels_Chunks[0])
00801         {
00802                 dbModels_Chunks[0] = trap_R_RegisterModel("models/chunks/generic/chunks_1.md3");
00803                 dbModels_Chunks[1] = trap_R_RegisterModel("models/chunks/generic/chunks_2.md3");
00804         }
00805         if (omodel == DEBRIS_SPECIALCASE_ROCK && !dbModels_Rocks[0])
00806         {
00807                 dbModels_Rocks[0] = trap_R_RegisterModel("models/chunks/rock/rock1_1.md3");
00808                 dbModels_Rocks[1] = trap_R_RegisterModel("models/chunks/rock/rock1_2.md3");
00809                 dbModels_Rocks[2] = trap_R_RegisterModel("models/chunks/rock/rock1_3.md3");
00810                 dbModels_Rocks[3] = trap_R_RegisterModel("models/chunks/rock/rock1_4.md3");
00811                 /*
00812                 dbModels_Rocks[4] = trap_R_RegisterModel("models/chunks/rock/rock2_1.md3");
00813                 dbModels_Rocks[5] = trap_R_RegisterModel("models/chunks/rock/rock2_2.md3");
00814                 dbModels_Rocks[6] = trap_R_RegisterModel("models/chunks/rock/rock2_3.md3");
00815                 dbModels_Rocks[7] = trap_R_RegisterModel("models/chunks/rock/rock2_4.md3");
00816                 dbModels_Rocks[8] = trap_R_RegisterModel("models/chunks/rock/rock3_1.md3");
00817                 dbModels_Rocks[9] = trap_R_RegisterModel("models/chunks/rock/rock3_2.md3");
00818                 dbModels_Rocks[10] = trap_R_RegisterModel("models/chunks/rock/rock3_3.md3");
00819                 dbModels_Rocks[11] = trap_R_RegisterModel("models/chunks/rock/rock3_4.md3");
00820                 */
00821         }
00822 
00823         VectorSubtract(maxs, mins, a);
00824 
00825         windowmass = VectorLength(a); //should give us some idea of how big the chunk of glass is
00826 
00827         while (shardsthrow < windowmass)
00828         {
00829                 velocity[0] = crandom()*150;
00830                 velocity[1] = crandom()*150;
00831                 velocity[2] = 150 + crandom()*75;
00832 
00833                 if (omodel == DEBRIS_SPECIALCASE_GLASS)
00834                 {
00835                         debrismodel = dbModels_Glass[Q_irand(0, NUM_DEBRIS_MODELS_GLASS-1)];
00836                 }
00837                 else if (omodel == DEBRIS_SPECIALCASE_WOOD)
00838                 {
00839                         debrismodel = dbModels_Wood[Q_irand(0, NUM_DEBRIS_MODELS_WOOD-1)];
00840                 }
00841                 else if (omodel == DEBRIS_SPECIALCASE_CHUNKS)
00842                 {
00843                         debrismodel = dbModels_Chunks[Q_irand(0, NUM_DEBRIS_MODELS_CHUNKS-1)];
00844                 }
00845                 else if (omodel == DEBRIS_SPECIALCASE_ROCK)
00846                 {
00847                         debrismodel = dbModels_Rocks[Q_irand(0, NUM_DEBRIS_MODELS_ROCKS-1)];
00848                 }
00849 
00850                 VectorCopy(org, shardorg);
00851         
00852                 dif[0] = (maxs[0]-mins[0])/2;
00853                 dif[1] = (maxs[1]-mins[1])/2;
00854                 dif[2] = (maxs[2]-mins[2])/2;
00855 
00856                 if (dif[0] < 2)
00857                 {
00858                         dif[0] = 2;
00859                 }
00860                 if (dif[1] < 2)
00861                 {
00862                         dif[1] = 2;
00863                 }
00864                 if (dif[2] < 2)
00865                 {
00866                         dif[2] = 2;
00867                 }
00868 
00869                 difx[0] = Q_irand(1, (dif[0]*0.9)*2);
00870                 difx[1] = Q_irand(1, (dif[1]*0.9)*2);
00871                 difx[2] = Q_irand(1, (dif[2]*0.9)*2);
00872 
00873                 if (difx[0] > dif[0])
00874                 {
00875                         shardorg[0] += difx[0]-(dif[0]);
00876                 }
00877                 else
00878                 {
00879                         shardorg[0] -= difx[0];
00880                 }
00881                 if (difx[1] > dif[1])
00882                 {
00883                         shardorg[1] += difx[1]-(dif[1]);
00884                 }
00885                 else
00886                 {
00887                         shardorg[1] -= difx[1];
00888                 }
00889                 if (difx[2] > dif[2])
00890                 {
00891                         shardorg[2] += difx[2]-(dif[2]);
00892                 }
00893                 else
00894                 {
00895                         shardorg[2] -= difx[2];
00896                 }
00897 
00898                 //CG_TestLine(org, shardorg, 5000, 0x0000ff, 3);
00899 
00900                 CG_ThrowChunk( shardorg, velocity, debrismodel, debrissound, 0 );
00901 
00902                 shardsthrow += 10;
00903         }
00904 }

void CG_DoGlass vec3_t  verts[4],
vec3_t  normal,
vec3_t  dmgPt,
vec3_t  dmgDir,
float  dmgRadius,
int  maxShards
 

Definition at line 456 of file cg_effects.c.

References CHAN_AUTO, qboolean, qfalse, qtrue, random, TIME_DECAY_FAST, TIME_DECAY_MED, TIME_DECAY_SLOW, trap_S_RegisterSound(), trap_S_StartSound(), vec2_t, vec3_t, and Vector2Set().

Referenced by CG_GlassShatter().

00457 {
00458         int                     i, t;
00459         int                     mxHeight, mxWidth;
00460         float           height, width;
00461         float           stepWidth, stepHeight;
00462         float           timeDecay;
00463         float           x, z;
00464         float           xx, zz;
00465         float           dif;
00466         int                     time = 0;
00467         int                     glassShards = 0;
00468         qboolean        stick = qtrue;
00469         vec3_t          subVerts[4];
00470         vec2_t          biPoints[4];
00471 
00472         // To do a smarter tesselation, we should figure out the relative height and width of the brush face,
00473         //      then use this to pick a lod value from 1-3 in each axis.  This will give us 1-9 lod levels, which will
00474         //      hopefully be sufficient.
00475         CG_CalcHeightWidth( verts, &height, &width );
00476 
00477         trap_S_StartSound( dmgPt, -1, CHAN_AUTO, trap_S_RegisterSound("sound/effects/glassbreak1.wav"));
00478 
00479         // Pick "LOD" for height
00480         if ( height < 100 )
00481         {
00482                 stepHeight = 0.2f;
00483                 mxHeight = 5;
00484                 timeDecay = TIME_DECAY_SLOW;
00485         }
00486         else if ( height > 220 )
00487         {
00488                 stepHeight = 0.05f;
00489                 mxHeight = 20;
00490                 timeDecay = TIME_DECAY_FAST;
00491         }
00492         else
00493         {
00494                 stepHeight = 0.1f;
00495                 mxHeight = 10;
00496                 timeDecay = TIME_DECAY_MED;
00497         }
00498 
00499         // Pick "LOD" for width
00500         /*
00501         if ( width < 100 )
00502         {
00503                 stepWidth = 0.2f;
00504                 mxWidth = 5;
00505                 timeDecay = ( timeDecay + TIME_DECAY_SLOW ) * 0.5f;
00506         }
00507         else if ( width > 220 )
00508         {
00509                 stepWidth = 0.05f;
00510                 mxWidth = 20;
00511                 timeDecay = ( timeDecay + TIME_DECAY_FAST ) * 0.5f;
00512         }
00513         else
00514         {
00515                 stepWidth = 0.1f;
00516                 mxWidth = 10;
00517                 timeDecay = ( timeDecay + TIME_DECAY_MED ) * 0.5f;
00518         }
00519         */
00520 
00521         //Attempt to scale the glass directly to the size of the window
00522 
00523         stepWidth = (0.25f - (width*0.0002)); //(width*0.0005));
00524         mxWidth = width*0.2;
00525         timeDecay = ( timeDecay + TIME_DECAY_FAST ) * 0.5f;
00526 
00527         if (stepWidth < 0.01f)
00528         {
00529                 stepWidth = 0.01f;
00530         }
00531         if (mxWidth < 5)
00532         {
00533                 mxWidth = 5;
00534         }
00535 
00536         for ( z = 0.0f, i = 0; z < 1.0f; z += stepHeight, i++ )
00537         {
00538                 for ( x = 0.0f, t = 0; x < 1.0f; x += stepWidth, t++ )
00539                 {
00540                         // This is nasty..
00541                         if ( t > 0 && t < mxWidth )
00542                         {
00543                                 xx = x - offX[i][t];
00544                         }
00545                         else
00546                         {
00547                                 xx = x;
00548                         }
00549 
00550                         if ( i > 0 && i < mxHeight )
00551                         {
00552                                 zz = z - offZ[t][i];
00553                         }
00554                         else
00555                         {
00556                                 zz = z;
00557                         }
00558 
00559                         Vector2Set( biPoints[0], xx, zz );
00560 
00561                         if ( t + 1 > 0 && t + 1 < mxWidth )
00562                         {
00563                                 xx = x - offX[i][t + 1];
00564                         }
00565                         else
00566                         {
00567                                 xx = x;
00568                         }
00569 
00570                         if ( i > 0 && i < mxHeight )
00571                         {
00572                                 zz = z - offZ[t + 1][i];
00573                         }
00574                         else
00575                         {
00576                                 zz = z;
00577                         }
00578 
00579                         Vector2Set( biPoints[1], xx + stepWidth, zz );
00580 
00581                         if ( t + 1 > 0 && t + 1 < mxWidth )
00582                         {
00583                                 xx = x - offX[i + 1][t + 1];
00584                         }
00585                         else
00586                         {
00587                                 xx = x;
00588                         }
00589 
00590                         if ( i + 1 > 0 && i + 1 < mxHeight )
00591                         {
00592                                 zz = z - offZ[t + 1][i + 1];
00593                         }
00594                         else
00595                         {
00596                                 zz = z;
00597                         }
00598 
00599                         Vector2Set( biPoints[2], xx + stepWidth, zz + stepHeight);
00600 
00601                         if ( t > 0 && t < mxWidth )
00602                         {
00603                                 xx = x - offX[i + 1][t];
00604                         }
00605                         else
00606                         {
00607                                 xx = x;
00608                         }
00609 
00610                         if ( i + 1 > 0 && i + 1 < mxHeight )
00611                         {
00612                                 zz = z - offZ[t][i + 1];
00613                         }
00614                         else
00615                         {
00616                                 zz = z;
00617                         }
00618 
00619                         Vector2Set( biPoints[3], xx, zz + stepHeight );
00620 
00621                         CG_CalcBiLerp( verts, subVerts, biPoints );
00622                         
00623                         dif = DistanceSquared( subVerts[0], dmgPt ) * timeDecay - random() * 32;
00624                         
00625                         // If we decrease dif, we are increasing the impact area, making it more likely to blow out large holes
00626                         dif -= dmgRadius * dmgRadius;
00627 
00628                         if ( dif > 1 )
00629                         {
00630                                 stick = qtrue;
00631                                 time = dif + random() * 200;
00632                         }
00633                         else
00634                         {
00635                                 stick = qfalse;
00636                                 time = 0;
00637                         }
00638 
00639                         CG_DoGlassQuad( subVerts, biPoints, stick, time, dmgDir );
00640                         glassShards++;
00641 
00642                         if (maxShards && glassShards >= maxShards)
00643                         {
00644                                 return;
00645                         }
00646                 }
00647         }
00648 }

void CG_ExplosionEffects vec3_t  origin,
float  intensity,
int  radius,
int  time
 

Definition at line 919 of file cg_effects.c.

References cg, CGCam_Shake(), cg_t::refdef, vec3_t, VectorNormalize(), VectorSubtract, and refdef_t::vieworg.

Referenced by CG_SurfaceExplosion().

00920 {
00921         //FIXME: When exactly is the vieworg calculated in relation to the rest of the frame?s
00922 
00923         vec3_t  dir;
00924         float   dist, intensityScale;
00925         float   realIntensity;
00926 
00927         VectorSubtract( cg.refdef.vieworg, origin, dir );
00928         dist = VectorNormalize( dir );
00929 
00930         //Use the dir to add kick to the explosion
00931 
00932         if ( dist > radius )
00933                 return;
00934 
00935         intensityScale = 1 - ( dist / (float) radius );
00936         realIntensity = intensity * intensityScale;
00937 
00938         CGCam_Shake( realIntensity, time );
00939 }

void CG_GlassShatter int  entnum,
vec3_t  dmgPt,
vec3_t  dmgDir,
float  dmgRadius,
int  maxShards
 

Definition at line 656 of file cg_effects.c.

References CG_DoGlass(), cg_entities, cgs, centity_s::currentState, cgs_t::inlineDrawModel, entityState_s::modelindex, trap_R_GetBModelVerts(), and vec3_t.

Referenced by CG_EntityEvent().

00657 {
00658         vec3_t          verts[4], normal;
00659 
00660         if (cgs.inlineDrawModel[cg_entities[entnum].currentState.modelindex])
00661         {
00662                 trap_R_GetBModelVerts(cgs.inlineDrawModel[cg_entities[entnum].currentState.modelindex], verts, normal);
00663                 CG_DoGlass(verts, normal, dmgPt, dmgDir, dmgRadius, maxShards);
00664         }
00665         //otherwise something awful has happened.
00666 }

void CG_GlassShatter_Old int  entnum,
vec3_t  org,
vec3_t  mins,
vec3_t  maxs
 

Definition at line 674 of file cg_effects.c.

References CG_ThrowChunk(), CHAN_BODY, Com_sprintf(), crandom, Q_irand(), trap_R_RegisterModel(), trap_S_RegisterSound(), trap_S_StartSound(), vec3_t, VectorCopy, and VectorSubtract.

00675 {
00676         vec3_t velocity, a, shardorg, dif, difx;
00677         float windowmass;
00678         float shardsthrow = 0;
00679         char chunkname[256];
00680 
00681         trap_S_StartSound(org, entnum, CHAN_BODY, trap_S_RegisterSound("sound/effects/glassbreak1.wav"));
00682 
00683         VectorSubtract(maxs, mins, a);
00684 
00685         windowmass = VectorLength(a); //should give us some idea of how big the chunk of glass is
00686 
00687         while (shardsthrow < windowmass)
00688         {
00689                 velocity[0] = crandom()*150;
00690                 velocity[1] = crandom()*150;
00691                 velocity[2] = 150 + crandom()*75;
00692 
00693                 Com_sprintf(chunkname, sizeof(chunkname), "models/chunks/glass/glchunks_%i.md3", Q_irand(1, 6));
00694                 VectorCopy(org, shardorg);
00695         
00696                 dif[0] = (maxs[0]-mins[0])/2;
00697                 dif[1] = (maxs[1]-mins[1])/2;
00698                 dif[2] = (maxs[2]-mins[2])/2;
00699 
00700                 if (dif[0] < 2)
00701                 {
00702                         dif[0] = 2;
00703                 }
00704                 if (dif[1] < 2)
00705                 {
00706                         dif[1] = 2;
00707                 }
00708                 if (dif[2] < 2)
00709                 {
00710                         dif[2] = 2;
00711                 }
00712 
00713                 difx[0] = Q_irand(1, (dif[0]*0.9)*2);
00714                 difx[1] = Q_irand(1, (dif[1]*0.9)*2);
00715                 difx[2] = Q_irand(1, (dif[2]*0.9)*2);
00716 
00717                 if (difx[0] > dif[0])
00718                 {
00719                         shardorg[0] += difx[0]-(dif[0]);
00720                 }
00721                 else
00722                 {
00723                         shardorg[0] -= difx[0];
00724                 }
00725                 if (difx[1] > dif[1])
00726                 {
00727                         shardorg[1] += difx[1]-(dif[1]);
00728                 }
00729                 else
00730                 {
00731                         shardorg[1] -= difx[1];
00732                 }
00733                 if (difx[2] > dif[2])
00734                 {
00735                         shardorg[2] += difx[2]-(dif[2]);
00736                 }
00737                 else
00738                 {
00739                         shardorg[2] -= difx[2];
00740                 }
00741 
00742                 //CG_TestLine(org, shardorg, 5000, 0x0000ff, 3);
00743 
00744                 CG_ThrowChunk( shardorg, velocity, trap_R_RegisterModel( chunkname ), 0, 254 );
00745 
00746                 shardsthrow += 10;
00747         }
00748 }

void CG_InitGlass void   ) 
 

Definition at line 430 of file cg_effects.c.

References crandom.

00431 {
00432         int i, t;
00433 
00434         // Build a table first, so that we can do a more unpredictable crack scheme
00435         //      do it once, up front to save a bit of time.
00436         for ( i = 0; i < 20; i++ )
00437         {
00438                 for ( t = 0; t < 20; t++ )
00439                 {
00440                         offX[t][i] = crandom() * 0.03f;
00441                         offZ[i][t] = crandom() * 0.03f;
00442                 }
00443         }
00444 }

void CG_LaunchGib vec3_t  origin,
vec3_t  velocity,
qhandle_t  hModel
 

Definition at line 1522 of file cg_effects.c.

References refEntity_t::axis, AxisCopy(), axisDefault, localEntity_s::bounceFactor, cg, CG_AllocLocalEntity(), localEntity_s::endTime, refEntity_t::hModel, LE_FRAGMENT, localEntity_s::leBounceSoundType, LEBS_BLOOD, localEntity_s::leMarkType, LEMT_BLOOD, localEntity_s::leType, localEntity_t, refEntity_t::origin, localEntity_s::pos, qhandle_t, random, localEntity_s::refEntity, localEntity_s::startTime, cg_t::time, TR_GRAVITY, trajectory_t::trBase, trajectory_t::trDelta, trajectory_t::trTime, trajectory_t::trType, vec3_t, and VectorCopy.

01522                                                                       {
01523         localEntity_t   *le;
01524         refEntity_t             *re;
01525 
01526         le = CG_AllocLocalEntity();
01527         re = &le->refEntity;
01528 
01529         le->leType = LE_FRAGMENT;
01530         le->startTime = cg.time;
01531         le->endTime = le->startTime + 5000 + random() * 3000;
01532 
01533         VectorCopy( origin, re->origin );
01534         AxisCopy( axisDefault, re->axis );
01535         re->hModel = hModel;
01536 
01537         le->pos.trType = TR_GRAVITY;
01538         VectorCopy( origin, le->pos.trBase );
01539         VectorCopy( velocity, le->pos.trDelta );
01540         le->pos.trTime = cg.time;
01541 
01542         le->bounceFactor = 0.6f;
01543 
01544         le->leBounceSoundType = LEBS_BLOOD;
01545         le->leMarkType = LEMT_BLOOD;
01546 }

localEntity_t* CG_MakeExplosion vec3_t  origin,
vec3_t  dir,
qhandle_t  hModel,
int  numFrames,
qhandle_t  shader,
int  msec,
qboolean  isSprite,
float  scale,
int  flags
 

Definition at line 1306 of file cg_effects.c.

References refEntity_t::axis, AxisClear(), cg, CG_AllocLocalEntity(), CG_Error(), localEntity_s::color, refEntity_t::customShader, localEntity_s::endTime, refEntity_t::hModel, LE_EXPLOSION, LE_SPRITE_EXPLOSION, LEF_NO_RANDOM_ROTATE, localEntity_s::leFlags, localEntity_s::leType, localEntity_s::lifeRate, localEntity_t, refEntity_t::nonNormalizedAxes, refEntity_t::oldorigin, refEntity_t::origin, qhandle_t, qtrue, localEntity_s::radius, rand(),