src/tron/gExplosion.cpp File Reference

#include "gExplosion.h"
#include "rModel.h"
#include "rRender.h"
#include "tInitExit.h"
#include "gWall.h"
#include "gCycle.h"
#include "eGrid.h"
#include "tRandom.h"
#include "tMath.h"
#include "eSoundMixer.h"

Include dependency graph for gExplosion.cpp:

Go to the source code of this file.

Functions

static void clamp01 (REAL &c)
static void S_BlowHoles (eWall *w)
static void init_exp ()

Variables

static tList< gExplosionsg_Explosions
static eCoord s_explosionCoord
static REAL s_explosionRadius
static REAL s_explosionTime
static gExplosions_holer = 0
static tArray< Vec3expvec
static tInitExit ie_exp & init_exp
bool sg_crashExplosion = true
bool sg_crashExplosionHud = true


Function Documentation

static void clamp01 ( REAL c  )  [static]

Definition at line 45 of file gExplosion.cpp.

Referenced by S_BlowHoles(), and sg_TopologyPoliceCheck().

00046 {
00047     if (!finite(c))
00048         c = 0.5;
00049 
00050     if (c<0)
00051         c = 0;
00052 
00053     if (c>1)
00054         c = 1;
00055 }

Here is the caller graph for this function:

static void init_exp (  )  [static]

Definition at line 329 of file gExplosion.cpp.

References tRandomizer::Get(), tRandomizer::GetInstance(), GrowingArrayBase::Len(), and REAL.

00330                       {
00331     int i=0;
00332     expvec[i++]=Vec3(0,0,1);
00333     expvec[i++]=Vec3(0,1,1);
00334     expvec[i++]=Vec3(0,-1,1);
00335     expvec[i++]=Vec3(1,0,1);
00336     expvec[i++]=Vec3(-1,0,1);
00337     expvec[i++]=Vec3(1,1,1);
00338     expvec[i++]=Vec3(-1,1,1);
00339     expvec[i++]=Vec3(1,-1,1);
00340     expvec[i++]=Vec3(-1,-1,1);
00341 
00342     const REAL fak=7;
00343 
00344     tRandomizer & randomizer = tRandomizer::GetInstance();
00345 
00346     for (int j=i;j<40;j++){
00347         expvec[i++]=Vec3(fak*( randomizer.Get() -.5f ),
00348                          fak*( randomizer.Get() -.5f ),
00349                          1);
00350         //        expvec[i++]=Vec3(fak*(rand()/static_cast<REAL>(RAND_MAX)-.5f),
00351         //                         fak*(rand()/static_cast<REAL>(RAND_MAX)-.5f),
00352         //                         1);
00353     }
00354 
00355     for (int k=expvec.Len()-1;k>=0;k--)
00356         expvec[k]=expvec[k]*(1/expvec[k].Norm());

Here is the call graph for this function:

static void S_BlowHoles ( eWall w  )  [static]

Definition at line 66 of file gExplosion.cpp.

References gPlayerWall::BegPos(), gPlayerWall::BegTime(), gPlayerWall::BlowHole(), clamp01(), eCoord, eWall::EndPoint(), gPlayerWall::EndPos(), gPlayerWall::EndTime(), gPlayerWall::Pos(), REAL, s_explosionCoord, s_explosionRadius, s_explosionTime, sqrt(), tASSERT, gPlayerWall::Time(), and eWall::Vec().

Referenced by gExplosion::OnNewWall(), and gExplosion::Timestep().

00067 {
00068     // determine the point closest to s_explosionCoord
00069     eCoord normal = w->Vec().Conj();
00070     normal.Normalize();
00071 
00072     eCoord Pos1 = normal.Turn( w->EndPoint(0) - s_explosionCoord );
00073     eCoord Pos2 = normal.Turn( w->EndPoint(1) - s_explosionCoord );
00074 
00075     tASSERT( fabs( Pos1.y - Pos2.y ) <= fabs( Pos1.y + Pos2.y + .1f ) * .1f );
00076 
00077     REAL alpha = .5f;
00078     if ( Pos1.x != Pos2.x)
00079         alpha = Pos1.x / ( Pos1.x - Pos2.x );
00080 
00081     REAL radius = s_explosionRadius * s_explosionRadius - Pos1.y * Pos2.y;
00082 
00083     // wall too far away
00084     if ( radius < 0 )
00085         return;
00086 
00087     radius = sqrt( radius );
00088 
00089     // works only for player walls
00090     gPlayerWall* wall = dynamic_cast<gPlayerWall*>( w );
00091     if ( ! wall )
00092         return;
00093 
00094     REAL closestPos = wall->Pos( alpha );
00095 
00096     REAL start = closestPos - radius;
00097     REAL end = closestPos + radius;
00098 
00099     // only cut away walls that were created before the explosion started
00100     REAL wallEnd = wall->EndPos();
00101     REAL wallBeg = wall->BegPos();
00102     if ( wallEnd <= wallBeg )
00103     {
00104         return;
00105     }
00106     REAL endAlpha = ( end - wallBeg ) / ( wallEnd - wallBeg );
00107     // //std::cout << wall->BegTime() << "\n";
00108     clamp01( endAlpha );
00109     REAL endHoleTime = wall->Time( endAlpha );
00110     if ( endHoleTime > s_explosionTime )
00111     {
00112         REAL begTime = wall->BegTime();
00113         REAL endTime = wall->EndTime();
00114         REAL timeNorm = endTime - begTime;
00115         if ( timeNorm != 0.0f )
00116         {
00117             endAlpha = ( s_explosionTime - begTime ) / timeNorm;
00118             end = wall->Pos( endAlpha );
00119         }
00120     }
00121 
00122     if ( end > start )
00123     {
00124         wall->BlowHole ( start, end, s_holer );
00125     }
00126 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

tArray<Vec3> expvec [static]

Definition at line 327 of file gExplosion.cpp.

tInitExit ie_exp& init_exp [static]

Definition at line 358 of file gExplosion.cpp.

eCoord s_explosionCoord [static]

Definition at line 60 of file gExplosion.cpp.

Referenced by gExplosion::OnNewWall(), S_BlowHoles(), and gExplosion::Timestep().

REAL s_explosionRadius [static]

Definition at line 61 of file gExplosion.cpp.

Referenced by gExplosion::OnNewWall(), S_BlowHoles(), gExplosion::Timestep(), and gExplosion::~gExplosion().

REAL s_explosionTime [static]

Definition at line 62 of file gExplosion.cpp.

Referenced by gExplosion::OnNewWall(), S_BlowHoles(), and gExplosion::Timestep().

gExplosion* s_holer = 0 [static]

Definition at line 63 of file gExplosion.cpp.

bool sg_crashExplosion = true

Definition at line 360 of file gExplosion.cpp.

Referenced by gExplosion::Render().

bool sg_crashExplosionHud = true

Definition at line 361 of file gExplosion.cpp.

Referenced by gExplosion::Render2D().

tList< gExplosion > sg_Explosions [static]

Definition at line 43 of file gExplosion.cpp.

Referenced by gExplosion::OnNewWall().


Generated on Sat Mar 15 23:15:19 2008 for Armagetron Advanced by  doxygen 1.5.4