Créer une présentation
Télécharger la présentation

Télécharger la présentation
## Computer Science 385.3

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Computer Science 385.3**Term 1, 2006 Tutorial 3 Assignment 4 – Special Effects**Assignment 4 – Special Effects**Implement Special Effects for your virtual world. A Few Options: -Particle Systems -Spring-Mass System -L-Systems, Fractals -Advanced Geometry (NURBs) -True Transparancy -Shadows**Assignment 4 – Special Effects**Particle Systems: -Simple animations can simulate many effects. -Demos: fireworks, ParticleCannon -Store information on a set of particles, and use some sort of simulation to move them through the world. particle { vector position; // current x,y,z position vector velocity; // current direction of particle vector force; // the force acting on the particle. int alive; // indicates how long particle has been active int lifespan; // indicates how long particle will exist float mass; // mass of particle, useful for calculations rgb color; // color of the particle. }**Assignment 4 – Special Effects**Particle Systems: -Must use some sort of integration to simulate the motion of the particles. Euler integration should be called at each timestep: euler_update() { for each particle { currentParticle.position += timestep * currentParticle.velocity; currentParticle.velocity += timestep * currentParticle.force/mass; } }**Assignment 4 – Special Effects**Particle Systems: -Can use different sets of dynamics to apply force to the particles, in order to simulate effects like ballistic motion, spreading, anti-gravity, or many more. Perform Ballistic Motion at each timestep: ballistic_motion() { for each particle {particle.age += timestep; if (particle.age > particle.lifespan) { expire(particle); } else { Apply gravity to the particle. } } }**Assignment 4 – Special Effects**Particle Systems: Can achieve a wide variety of effects, including: -Rain -Snow -Fountains -Sparks -Smoke -Spring-Mass -Demos: particle**Assignment 4 – Special Effects**Spring-Mass System: -Specific instance of a particle system where the particles are treated as masses that are attached together by springs. Can be used to model cloth, bone structures, etc. -Demo: springs spring { float k; // spring constant float restLength; // rest length of the spring } The attached spring will apply forces on the masses at both ends. Equation: Spring Force = -k * distance (distance from rest position).**Assignment 4 – Special Effects**Spring-Mass System: -Use a different set of dynamics to calculate the forces on each mass, based on the spring values. spring_motion() { for each spring { // find the distance between the two masses; vector difference = vector_difference(mass1.position, mass2.position); float length = vector_length(difference); force = -1*currentSpring.k * (length – currentSpring.restLength); // normalize the difference vector to find out amount in each x,y component. normalize(difference); mass1.force += difference * force; } euler_update(); damping(); }**Assignment 4 – Special Effects**L-Systems: Replacement grammars that have proven effective in modeling trees and other plantlife. Similar to Turtle Graphics (Logo), can map tokens to drawing primitives, such as lines. -Demo: lsys Tokens can include: F : move a set distance in the current direction. +/- : change current direction a set angle. @/# : change current angle in 3-dimensions. [/] : push/pop current state on the stack**Assignment 4 – Special Effects**L-Systems: L-Systems also require replacement rules, which are all applied simultaneously to the current string of tokens. Probabilities and random values can be used to determine which rule is used when more than one applies. Replacement Rules could include: F -> FF- F -> F[-F][F][+F] -Demo: Trees**Assignment 4 – Special Effects**Advanced Geometry: Can specify parametric equations for curves in order to achieve better control and aesthetic qualities. There are other more advanced curves, such as splines, bezier curves and NURBs that use a combination of endpoints and control points to achieve smooth curves. -OpenGL provides some functionality for these features; see the notes for further details. -Demo: splines**Assignment 4 – Special Effects**True Transparency: By default, OpenGL's depth test will cull occluded objects and ensure that only the nearest polygons are displayed. Transparency can be achieved by pulling information out of the depth buffer and blending color information from all objects at a specific location. This blending function is based on the transparency of the occluding polygons.**Assignment 4 – Special Effects**Shadows: Z-Buffer is notoriously poor for providing support for shadows; only hard shadows can be achieved. OpenGL offers this functionality using the stencil buffer. -Demo: Shadows