Paticle Systems Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell
Reading Requied: Witkin, Paticle System Dynamics, SIGGRAPH 97 couse notes on Physically Based Modeling. Witkin and Baaff, Diffeential Equation Basics, SIGGRAPH 01 couse notes on Physically Based Modeling. Optional Hocknew and Eastwood. Compute simulation using paticles. Adam Hilge, New Yok, 1988. Gavin Mille. The motion dynamics of snakes and woms. Compute Gaphics 22:169-178, 1988. Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 2
What ae paticle systems? A paticle system is a collection of point masses that obeys some physical laws (e.g, gavity, heat convection, sping behavios, ). Paticle systems can be used to simulate all sots of physical phenomena: Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 3
Paticle in a flow field We begin with a single paticle with: Position, " x = x % # y& y Velocity, v = x = d x dt " dx dt% = # dy dt& g(x,t) Suppose the velocity is actually dictated by some diving function g: x = g( x,t) x Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 4
Vecto fields At any moment in time, the function g defines a vecto field ove x: How does ou paticle move though the vecto field? Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 5
Diff eqs and integal cuves The equation x = g( x,t) is actually a fist ode diffeential equation. We can solve fo x though time by stating at an initial point and stepping along the vecto field: Stat Hee This is called an initial value poblem and the solution is called an integal cuve. Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 6
Eule s method One simple appoach is to choose a time step, Δt, and take linea steps along the flow: x (t + "t) = Witing as a time iteation: x (t) + "t # x(t) = x (t) + "t # g( x,t) x i+1 = x i + "t # v i This appoach is called Eule s method and looks like: Popeties: Simplest numeical method Bigge steps, bigge eos. Eo ~ O(Δt 2 ). Need to take petty small steps, so not vey efficient. Bette (moe complicated) methods exist, e.g., Runge-Kutta and implicit integation. Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 7
Paticle in a foce field Now conside a paticle in a foce field f. In this case, the paticle has: Mass, m Acceleation, a " x = d v dt = d 2 x dt 2 The paticle obeys Newton s law: f = m a = mx The foce field f can in geneal depend on the position and velocity of the paticle as well as time. Thus, with some eaangement, we end up with: f ( x,x,t) x = m Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 8
Second ode equations This equation: x = f ( x,x,t) m is a second ode diffeential equation. Ou solution method, though, woked on fist ode diffeential equations. We can ewite this as: x = v " f ( x, v %,t) v = # m & whee we have added a new vaiable v to get a pai of coupled fist ode equations. Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 9
Phase space " x % # v & " x% # v& " x% " v % = # v& # f m& Concatenate x and v to make a 6- vecto: position in phase space. Taking the time deivative: anothe 6-vecto. A vanilla 1 st -ode diffeential equation. Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 10
Diffeential equation solve Stating with: Applying Eule s method: And making substitutions: " x% " v % = # v& # f m& x (t + "t) = x (t) + "t # x(t) x(t + "t) = x(t) + "t # x(t) x (t + "t) = x (t) + "t # v (t) x(t + "t) = x(t) + "t # f ( x,x,t) m Witing this as an iteation, we have: Again, pefoms pooly fo lage Δt. x i+1 = x i + "t # v i v i+1 = v f i i + "t # m Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 11
Paticle stuctue How do we epesent a paticle?! x " # v # # f # m % & position velocity foce accumulato mass Position in phase space Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 12
Single paticle solve inteface! x " # v # # f # m % & getdim getstate setstate deiveval [ 6]! x" # % v&! v " # /m % f & Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 13
Paticle systems In geneal, we have a paticle system consisting of n paticles to be managed ove time: paticles n time " f 1 # x 1 v 1 m 1 % & " # x 2 v 2 f 2 m 2 % " x n % v n K f n & # & m n Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 14
Paticle system solve inteface Fo n paticles, the solve inteface now looks like: paticles n time get/setstate getdim deiveval 6n x 1 v 1 v 1 f 1 m 1 x 2 v 2 v 2 K x n f 2 K v n m 2 v n f n m n Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 15
Paticle system diff. eq. solve We can solve the evolution of a paticle system again using the Eule method: " M # x 1 i+1 v 1 i+1 x n i+1 v n i+1 % " = M & # x 1 i v 1 i x n i v n i % + (t & " # f 1 i f n i v 1 i M v n i m 1 m n % & Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 16
Foces Each paticle can expeience a foce which sends it on its mey way. Whee do these foces come fom? Some examples: Constant (gavity) Position/time dependent (foce fields) Velocity-dependent (dag) Combinations (Damped spings) How do we compute the net foce on a paticle? Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 17
Paticle systems with foces Foce objects ae black boxes that point to the paticles they influence and add in thei contibutions. We can now visualize the paticle system with foce objects: paticles n time foces nf F 1 F 2 F nf " f 1 # x 1 v 1 m 1 % & " # x 2 v 2 f 2 m 2 % " x n % v n K f n & # & m n Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 18
Gavity and viscous dag The foce due to gavity is simply: f gav = mg p->f += p->m * F->G Often, we want to slow things down with viscous dag: f dag = "k v p->f -= F->k * p->v Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 19
Damped sping Recall the equation fo the foce due to a sping: We can augment this with damping: f = "k sping (# x " ) [ ] f = " k sping (# x " ) + k damp v The esulting foce equations fo a sping between two paticles become: * f 1 = ", k sping +, f 2 = " f 1 # x # ( " ) + k damp & % v # x - # x )/ (./ # x # x = est length " x p 1 = 1 % # v 1 & " x = x 1 # " x p 2 = 2 % # & v 2 x 2 Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 20
deiveval Clea foces Loop ove paticles, zeo foce accumulatos Calculate foces Sum all foces into accumulatos Retun deivatives Loop ove paticles, etun v and f/m " v 1 %" v 2 % " v K n # f 1 m 1 &# f 2 m 2 & # f n m n % & Retun deivatives to solve 1 Apply foces to paticles 3 Clea foce accumulatos Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 21 2 " f 1 # F 1 " f 1 # x 1 v 1 x 1 v 1 m 1 m 1 F 2 F 3 F nf % & % & " # " # x 2 v 2 f 2 x 2 v 2 f 2 m 2 m 2 % " x n % v K n f n & # & m n % " x n % v n K f n & # & m n
Bouncing off the walls P N Add-on fo a paticle simulato Fo now, just simple point-plane collisions A plane is fully specified by any point P on the plane and its nomal N. Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 22
Collision Detection How do you decide when you ve cossed a plane? v P N x Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 23
Nomal and tangential velocity To compute the collision esponse, we need to conside the nomal and tangential components of a paticle s velocity. v N v P N v vt v N = ( N v ) N v T = v " v N Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 24
Collision Response v N "k estitution v N v v T v T " v befoe v " = v T # k estitution v N afte Without backtacking, the esponse may not be enough to bing a paticle to the othe side of a wall. In that case, detection should include a velocity check: Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 25
Paticle fame of efeence Let s say we had ou obot am example and we wanted to launch paticles fom its tip. How would we go about stating the paticles fom the ight place? Fist, we have to look at the coodinate systems in the OpenGL pipeline Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 26
The OpenGL geomety pipeline Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 27
Pojection and modelview matices Any piece of geomety will get tansfomed by a sequence of matices befoe dawing: p = M poject M view M model p The fist matix is OpenGL s GL_PROJECTION matix. The second two matices, taken as a poduct, ae maintained on OpenGL s GL_MODELVIEW stack: M modelview = M view M model Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 28
Robot am code, evisited Recall that the code fo the obot am looked something like: glrotatef( theta, 0.0, 1.0, 0.0 ); base(h1); gltanslatef( 0.0, h1, 0.0 ); glrotatef( phi, 0.0, 0.0, 1.0 ); uppe_am(h2); gltanslatef( 0.0, h2, 0.0 ); glrotatef( psi, 0.0, 0.0, 1.0 ); lowe_am(h3); All of the GL calls hee modify the modelview matix. Note that even befoe these calls ae made, the modelview matix has been modified by the viewing tansfomation, M view. Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 29
Computing paticle launch point To find the wold coodinate position of the end of the obot am, you need to follow a seies of steps: 1. Figue out what M view befoe dawing you model. Mat4f matcam = ps>glgetmatix(gl_modelview_matrix); 2. Daw you model and add one moe tansfomation to the tip of the obot am. 3. Compute gltanslatef( 0.0, h3, 0.0 ); "1 M model = M view M modelview Mat4f paticlexfom = ps->getwoldxfom( matcam); 4. Tansfom a point at the oigin by the esulting matix. Vec4f paticleoigin = paticlexfom * Vec4f(0,0,0,1); // 4 th coodinate should be 1.0 -- ignoe Now you e eady to launch a paticle fom that last computed point! Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 30
Next lectue Topic: Paametic Cuves: C2 intepolating cuves. How can we make splines that intepolate the contol points, and have C2 continuity eveywhee? Reading: Batels, Beatty, and Basky. An Intoduction to Splines fo use in Compute Gaphics and Geometic Modeling, 1987. [Couse eade, pp. 239-247] Univesity of Texas at Austin CS384G - Compute Gaphics Fall 2010 Don Fussell 31