1 /* 2 * Copyright (C) 2002 Terence M. Welsh 3 * Ported to Linux by Tugrul Galatali <tugrul@galatali.com> 4 * 5 * Skyrocket is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License version 2 as 7 * published by the Free Software Foundation. 8 * 9 * Skyrocket is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 #ifndef PARTICLE_H 20 #define PARTICLE_H 21 22 #include "rsMath/rsVec.h" 23 24 // types of particles 25 #define ROCKET 0 26 #define FOUNTAIN 1 27 #define SPINNER 2 28 #define SMOKE 3 29 #define EXPLOSION 4 30 #define STAR 5 31 #define STREAMER 6 32 #define METEOR 7 33 #define POPPER 8 34 #define BEE 9 35 #define SUCKER 10 36 #define SHOCKWAVE 11 37 #define STRETCHER 12 38 #define BIGMAMA 13 39 40 class particle { 41 public: 42 unsigned int type; // choose type from #defines listed above 43 unsigned int displayList; // which object to draw (uses flare and rocket models) 44 rsVec xyz; // current position 45 rsVec lastxyz; // position from previous frame 46 rsVec vel; // velocity vector 47 rsVec rgb; // particle's color 48 float drag; // constant to represent air resistance 49 float t; // total time that particle lives 50 float tr; // time remaining 51 float bright; // intensity at which particle shines 52 float life; // life remaining (usually defined from 0.0 to 1.0) 53 float size; // scale factor by which to multiply the display list 54 // rocket variables 55 float thrust; // constant to represent power of rocket 56 float endthrust; // point in rockets life at which to stop thrusting 57 float spin, tilt; // radial and pitch velocities to make rockets wobble when they go up 58 rsVec tiltvec; // vector about which a rocket tilts 59 int makeSmoke; // whether or not this particle produces smoke 60 int smokeTimeIndex; // which smoke time to use 61 float smokeTrailLength; // length that smoke particles must cover from one frame to the next. 62 // smokeTrailLength is stored so that remaining length from previous frame can be covered 63 // and no gaps are left in the smoke trail 64 float sparkTrailLength; // same for sparks from streamers 65 int explosiontype; // Type of explosion that a rocket will become when life runs out 66 // sorting variable 67 float depth; 68 69 // Constructor initializes particles to be stars because that's what most of them are 70 particle (); ~particle()71 ~particle () { 72 }; 73 74 // A handy function for choosing an explosion's color 75 rsVec randomColor (); 76 77 // Initialization functions for particle types other than stars 78 void initStar (); 79 void initStreamer (); 80 void initMeteor (); 81 void initStarPopper (); 82 void initStreamerPopper (); 83 void initMeteorPopper (); 84 void initLittlePopper (); 85 void initBee (); 86 void initRocket (); 87 void initFountain (); 88 void initSpinner (); 89 void initSmoke (rsVec pos, rsVec speed); 90 void initSucker (); // rare easter egg explosion which is immediately followed by... 91 void initShockwave (); // a freakin' huge explosion 92 void initStretcher (); // another rare explosion followed by... 93 void initBigmama (); // this other massive bomb 94 void initExplosion (); 95 96 // "pop" functions are used to spawn new particles during explosions 97 void popSphere (int numParts, float v0, rsVec color); 98 void popSplitSphere (int numParts, float v0, rsVec color1); 99 void popMultiColorSphere (int numParts, float v0); 100 void popRing (int numParts, float v0, rsVec color); 101 void popStreamers (int numParts, float v0, rsVec color); 102 void popMeteors (int numParts, float v0, rsVec color); 103 void popStarPoppers (int numParts, float v0, rsVec color); 104 void popStreamerPoppers (int numParts, float v0, rsVec color); 105 void popMeteorPoppers (int numParts, float v0, rsVec color); 106 void popLittlePoppers (int numParts, float v0); 107 void popBees (int numParts, float v0, rsVec color); 108 109 // Finds depth along camera's coordinate system's -z axis. 110 // Can be used for sorting and culling. 111 void findDepth (); 112 113 // Update a particle according to elapsedTime 114 void update (); 115 116 // Draw a particle 117 void draw (); 118 119 // Return a pointer to this particle thisParticle()120 particle *thisParticle () { 121 return this; 122 }; 123 124 // operators used by stl list sorting 125 friend bool operator < (const particle & p1, const particle & p2) { 126 return (p2.depth < p1.depth); 127 } 128 friend bool operator > (const particle & p1, const particle & p2) { 129 return (p2.depth > p1.depth); 130 } 131 friend bool operator == (const particle & p1, const particle & p2) { 132 return (p1.depth == p2.depth); 133 } 134 friend bool operator != (const particle & p1, const particle & p2) { 135 return (p1.depth != p2.depth); 136 } 137 }; 138 139 #endif 140