gSpark Class Reference

#include <gSparks.h>

Inheritance diagram for gSpark:

Inheritance graph
[legend]
Collaboration diagram for gSpark:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 gSpark (eGrid *grid, const eCoord &pos, const eCoord &dir, REAL time, REAL ocolor_r, REAL ocolor_g, REAL ocolor_b, REAL ecolor_r, REAL ecolor_g, REAL ecolor_b)
virtual ~gSpark ()
virtual bool Timestep (REAL currentTime)
virtual void InteractWith (eGameObject *target, REAL time, int recursion=1)
virtual void PassEdge (const eWall *e, REAL time, REAL a, int recursion=1)
virtual void Kill ()
 destroys the gameobject (in the game)
virtual void Render (const eCamera *cam)
 draws object to the screen using OpenGL

Private Attributes

REAL createTime
Vec3 x [SPARKS]
Vec3 lastX [SPARKS]
Vec3 preLastX [SPARKS]
Vec3 xDot [SPARKS]
REAL heat [SPARKS]
REAL lastBreak [SPARKS]
REAL sparkowncolor_r
REAL sparkowncolor_g
REAL sparkowncolor_b
REAL sparkenemycolor_r
REAL sparkenemycolor_g
REAL sparkenemycolor_b


Detailed Description

Definition at line 37 of file gSparks.h.


Constructor & Destructor Documentation

gSpark::gSpark ( eGrid grid,
const eCoord &  pos,
const eCoord &  dir,
REAL  time,
REAL  ocolor_r,
REAL  ocolor_g,
REAL  ocolor_b,
REAL  ecolor_r,
REAL  ecolor_g,
REAL  ecolor_b 
)

Definition at line 39 of file gSparks.cpp.

References a, eGameObject::AddToList(), b, c, createTime, eCoord, tRandomizer::Get(), tRandomizer::GetInstance(), heat, lastBreak, eGameObject::lastTime, lastX, Vec3::Norm(), pCurrentGroup(), pGenParticleGroups(), eGameObject::Position(), preLastX, pSource(), REAL, sparkenemycolor_b, sparkenemycolor_g, sparkenemycolor_r, sparkowncolor_b, sparkowncolor_g, sparkowncolor_r, SPARKS, Vec3::x, x, and xDot.

