00001 00002 // Copyright (C) 2004-2007 by The Allacrost Project 00003 // All Rights Reserved 00004 // 00005 // This code is licensed under the GNU GPL version 2. It is free software 00006 // and you may modify it and/or redistribute it under the terms of this license. 00007 // See http://www.gnu.org/copyleft/gpl.html for details. 00009 00010 /*!**************************************************************************** 00011 * \file particle_system.h 00012 * \author Raj Sharma, roos@allacrost.org 00013 * \brief Header file for particle system 00014 * 00015 * This file contains two classes: ParticleSystemDef, and ParticleSystem. 00016 * 00017 * ParticleSystemDef is a "definition" class, meaning that it holds information 00018 * about a particle system, like its lifetime, the emitter, and other properties. 00019 * 00020 * ParticleSystem is an "instance" class, meaning that it holds information about 00021 * a particle system which is currently being drawn on screen. 00022 * 00023 * This way, if you have 100 explosions for example, the properties of the 00024 * effect are stored only once, and the only thing that gets repeated 100 times 00025 * is instance-specific stuff like positions of vertices, etc. 00026 *****************************************************************************/ 00027 00028 #ifndef __PARTICLE_SYSTEM_HEADER__ 00029 #define __PARTICLE_SYSTEM_HEADER__ 00030 00031 #include "defs.h" 00032 #include "utils.h" 00033 #include "particle.h" 00034 #include "particle_emitter.h" 00035 #include "video.h" 00036 00037 namespace hoa_video 00038 { 00039 00040 namespace private_video 00041 { 00042 00043 00044 /*!*************************************************************************** 00045 * \brief when we change a property of an effect, it affects all of the 00046 * systems contained within that effect. So, this structure contains 00047 * any relevant parameters that particle systems need to know about. 00048 *****************************************************************************/ 00049 00050 class EffectParameters 00051 { 00052 public: 00053 00055 float orientation; 00056 00058 float attractor_x, attractor_y; 00059 }; 00060 00061 00062 class ParticleSystemDef 00063 { 00064 public: 00065 00066 00068 bool enabled; 00069 00072 ParticleEmitter emitter; 00073 00076 std::vector <ParticleKeyframe *> keyframes; 00077 00080 int32 blend_mode; 00081 00087 float system_lifetime; 00088 00090 float particle_lifetime; 00091 00093 float particle_lifetime_variation; 00094 00096 int32 max_particles; 00097 00100 float damping; 00101 00103 float damping_variation; 00104 00107 float acceleration_x; 00108 float acceleration_y; 00109 00110 float acceleration_variation_x; 00111 float acceleration_variation_y; 00112 00114 float wind_velocity_x; 00115 float wind_velocity_y; 00116 00118 float wind_velocity_variation_x; 00119 float wind_velocity_variation_y; 00120 00122 bool wave_motion_used; 00123 00126 float wave_length; 00127 00129 float wave_length_variation; 00130 00132 float wave_amplitude; 00133 00135 float wave_amplitude_variation; 00136 00139 float tangential_acceleration; 00140 00142 float tangential_acceleration_variation; 00143 00146 float radial_acceleration; 00147 00149 float radial_acceleration_variation; 00150 00153 bool user_defined_attractor; 00154 00158 float attractor_falloff; 00159 00164 bool rotation_used; 00165 00169 bool rotate_to_velocity; 00170 00171 00174 bool speed_scale_used; 00175 00176 00179 float speed_scale; 00180 00181 00184 float min_speed_scale; 00185 00186 00189 float max_speed_scale; 00190 00191 00194 bool smooth_animation; 00195 00199 bool modify_stencil; 00200 00204 00205 VIDEO_STENCIL_OP stencil_op; 00206 00207 00210 bool use_stencil; 00211 00212 00217 float scene_lighting; 00218 00219 00222 bool random_initial_angle; 00223 00224 00226 std::vector <int32> animation_frame_times; 00227 00228 00230 std::vector <std::string> animation_frame_filenames; 00231 00232 }; // class ParticleSystemDef 00233 00234 00235 00236 class ParticleSystem 00237 { 00238 public: 00239 00243 ParticleSystem(); 00244 00245 00252 bool Create(const ParticleSystemDef *sys_def); 00253 00254 00259 bool Draw(); 00260 00261 00268 bool Update(float frame_time, const EffectParameters ¶ms); 00269 00270 00274 void Destroy(); 00275 00276 00281 bool IsAlive() const; 00282 00283 00288 bool IsStopped() const; 00289 00290 00294 void Stop(); 00295 00296 00301 int32 GetNumParticles() const; 00302 00303 00308 float GetAge() const; 00309 00310 private: 00311 00312 00318 void _UpdateParticles(float t, const EffectParameters ¶ms); 00319 00320 00333 void _KillParticles(int32 &num_particles, const EffectParameters ¶ms); 00334 00335 00342 void _EmitParticles(int32 num_particles, const EffectParameters ¶ms); 00343 00344 00352 void _MoveParticle(int32 src, int32 dest); 00353 00354 00360 void _RespawnParticle(int32 i, const EffectParameters ¶ms); 00361 00362 00365 const ParticleSystemDef *_system_def; 00366 00368 hoa_video::AnimatedImage _animation; 00369 00371 int32 _max_particles; 00372 00375 int32 _num_particles; 00376 00379 std::vector <ParticleVertex> _particle_vertices; 00380 std::vector <Color> _particle_colors; 00381 std::vector <ParticleTexCoord> _particle_texcoords; 00382 00385 std::vector <Particle> _particles; 00386 00388 bool _stopped; 00389 00391 bool _alive; 00392 00394 float _age; 00395 00397 float _last_update_time; 00398 00399 }; // class ParticleSystem 00400 00401 } // namespace private_video 00402 } // namespace hoa_video 00403 00404 #endif
1.5.1