MasterScan  Lab_Matlab_control Master Branch
List of all members | Properties and Events | Protected Properties | Methods | Protected Methods | Static Methods
dotsDrawableExplosion Class Reference

Overview

Animate an explosion of many particles.

dotsDrawableExplosion simulates a fireworks-style explosion. It animates multiple particles with constant-acceleration projectile motion. The animation has a few distinct phases:

The explosion and bounce trajectory parameters for each particle are solved during prepareToDrawInWindow(). Frame-by-frame positions are computed for each particle during draw(), based on the current time. An OpenGL vertex shader (explosion.vert by default) implements the projectile calculations.

The algebra used to solve trajectory parameters is on the Snow Dots wiki: http://code.google.com/p/snow-dots/wiki/ExplosionAlgebra

Inheritance diagram for dotsDrawableExplosion:
Inheritance graph
[legend]

Properties and Events

Property vertexShader = 'explosion.vert'
 file name with projectile motion vertex shader source
 
Property xRest = 1
 x-position where each particle should come to rest
 
Property yRest = 1
 y-position where each particle should bounce, then rest
 
Property tRest = 1
 how long it should take each particle to come to rest
 
Property gravity = -1
 constant vertical acceleration for all particles
 
Property bounceDamping = [0.5 -0.5]
 multiplier for particle x and y velocity at each bounce [bX bY]
 
Property whichRoot = 2
 how to choose roots from quadratic solutions More...
 
Property clockFunction
 function that returns the current time as a number
 
Property currentTime
 time of the most recent draw()
 
Property isInternalTime = true
 whether to update currentTime with clockFunction during draw()
 
- Properties and Events inherited from dotsDrawableVertices
Property x = 0
 vertex x-positions (x, y, and z must be scalar or match sizes)
 
Property y = 0
 vertex y-positions (x, y, and z must be scalar or match sizes)
 
Property z = 0
 vertex z-positions (x, y, and z must be scalar or match sizes)
 
