/****************************************************************************** Use 'Particles' for simplified particles management (updating and drawing). Use 'RawParticles' for batched drawing of thousands of particles that are updated manually. Use 'DrawParticle' functions for drawing each particle manually. /******************************************************************************/ enum PARTICLE_SRC : Byte // Particles Source Type { PARTICLE_NONE , // none PARTICLE_STATIC_SHAPE , // static shape , 'Particles.shape' transformed by 'Particles.matrix' PARTICLE_DYNAMIC_SHAPE , // dynamic shape , 'Shape' PARTICLE_DYNAMIC_SHAPES , // dynamic shapes , 'Shape' array PARTICLE_DYNAMIC_ORIENTP , // dynamic point , 'OrientP' PARTICLE_DYNAMIC_SKELETON , // dynamic skeleton , 'AnimatedSkeleton' PARTICLE_DYNAMIC_MESH , // dynamic mesh , 'Mesh' transformed by 'Particles.matrix' PARTICLE_DYNAMIC_MESH_SKELETON, // dynamic mesh animated by skeleton, 'Mesh' transformed by 'AnimatedSkeleton' }; /******************************************************************************/ struct Particle // Single Particle { Byte palette_y , // palette y coordinate for 'Particles.palette_image' image_index; // image index for animated particle images, used when "image_speed<=0 && (image_x_frames>1 || image_y_frames>1)" Flt life , // current life life_max , // maximum life radius , // radius ang_vel ; // angular velocity Vec pos , // position vel ; // velocity Particle() {Zero(T);} }; /******************************************************************************/ struct Particles // Set of Particles { Mems p; // particles Bool reborn , // if reborn particles after their death , false/true, default=true smooth_fade , // false for (quick fade-in and slow fade-out) or true for (smooth fade-in and fade-out), false/true, default=false (this is ignored if 'opacity_func' is specified) motion_affects_alpha; // if motion stretching affects opacity , false/true, default=true Byte glow ; // glow amount , 0..255 , default=0 (this is valid only for particles rendered in RM_BLEND mode when 'palette'=false) Color color ; // color , , (this is used when the color table isn't set) Flt radius , // Particle radius at its creation time , 0..Inf, (this is the initial value of 'Particle.radius' at its creation time) radius_random, // Particle radius random factor , 0..Inf, default=0 (this affects initial value of 'Particle.radius', 0 value keeps it constant, 1 value can make it 2x smaller to 2x bigger, 2 value can make it 3x smaller to 3x bigger) radius_growth, // Particle radius growth factor , 0..Inf, default=1 (this affects 'Particle.radius' in each frame, where a value of 0..1 decreases the radius, 1 keeps it constant, and 1..Inf increases the radius) offset_range , // Particle position offset range applied during drawing, 0..Inf, default=0 (this simulates the range of random position offsets for each particle during drawing, value of 0 is the fastest and disables the offset usage) offset_speed , // Particle position offset speed applied during drawing, 0..Inf, default=1 (this simulates the speed of random potision offsets for each particle during drawing) life , // Particle life , 0..Inf, (this is the life of a single particle 'Particle.max_life') life_random ; // Particle life random factor , 0..Inf, (this affects 'Particle.max_life', 0 value keeps it constant, 1 value can make it 2x shorter to 2x longer, 2 value can make it 3x shorter to 3x longer) Flt glue , // moves particles along with the source movement, 0..1 , default=0 (this affects each single particle position according to source generation object movement, value of 0 disables position adjustment and doesn't require any additional calculations) damping , // Particle velocity damping , 0..1 , default=0 (this dampens particles velocity in each frame) ang_vel , // angular velocity range , 0..Inf , default=0 vel_random ; // random velocity applied at particle creation, 0..Inf , default=0 Vec vel_constant, // constant velocity applied at particle creation, (-Inf,-Inf,-Inf)..(Inf,Inf,Inf), default=(0,0,0) accel ; // acceleration applied each frame , (-Inf,-Inf,-Inf)..(Inf,Inf,Inf), default=(0,0,0) Flt emitter_life_max , // maximum life of the Particles Emitter , 0..Inf , default=0 (this specifies the maximum life of the Particles Set, value <=0 specifies infinite life, value >0 specifies finite life) emitter_life , // current life of the Particles Emitter , 0..emitter_life_max, default=0 (this specifies the current life of the Particles Set, this value is increased only if the Particles Set has finite life) fade_in , // fade in time , 0..Inf , default=1 (this affects the global opacity of all particles , this value is used only if the Particles Set has finite life) fade_out , // fade out time , 0..Inf , default=1 (this affects the global opacity of all particles , this value is used only if the Particles Set has finite life) radius_scale_base, // Particle radius global scale applied during drawing, -Inf..Inf , default=1 (this is the base global scale of all particles radius applied during drawing only) final particle radius value = "Particle.radius * radiusScale()" radius_scale_time; // Particle radius global scale applied during drawing, -Inf..Inf , default=0 (this is the time relative global scale of all particles radius applied during drawing only) final particle radius value = "Particle.radius * radiusScale()" Matrix matrix ; // particle generation matrix , , default=MatrixIdentity (this matrix is used for following source types: PARTICLE_STATIC_SHAPE, PARTICLE_DYNAMIC_MESH) Shape shape ; // particle generation shape , , default=Ball(1) (this shape is used for following source types: PARTICLE_STATIC_SHAPE) Bool inside_shape; // if generate particles inside shape or on its surface, false/true, default=true ImagePtr image ; // particle image UShort image_x_frames, // number of animation frames in image width , 1..65535, default=1 image_y_frames; // number of animation frames in image height, 1..65535, default=1 Flt image_speed ; // image animation speed , 0..Inf , default=1 ImagePtr palette_image; // if specified, then particle colors will be multiplied by this image, x coordinate of the image is based on particle life, y coordinate of the image is taken from 'Particle.palette_y', the mode of this image must be equal to IMAGE_SOFT (to avoid unnecessary locking) Flt hard_depth_offset; // 0..1, default=0, this value is used when particles are not drawn with softing (D.particlesSoft is false or not supported), in that case each particle will be offsetted towards the camera by its radius multiplied by this factor, decreasing the chance of particles being occluded Flt (*opacity_func)(Flt life_frac); // pointer to a custom function (may be null) used to calculate opacity of a single particle, based on its life, if this is null then a default function is used based on 'smooth_fade', this member is not saved in 'save/load' methods, default=null // set / get Flt fade ( )C {return _fade ;} // get current fading value according to 'fade_in fade_out emitter_life_max', this should be used for accessing the fade value of particle sets with finite life (emitter_life_max>0) Flt opacity (Vec *pos=null)C; // get average particles opacity (0..1) and position (this can be useful for example in applying lights basing on particles average opacity and position) Flt radiusScale( )C {return emitter_life*radius_scale_time + radius_scale_base ;} // get current radius scale Bool alive ( )C {return emitter_life_max<=0 || emitter_life ParticlesCache; // Particles Cache inline Int Elms(C Particles &particles) {return particles.p.elms();} /******************************************************************************/ #if EE_PRIVATE void ShutParticles(); #endif /******************************************************************************/