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.9 2003/06/04 14:22:46 jetro Exp $ 00008 * $Date: 2003/06/04 14:22:46 $ 00009 * $Revision: 1.9 $ 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 // Methods 00168 00169 //! Constructor. 00170 XFuParticleSystem(); 00171 //! Destructor. 00172 virtual ~XFuParticleSystem(); 00173 //! Restarts the particle system. 00174 void restart(); 00175 //! Called to update the particle system. 00176 void tick(XFcFixed aTime); 00177 00178 //! Used internally. 00179 /*! \internal 00180 */ 00181 void tickOnce(XFcFixed aTimeSlice); 00182 //! Renders the particle system using 3D sprites. 00183 void render(XFcGL * mGL); 00184 //! Sets maximum number of visible particles. 00185 void setMaxVisible(INT32 value); 00186 //! Saves particle system to disk. 00187 void save(const CHAR *aFname); 00188 //! Loads particle system from disk. 00189 void load(const CHAR *aFname); 00190 //! Loads textures. 00191 /*! \param aFilenamePrefix filename prefix to use for each texture filename. 00192 */ 00193 void loadTextures(const CHAR *aFilenamePrefix = NULL); 00194 00195 // Internal methods 00196 00197 //! Creates a new particle. 00198 /*! \internal 00199 */ 00200 void newParticle(struct Particle &aParticle); 00201 //! Seeds the noise function. 00202 /*! \internal 00203 */ 00204 void PSSeed(INT32 aValue); 00205 //! Noise function. 00206 /*! \internal 00207 */ 00208 INT32 PSRand(); 00209 //! Seeds the noise function and returns the next value. 00210 /*! \internal 00211 */ 00212 static INT32 PSRandInPlace(INT32 aSeed); 00213 }; 00214 00215 00216 #endif // !XFUPARTICLESYSTEM_H_INCLUDED
![]() | ||||
![]() |
Confidential Copyright © 2002-2003 Fathammer | with doxygen by Dimitri van Heesch |