building a particle system
DESCRIPTION
Building a Particle System. References: 1. Gamasutra article by Van der Berg 2. Particle System API by McAllister 3. Explosion.c. Particle System (PS) Gallery. Performance and Requirement. - PowerPoint PPT PresentationTRANSCRIPT
Building a Particle System
References:1. Gamasutra article by Van der Berg2. Particle System API by McAllister3. Explosion.c
Fall 2009 2
Particle System (PS) Gallery
Fall 2009 3
Fall 2009 4
Fall 2009 5
Fall 2009 6
Fall 2009 7
Fall 2009 8
Fall 2009 9
Fall 2009 10
Performance and Requirement
Keep in mind: a PS greatly increases the number of polygon per frame (one particle: four vertices & 2 triangles)Perform as few memory operations (allocation/release) as possible Use a flag to mark a particle dead or respawn
Ability to link PS within the hierarchy of other geometry (smoke out of a cigarette)
Fall 2009 11
Data Structure
Reference 1 contains all other detailsReference 1 contains all other details
Fall 2009 12
Explosion
A simple particle system demo for explosion effects (particles and debris)Observe how particle evolves and how debris rotates
Fall 2009 13
Particle System API (McAllister)
API used in some academic projectsDesign modeled after OpenGLDesign goals: Run-time efficiency Flexibility: create effects from simple
building blocks (gravity, bounce, …) Scalable simulation quality Easy to learn
Fall 2009 14
API Description
Particle Position Velocity Color Alpha Size Age Secondary position Secondary velocity
Particle group A set of particles acted
upon by the same forces API applies to the
current group
Action Functions modify the
attributes of particles in the current group
Currently has 27 actions (some are physically related)
Building blocks for special effects
Fall 2009 15
Actions in Use
ActionList Actions compiled (si
milar to displaylist)
Fall 2009 16
Attributes and Domains
API state (color, velocity, size, …)pSource: create new particles
Domain: a uniform mechanism for specifying a region of three-space
pColorD: a region of color space
pVelocityD: a region of vector space
A variety of shapes: PDSphere, PDPlane, …
Specified by 9 or fewer floats
Fall 2009 17
Particle Simulation
Newton’s lawUse Euler’s method with user-specified step size dt
Fall 2009 18
Design a PS that suits your needs
Starting posBreaking posTimeline: ADSR envelopeColor attributesRendering styleDynamics
PAPI (v.210)
You need VC80!Uses freeglut
Fall 2009 20
Particle Data Structure
Fall 2009 21
Example: ParticleContext_t PGenParticleGroups
P_group_count Max_particles (similar to display list)
CurrentGroup Current particle group all
actions and commands apply
SetMaxParticlesGetGroupCount
# of particles in the groupGetParticlePointer
Expose internal storage of particles (avoid copying for higher performance)
Fall 2009 22
GetParticlePointer
Fall 2009 23
ParticleContext_t P
GravityMove (vel, rotvel)
Update pos, orient (up vector)
P.Source (rate, dom) Particles to add per unit
timeP.Sink (inOrOut, dom)
Kill particles w.r.t dom
Bounce (friction, resilience, cutoff, dom)
Sphere, rectangle, triangle disc, plane
Color (rgb); Color(dom)
Translate pos into color
Velocity (dom) …
Fall 2009 24
pDomain
Blob, Box, Cone, Cylinder, Disc, Line, Plane, Point, Rectangle, Sphere, Triangle