Particle Systems - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Particle Systems

Description:

Fog. Weapon Effects. Impact Effectsa. Definition ... http://www.javaworld.com/javaworld/jw-05-2006/jw-0529-funandgames.html?page =1 ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 24
Provided by: rahulma7
Category:

less

Transcript and Presenter's Notes

Title: Particle Systems


1
Particle Systems
  • CS 536
  • Rahul Malhotra

2
Effects
3
History Spacewar (1962)
4
History Asteroids (1978)
5
History Star Trek II (1983)
6
Uses of Particle Systems
  • Explosions
  • Smoke
  • Fog
  • Weapon Effects
  • Impact Effectsa

7
Definition
  • A particle system is a collection of a number of
    individual elements or particles.
  • Particle systems control a set of particles that
    act autonomously but share some common
    attributes.

8
Basic Particle System Physics
  • Particle is a point in 3D space.
  • Forces (e.g. gravity or wind) accelerate a
    particle.
  • Acceleration changes velocity.
  • Velocity changes position

9
Attributes of a Particle
  • Position
  • Velocity
  • Life Span
  • Size
  • Weight
  • Representation
  • Color
  • Owner

10
Attributes of a Particle System
  • Particle List
  • Position
  • Emission Rate
  • Forces
  • Current State
  • Blending
  • Representation

11
Methods of a particle system
  • Initialize
  • Update
  • Render
  • Move
  • Get/Set force

12
Implementation - Particle
  • struct Particle
  • Vector3 m_pos // current position
    of the particle
  • Vector3 m_prevPos // last position of
    the particle
  • Vector3 m_velocity // direction and
    speed
  • Vector3 m_acceleration // acceleration
  • float m_energy // determines how
    long the particle is alive
  • float m_size // size of particle
  • float m_sizeDelta // amount to change
    the size over time
  • float m_weight // determines how
    gravity affects the particle
  • float m_weightDelta // change over time
  • float m_color4 // current color of
    the particle
  • float m_colorDelta4 // how the color
    changes with time

13
Implementation - Particle System
  • class ParticleSystem
  • public
  • ParticleSystem(int maxParticles, Vector3
    origin)
  • // abstract functions
  • virtual void Update(float elapsedTime) 0
  • virtual void Render() 0
  • virtual int Emit(int numParticles)
  • virtual void InitializeSystem()
  • virtual void KillSystem()
  • protected
  • virtual void InitializeParticle(int index)
    0
  • Particle m_particleList // particles for
    this emitter
  • int m_maxParticles // maximum number
    of particles in total
  • int m_numParticles // indicies of all
    free particles
  • Vector3 m_origin // center of the
    particle system
  • float m_accumulatedTime //track when
    waslast particle emitted
  • Vector3 m_force // force (gravity,
    wind, etc.) acting on the particle system

14
How to represent particles?
  • Points
  • Lines
  • Texture-mapped quads
  • Point Sprites

15
Render Particles as Points
  • glBegin( GL_POINTS )
  • glVertex3f( m_position.x, m_position.y,
    m_position.z )
  • glEnd()

16
Render Partices as Lines
  • glBegin(GL_LINES)
  • glColor4f( r, g, b, 0.1f )
  • glVertex3f(m_position.x, m_position.y,
    m_position.z)
  • glColor4f( r, g, b, a )
  • glVertex3f(m_position.x m_direction.x,
  • m_position.y m_direction.y,
  • m_position.z m_direction.z)
  • glEnd()

17
Render Particles as Quads
  • glBegin(GL_TRIANGLE_FAN)
  • if(textured)
  • glTexCoord2f(0.0f, 0.0f)
  • glVertex3f(pts0.x, pts0.y, pts0.z)
  • if(textured)
  • glTexCoord2f(1.0f, 0.0f)
  • glVertex3f(pts1.x, pts1.y, pts1.z)
  • if(textured)
  • glTexCoord2f(1.0f, 1.0f)
  • glVertex3f(pts2.x, pts2.y, pts2.z)
  • if(textured)
  • glTexCoord2f(0.0f, 1.0f)
  • glVertex3f(pts3.x, pts3.y, pts3.z)
  • glEnd()

18
Render Particles as Point Sprites
  • glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE,
    GL_TRUE)
  • glEnable(GL_POINT_SPRITE)
  • glBegin( GL_POINTS )
  • glVertex3f( m_position.x, m_position.y,
    m_position.z )
  • glEnd()
  • glDisable(GL_POINT_SPRITE)

19
Point Sprites vs Textured Quads
  • Point Sprites dissappear suddenly
  • Cannot rotate a point.
  • Point sprites are not supported in older cards.
  • Point sprite size is dependent on available
    OpenGL point sizes.

20
Snowstorm - Demo
21
Particle Systems API 2.0
  • Free Particle System
  • Much lighter than a full physics engine
  • Simulations of groups of moving objects
    explosion, bounce, etc.
  • Download from www.particlesystems.org
  • Demo

22
Advanced Topics
  • Adding Scripting capability
  • Particle Systems Manager
  • Improving Particle Systems with the GPU

23
Refernces
  • More OPENGL Game Programming Dave Astle
  • http//www.particlesystems.org/
  • http//www.2ld.de/gdc2007/EverythingAboutParticleE
    ffectsSlides.pdf
  • www.evl.uic.edu/aej/527/lecture05.html
  • mit.edu/groups/el/projects/spacewar/
  • http//www.mirwin.net/
  • http//www.javaworld.com/javaworld/jw-05-2006/jw-0
    529-funandgames.html?page1
Write a Comment
User Comments (0)
About PowerShow.com