00040         :eReferencableGameObject(grid, pos, dir , NULL, true),
00041         //   sound(scrap),
00042 createTime(time){
00043     lastTime=createTime;
00044 
00045 #ifndef USEPARTICLES
00046     sparkowncolor_r=ocolor_r;
00047     sparkowncolor_g=ocolor_g;
00048     sparkowncolor_b=ocolor_b;
00049 
00050     sparkenemycolor_r=ecolor_r;
00051     sparkenemycolor_g=ecolor_g;
00052     sparkenemycolor_b=ecolor_b;
00053 
00054     for (int i=SPARKS-1;i>=0;i--){
00055         lastX[i]=preLastX[i]=x[i]=Vec3(pos.x,pos.y,.5);
00056 
00057         static const REAL fak=4;
00058 
00059         tRandomizer & randomizer = tRandomizer::GetInstance();
00060         REAL a=fak*( randomizer.Get() - .5f );
00061         REAL b=fak*( randomizer.Get() - .5f );
00062         //      REAL a=fak*(rand()/static_cast<REAL>(RAND_MAX)-.5f);
00063         //      REAL b=fak*(rand()/static_cast<REAL>(RAND_MAX)-.5f);
00064         REAL c=1;
00065 
00066         eCoord xy(eCoord(c,b).Turn(dir));
00067 
00068         xDot[i]=Vec3(xy.x,xy.y,a);
00069         xDot[i]=xDot[i]*(1/xDot[i].Norm());
00070         xDot[i].x[2]+=1;
00071 
00072         heat[i]=2+randomizer.Get();
00073         //      heat[i]=2+rand()/REAL(RAND_MAX);
00074         lastBreak[i]=createTime;
00075     }
00076 #else
00077 #ifndef DEDICATED
00078     particle_handle = pGenParticleGroups(1, SPARKS);
00079 
00080     pCurrentGroup(particle_handle);
00081     // Generate particles along a very small line in the nozzle.
00082     pSource(SPARKS, PDLine(pVec(Position().x, Position().y, 0.3), pVec(Position().x, Position().y, 0.8)));
00083 #endif
00084 #endif
00085     // add to game grid
00086     this->AddToList();

Here is the call graph for this function:

gSpark::~gSpark (  )  [virtual]

Definition at line 88 of file gSparks.cpp.


Member Function Documentation

bool gSpark::Timestep ( REAL  currentTime  )  [virtual]

Reimplemented from eGameObject.

Definition at line 92 of file gSparks.cpp.

References createTime, heat, lastBreak, eGameObject::lastTime, pBounce(), pColorD(), pCurrentGroup(), pDeleteParticleGroups(), pGetGroupCount(), pGravity(), pKillOld(), pMove(), pSink(), pSize(), pVelocityD(), REAL, SPARKS, ts, Vec3::x, x, and xDot.

00093                                      {
00094 #ifndef USEPARTICLES
00095     REAL ts=currentTime-lastTime;
00096 
00097     for (int i=SPARKS-1;i>=0;i--){
00098         x[i]+=xDot[i]*ts;
00099         xDot[i].x[2]-=5*ts;
00100         heat[i]-=ts;
00101 
00102         if (x[i].x[2]<0){
00103             x[i].x[2]*=-1;
00104             xDot[i].x[2]*=-.5;
00105             lastBreak[i]=currentTime;
00106         }
00107     }
00108 
00109     if (currentTime>createTime+4)
00110         return true;
00111     else
00112         return false;
00113 #else
00114 #ifndef DEDICATED
00115     pCurrentGroup(particle_handle);
00116     // Set up the state.
00117     pVelocityD(PDCylinder(pVec(0.0, 0.0, 0.0), pVec(0.0, 0.0, 0.01), 0.01, 0.007));
00118     pColorD(PDLine(pVec(1.0, 1.0, 1.0), pVec(1.0, 1.0, 1.0)));
00119     pSize(40.0);
00120     //pStartingAge(0);
00121 
00122     //pRandomAccel(PDSphere(pVec(Position().x, Position().y, 0.0), 100.0));
00123 
00124     // Gravity.
00125     pGravity(pVec(0.0, 0.0, -0.001));
00126 
00127     // Bounce particles off a disc of radius 5.
00128     pBounce(-0.05, 1.0, 0.1, PDDisc(pVec(0, 0, 0), pVec(0, 0, 1), 5000000));
00129 
00130     // Kill particles below Z=0.
00131     pSink(false, PDPlane(pVec(0,0,0), pVec(0,0,1)));
00132 
00133     pKillOld(40);
00134 
00135     // Move particles to their new positions.
00136     pMove();
00137 
00138     // Finished when there are less than 1/10 of the original particles
00139     if (pGetGroupCount() < SPARKS/10) {
00140         pDeleteParticleGroups(particle_handle, particle_handle);
00141         return true;
00142     }
00143 #endif // dedicated
00144 #endif // particles
00145 
00146     lastTime=currentTime;
00147 

Here is the call graph for this function:

void gSpark::InteractWith ( eGameObject target,
REAL  time,
int  recursion = 1 
) [virtual]

Reimplemented from eGameObject.

Definition at line 149 of file gSparks.cpp.

void gSpark::PassEdge ( const eWall e,
REAL  time,
REAL  a,
int  recursion = 1 
) [virtual]

Reimplemented from eGameObject.

Definition at line 150 of file gSparks.cpp.

void gSpark::Kill (  )  [virtual]

destroys the gameobject (in the game)

Reimplemented from eGameObject.

Definition at line 152 of file gSparks.cpp.

00152 {}

void gSpark::Render ( const eCamera cam  )  [virtual]

draws object to the screen using OpenGL

Reimplemented from eGameObject.

Definition at line 156 of file gSparks.cpp.

References a, b, BeginLines(), gmax, heat, lastBreak, lastX, pCurrentGroup(), pGetGroupCount(), pGetParticlePointer(), preLastX, REAL, RenderEnd(), Vec3::RenderVertex(), rmax, se_GameTime(), sparkenemycolor_b, sparkenemycolor_g, sparkenemycolor_r, sparkowncolor_b, sparkowncolor_g, sparkowncolor_r, SPARKS, white_sparks, x, and xDot.

00158                                      {
00159 #ifndef USEPARTICLES
00160     glBlendFunc(GL_SRC_ALPHA,GL_ONE);
00161 
00162     //glMatrixMode(GL_MODELVIEW);
00163     //glPushMatrix();
00164     //glLoadIdentity();
00165 
00166     //glDisable(GL_TEXTURE);
00167     glDisable(GL_TEXTURE_2D);
00168 
00169     BeginLines();
00170     for (int i=SPARKS-1;i>=0;i--){
00171     #define rmax 1.2
00172     #define gmax 1.1
00173         REAL ago=.2;
00174         if (ago>se_GameTime()-lastBreak[i])
00175             ago=se_GameTime()-  lastBreak[i];
00176 
00177         REAL a=heat[i]+1.5;
00178         if (a>1) a=1;
00179         if (a<0) a=0;
00180 
00181         if(!white_sparks) {
00182             if(i%2)
00183                 glColor4f(sparkowncolor_r,sparkowncolor_g,sparkowncolor_b,a);
00184             else
00185                 glColor4f(sparkenemycolor_r,sparkenemycolor_g,sparkenemycolor_b,a);
00186         }
00187         else {
00188             REAL r=heat[i]+1;
00189             if (r>rmax) r=rmax;
00190             if (r>1) r=2-r;
00191             if (r<0) r=0;
00192             REAL g=heat[i]+.5;
00193             if (g>gmax) g=gmax;
00194             if (g>1) g=2-g;
00195             if (g<0) g=0;
00196             REAL b=heat[i];
00197             if (b>1) b=1;
00198             if (b<0) b=0;
00199 
00200             glColor4f(r,g,b,a);
00201         }
00202 
00203         x[i].RenderVertex();
00204         preLastX[i]=x[i];
00205         preLastX[i]+=xDot[i]*(-ago*.8);
00206 
00207         preLastX[i].RenderVertex();
00208         preLastX[i]=lastX[i];
00209         lastX[i]=x[i];
00210     }
00211     RenderEnd();
00212     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00213     //glPopMatrix();
00214 #else
00215     pCurrentGroup(particle_handle);
00216     int cnt = (int)pGetGroupCount();
00217     if(cnt < 1) return;
00218 
00219     float *ptr;
00220     size_t flstride, pos3Ofs, posB3Ofs, size3Ofs, vel3Ofs, velB3Ofs, color3Ofs, alpha1Ofs, age1Ofs;
00221 
00222     cnt = (int)pGetParticlePointer(ptr, flstride, pos3Ofs, posB3Ofs,
00223                                    size3Ofs, vel3Ofs, velB3Ofs, color3Ofs, alpha1Ofs, age1Ofs);
00224     if(cnt < 1) return;
00225 
00226     glEnableClientState(GL_COLOR_ARRAY);
00227     glColorPointer(4, GL_FLOAT, int(flstride) * sizeof(float), ptr + color3Ofs);
00228 
00229     glEnableClientState(GL_VERTEX_ARRAY);
00230     glVertexPointer(3, GL_FLOAT, int(flstride) * sizeof(float), ptr + pos3Ofs);
00231 
00232     glDrawArrays(GL_POINTS, 0, cnt);
00233     glDisableClientState(GL_VERTEX_ARRAY);

Here is the call graph for this function:


Member Data Documentation

REAL gSpark::createTime [private]

Definition at line 38 of file gSparks.h.

Referenced by gSpark(), and Timestep().

Vec3 gSpark::x[SPARKS] [private]

Definition at line 43 of file gSparks.h.

Referenced by gSpark(), Render(), and Timestep().

Vec3 gSpark::lastX[SPARKS] [private]

Definition at line 44 of file gSparks.h.

Referenced by gSpark(), and Render().

Vec3 gSpark::preLastX[SPARKS] [private]

Definition at line 45 of file gSparks.h.

Referenced by gSpark(), and Render().

Vec3 gSpark::xDot[SPARKS] [private]

Definition at line 46 of file gSparks.h.

Referenced by gSpark(), Render(), and Timestep().

REAL gSpark::heat[SPARKS] [private]

Definition at line 47 of file gSparks.h.

Referenced by gSpark(), Render(), and Timestep().

REAL gSpark::lastBreak[SPARKS] [private]

Definition at line 48 of file gSparks.h.

Referenced by gSpark(), Render(), and Timestep().

REAL gSpark::sparkowncolor_r [private]

Definition at line 49 of file gSparks.h.

Referenced by gSpark(), and Render().

REAL gSpark::sparkowncolor_g [private]

Definition at line 50 of file gSparks.h.

Referenced by gSpark(), and Render().

REAL gSpark::sparkowncolor_b [private]

Definition at line 51 of file gSparks.h.

Referenced by gSpark(), and Render().

REAL gSpark::sparkenemycolor_r [private]

Definition at line 52 of file gSparks.h.

Referenced by gSpark(), and Render().

REAL gSpark::sparkenemycolor_g [private]

Definition at line 53 of file gSparks.h.

Referenced by gSpark(), and Render().

REAL gSpark::sparkenemycolor_b [private]

Definition at line 54 of file gSparks.h.

Referenced by gSpark(), and Render().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:45:43 2008 for Armagetron Advanced by  doxygen 1.5.4