Property colors = [1 1 1]
 color map to use for vertices [r g b a; r g b a; etc. More...
 
Property isColorByVertexGroup = false
 whether to color vertices in groups(true) or individually(false)
 
Property indices = []
 array of indices for selecting, reusing, and reordering vertices More...
 
Property pixelSize = 1
 width in pixels for points or lines
 
Property isSmooth = false
 whether to use anti-aliasing for primitives
 
Property primitive = 0
 index to choose OpenGL vertex drawing mode More...
 
Property usageHint = 3
 index to choose usage "hint" for OpenGL buffers More...
 
Property translation = []
 optional translation to apply to vertex positions [tX tY tZ] More...
 
Property rotation = []
 optional rotation of vertices about coordinate axes [rX rY rZ] More...
 
Property scaling = []
 optional scaling to apply to vertex positions [sX sY sZ] More...
 
- Properties and Events inherited from dotsDrawable
Property isVisible = true
 true or false, whether to draw() this object
 

Protected Properties

Property startTime
 zero-time for the beginning of each animation sequence
 
Property programInfo
 identifier and other info for OpenGL shader program
 
Property timeVar
 identifier and other info about the shader time variable
 
Property nBounces = 4
 number of bounces supported by shader program
 
 attribNames
 attribute names for the OpenGL shader program
 
Property attribData
 attribute data calculated in solveParticleSystem()
 
- Protected Properties inherited from dotsDrawableVertices
Property attribBufferInfo = []
 identifier and other info for the OpenGL vertex attribute buffer
 
Property isAttribBufferStale = true
 whether or not the attribute buffer is out of date
 
Property indexBufferInfo = []
 identifier and other info for the OpenGL vertex index buffer
 
Property isIndexBufferStale = true
 whether or not the index buffer is out of date
 
Property colorBufferInfo = []
 identifier and other info for the OpenGL vertex color buffer
 
Property isColorBufferStale = true
 whether or not the color buffer is out of date
 
Property smoothMap
 map primitive integers to dotsMglSmoothness() switches
 

Methods

self dotsDrawableExplosion ()
 Constructor takes no arguments.
 
 delete (self)
 Release OpenGL resources.
 
 set_xRest (self, xRest)
 Keep track of required buffer updates.
 
 set_yRest (self, yRest)
 Keep track of required buffer updates.
 
 set_tRest (self, tRest)
 Keep track of required buffer updates.
 
 set_bounceDamping (self, bounceDamping)
 Keep track of required buffer updates.
 
 set_gravity (self, gravity)
 Keep track of required buffer updates.
 
 set_whichRoot (self, whichRoot)
 Keep track of required buffer updates.
 
tRestMins calculateMinimumRestTimes (self)
 Determine minimum resting times, based on system properties. More...
 
 solveParticleSystem (self)
 Compute motion parameters for each particle and each bounce.
 
 prepareToDrawInWindow (self)
 Solve particle trajectores into buffers and load shader program.
 
 draw (self)
 Draw particles, based on the current time.
 
nVertices getNVertices (self)
 Calculate number of vertices based on several properties;.
 
- Methods inherited from dotsDrawableVertices
self dotsDrawableVertices ()
 Constructor takes no arguments.
 
 delete (self)
 Release OpenGL resources. More...
 
 set_x (self, x)
 Keep track of required buffer updates.
 
 set_y (self, y)
 Keep track of required buffer updates.
 
 set_z (self, z)
 Keep track of required buffer updates.
 
 set_indices (self, indices)
 Keep track of required buffer updates.
 
 set_colors (self, colors)
 Keep track of required buffer updates.
 
 set_isColorByVertexGroup (self, isColorByVertexGroup)
 Keep track of required buffer updates.
 
nVertices getNVertices (self)
 Calculate number of vertices from x, y, and z.
 
 prepareToDrawInWindow (self)
 Create fresh OpenGL buffer objects.
 
 draw (self)
 Draw vertices from OpenGL buffer objects.
 
- Methods inherited from dotsDrawable
self dotsDrawable ()
 Constructor takes no arguments.
 
 prepareToDrawInWindow (self)
 Do any pre-draw setup that requires an OpenGL drawing window.
 
 mayDrawNow (self)
 Draw() or not, depending on isVisible and possibly other factors.
 
 draw (self)
 Subclass must redefine draw() to draw graphics.
 
 show (self)
 Shorthand to set isVisible=true.
 
 hide (self)
 Shorthand to set isVisible=false.
 

Protected Methods

 deleteAttribBuffer (self)
 Release OpenGL vertex buffer for each attribNames.
 
 updateAttribBuffer (self)
 Write OpenGL vertex buffer data for each attribNames.
 
 loadShaderProgram (self)
 Load the shader program which makes particles explode.
 
 selectBuffers (self)
 Bind buffers for drawing.
 
 deselectBuffers (self)
 Unbind buffers for drawing.
 
- Protected Methods inherited from dotsDrawableVertices
 deleteBuffers (self)
 Release OpenGL buffer handles and memory.
 
 updateBuffers (self)
 Write attribute, color, and index data to buffers, as needed.
 
 deleteAttribBuffer (self)
 Release OpenGL vertex attribute resources.
 
 updateAttribBuffer (self)
 Write new vertex attributes to OpenGL buffer(s).
 
 deleteIndexBuffer (self)
 Release OpenGL vertex index resources.
 
 updateIndexBuffer (self)
 Write new vertex indices to OpenGL buffer(s).
 
 deleteColorBuffer (self)
 Release OpenGL vertex color resources.
 
 updateColorBuffer (self)
 Write new vertex colors to OpenGL buffer(s).
 
groupIndices getVertexGroupIndices (self)
 Get an arbitrary 1-based group index for each vertex.
 
buffer overwriteOrReplaceBuffer (self, oldBuffer, data, target, elementsPerVertex)
 Modify or replace a buffer with new data.
 
 selectBuffers (self)
 Bind buffers for drawing.
 
 deselectBuffers (self)
 Unbind buffers for drawing.
 
 flagAllBuffersAsStale (self)
 Mark all OpenGL buffers as stale.
 

Static Methods

static roots solveQuadratic (aCoef, bCoef, cCoef)
 Solve roots of a quadratic, given coefficients.
 
- Static Methods inherited from dotsDrawable
static frameInfo drawFrame (drawables, doClear)
 draw() several drawable objects and show the next Screen frame. More...
 
static ensemble makeEnsemble (name, objects)
 Convenient utility for combining a bunch of drawables into an ensemble. More...
 
static frameInfo drawEnsemble (ensemble, args, prepareFlag, showDuration, pauseDuration)
 Convenient utility for drawing an ensemble either locally or remotely. More...
 

Methods

◆ calculateMinimumRestTimes()

tRestMins calculateMinimumRestTimes ( self  )

Determine minimum resting times, based on system properties.

Several parameters affect how long each particle requires to fall to the ground and bounce. Together they impose a minimum duration for particle bouncing. Smaller times for tRest would be impossible to achieve.

Intuituvely, a particle starting with zero y-velocity should require the least time–adding upward or downward velocity would add energy to the system and causes larger bounces. calculateMinimumRestTimes() assumes zero starting velocity and calculates the corresponding time to complete all bounces.

Properties and Events

◆ whichRoot

Property whichRoot = 2

how to choose roots from quadratic solutions

Solving for velocities yields two solutions. The first tends to slam paricles against the ground and makes them bounce high. The second tends to toss particles gently in the air. Either way, particles end up in the same place.


The documentation for this class was generated from the following file: