00001 /*! \file 00002 * X-Forge Util <br> 00003 * Copyright 2000-2003 Fathammer Ltd 00004 * 00005 * \brief Particle system utility 00006 * 00007 * $Id: XFuParticleSystem.h,v 1.12 2003/10/01 08:10:05 peppe Exp $ 00008 * $Date: 2003/10/01 08:10:05 $ 00009 * $Revision: 1.12 $ 00010 */ 00011 #ifndef XFUPARTICLESYSTEM_H_INCLUDED 00012 #define XFUPARTICLESYSTEM_H_INCLUDED 00013 00014 00015 class XFuParticleSystem; 00016 00017 00018 //! Noise controller for the XFuParticleSystem class. 00019 class XFuNoiseController 00020 { 00021 public: 00022 INT32 mType; //!< Type of particle system. 00023 XFcFixed mValue; //!< Noise 'value' - strenght of the particle system. 00024 XFcFixed mPeriod; //!< Noise 'period' - time in which the noise loops, or changes. 00025 XFcFixed noise(INT32 aTick, XFuParticleSystem * ps); //!< Generate noise. 00026 void write(XFcFile * aFile); //!< Write the noise controller data into a file. 00027 void read(XFcFile * aFile); //!< Read the noise controller data from a file. 00028 }; 00029 00030 00031 //! Flags for the particle system. 00032 enum XFUPARTICLESYSTEM_FLAGBITS 00033 { 00034 //! X min is a collider. 00035 XFUPSF_COLLIDER_XMIN = 1, 00036 //! Y min is a collider. 00037 XFUPSF_COLLIDER_YMIN = 2, 00038 //! Z min is a collider. 00039 XFUPSF_COLLIDER_ZMIN = 4, 00040 //! X max is a collider. 00041 XFUPSF_COLLIDER_XMAX = 8, 00042 //! Y max is a collider. 00043 XFUPSF_COLLIDER_YMAX = 16, 00044 //! Z max is a collider. 00045 XFUPSF_COLLIDER_ZMAX = 32, 00046 //! Does N iterations per second (and not FPS iterations). 00047 XFUPSF_FORCEITERATIONS = 64, 00048 //! Not implemented at the moment (world vs object space). 00049 XFUPSF_WORLDSPACE_PARTICLES = 128, 00050 //! Flag set in the editor, used in high-level x-forge. 00051 XFUPSF_TICK_ONLY_WHEN_SEEN = 256 00052 }; 00053 00054 00055 //! Particle system class. 00056 /*! 00057 * This particle system class runs and renders particle systems made with the 00058 * 'thingamajig' particle system editor. 00059 */ 00060 class XFuParticleSystem 00061 { 00062 // Everything is made public for the editor. 00063 public: 00064 UINT32 mFlags; //!< Flags (see XFUPARTICLESYSTEM_FLAGBITS enum). 00065 00066 //! Launch velocity. 00067 XFcFixed mLaunchVelocity[3]; 00068 //! Noise controllers for launch velocity. 00069 XFuNoiseController mLaunchVelocityVar[3]; 00070 00071 //! Damping (emulates friction). 00072 XFcFixed mDamping[3]; 00073 00074 //! Weight (or gravity, wind, whatever). 00075 XFcFixed mWeight[3]; 00076 //! Noise contollers for weight. 00077 XFuNoiseController mNoise[3]; 00078 00079 //! Launch rate (particles per second). 00080 XFcFixed mLaunchRate; 00081 //! Maximum age (in msec). 00082 INT32 mMaxAge; 00083 //! Maximum age noise controller. 00084 XFuNoiseController mAgeVariation; 00085 //! Maximum number of particles for all time. 00086 INT32 mMaxTotal; 00087 //! Maximum number of particles visible at any time. DO NOT CHANGE DIRECTLY. 00088 INT32 mMaxVisible; 00089 00090 //! All sizes are scaled by this value. 00091 XFcFixed mSizeScale; 00092 //! Scaling value for the rendering billboards. 00093 /*! This is inverse of the camera scale in ViewMatrix. 00094 */ 00095 XFcFixed mViewScale; 00096 //! Time is scaled by this value (for 'bullet-time'ish things) - unfinished. 00097 XFcFixed mTimeScale; 00098 //! Maximum iterations per second. 00099 XFcFixed mDesiredFPS; 00100 00101 //! Alpha mode (none, alpha, add, mul, invmul). 00102 INT32 mAlphaMode; 00103 //! Alpha value at the beginning of the lifespan. 00104 XFcFixed mAlphaStart; 00105 //! Alpha value at the end of the lifespan. 00106 XFcFixed mAlphaEnd; 00107 //! Noise controller for alpha. 00108 XFuNoiseController mAlphaVariation; 00109 00110 //! Particle size at the beginning of the lifespan. 00111 XFcFixed mParticleSizeStart; 00112 //! Particle size at the end of the lifespan. 00113 XFcFixed mParticleSizeEnd; 00114 //! Noise controller for particle size. 00115 XFuNoiseController mParticleSizeVariation; 00116 //! Base z-rotation. 00117 XFcFixed mRotation; 00118 //! Noise controller for rotation. 00119 XFuNoiseController mRotationVariation; 00120 //! Noise controller for original z-position. 00121 XFuNoiseController mRotationNoise; 00122 00123 //! Noise controller for particle animation frames. 00124 XFuNoiseController mFrameVariation; 00125 00126 //! Emitter size (0 for point). 00127 XFcFixed mEmitterSize[3]; 00128 //! Maximum limits from the center of the particle system (0 for infinite). 00129 XFcFixed mAABB[3]; 00130 00131 //! How many frames to pre-tick the particle system on restart. 00132 INT32 mPreTick; 00133 00134 //! File names for animation frames. 00135 CHAR **mTexture; 00136 00137 ////////////////////////////////////////////////////////////////////// 00138 // Rest are not meant to be saved in a file 00139 ////////////////////////////////////////////////////////////////////// 00140 00141 //! Single particle structure. 00142 struct Particle 00143 { 00144 XFcFixed mX, mY, mZ; //!< Current position. 00145 XFcFixed mXi, mYi, mZi; //!< Current motion vector. 00146 XFcFixed mAngle; //!< Current z-rotation angle. 00147 XFcFixed mBaseRotation; //!< Base rotation. 00148 XFcFixed mSize; //!< Current size. 00149 XFcFixed mAge; //!< Current age. 00150 XFcFixed mMaxAge; //!< Maximum age. 00151 INT32 mUniqueSeed; //!< For noise controller(s). 00152 } *mParticle; //!< Array of particles. 00153 00154 INT32 mActive; //!< Number of currently active particles. 00155 INT32 mFrames; //!< Number of frames of animation for this system. 00156 XFcGLTexture **mFrame; //!< Particle animation frames. 00157 XFcFixed mStartTick; //!< Start tick. 00158 XFcFixed mLastTick; //!< Last tick the particle system was updated. 00159 XFcFixed mCurrentTick; //!< Current tick . 00160 INT32 mPeakActive; //!< Peak active particles. 00161 INT32 mEmitted; //!< Number of particles emitted so far. 00162 XFcFixed mEmitQueue; //!< Number of particles in queue to be emitted. 00163 00164 INT32 mRandSeed1; //!< First seed for rol'n'xor noise function. 00165 INT32 mRandSeed2; //!< Second seed for rol'n'xor noise function. 00166 00167 //! Are textures shared? (otherwise owned by this particle system) 00168 INT mSharedTextures; 00169 00170 // Methods 00171 00172 //! Constructor. 00173 XFuParticleSystem(); 00174 //! Destructor. 00175 virtual ~XFuParticleSystem(); 00176 //! Restarts the particle system. 00177 void restart(); 00178 //! Called to update the particle system. 00179 void tick(XFcFixed aTime); 00180 00181 //! Used internally. 00182 /*! \internal 00183 */ 00184 void tickOnce(XFcFixed aTimeSlice); 00185 //! Renders the particle system using 3D sprites. 00186 void render(XFcGL * mGL); 00187 //! Sets maximum number of visible particles. 00188 void setMaxVisible(INT32 value); 00189 //! Saves particle system to disk. 00190 void save(const CHAR *aFname); 00191 //! Loads particle system from disk. 00192 void load(XFcFile *f); 00193 //! Loads particle system from disk. 00194 void load(const CHAR *aFname); 00195 //! Loads textures. 00196 /*! \param aFilenamePrefix filename prefix to use for each texture filename. 00197 */ 00198 void loadTextures(const CHAR *aFilenamePrefix = NULL); 00199 00200 // Internal methods 00201 00202 //! Creates a new particle. 00203 /*! \internal 00204 */ 00205 void newParticle(struct Particle &aParticle); 00206 //! Seeds the noise function. 00207 /*! \internal 00208 */ 00209 void PSSeed(INT32 aValue); 00210 //! Noise function. 00211 /*! \internal 00212 */ 00213 INT32 PSRand(); 00214 //! Seeds the noise function and returns the next value. 00215 /*! \internal 00216 */ 00217 static INT32 PSRandInPlace(INT32 aSeed); 00218 }; 00219 00220 00221 #endif // !XFUPARTICLESYSTEM_H_INCLUDED 00222
![]() | ||||
![]() |
Confidential Copyright © 2002-2003 Fathammer | with doxygen by Dimitri van Heesch |