Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] Diff of /trunk/sml3d/src/particles/particles.sml
ViewVC logotype

Diff of /trunk/sml3d/src/particles/particles.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1007, Sun Jan 16 17:00:40 2011 UTC revision 1008, Sun Jan 16 17:04:08 2011 UTC
# Line 23  Line 23 
23      (***** DOMAINS *****)      (***** DOMAINS *****)
24    
25      type 'a var = 'a PSV.var      type 'a var = 'a PSV.var
26      datatype domain      datatype 'a domain
27        = D_POINT of vec3f var        = D_POINT of 'a var
28        | D_LINE of {pt1: vec3f var, pt2: vec3f var}        | D_LINE of {pt1: 'a var, pt2: 'a var}
29        | D_TRIANGLE of {pt1: vec3f var, pt2: vec3f var, pt3: vec3f var}        | D_TRIANGLE of {pt1: 'a var, pt2: 'a var, pt3: 'a var}
30        | D_PLANE of {pt: vec3f var, normal: vec3f var}        | D_PLANE of {pt: 'a var, normal: 'a var}
31        | D_RECT of {pt: vec3f var, htvec: vec3f var, wdvec: vec3f var}        | D_RECT of {pt: 'a var, htvec: 'a var, wdvec: 'a var}
32        | D_BOX of {min: vec3f var, max: vec3f var}        | D_BOX of {min: 'a var, max: 'a var}
33        | D_SPHERE of {center: vec3f var, irad: vec3f var, orad: vec3f var}        | D_SPHERE of {center: 'a var, irad: 'a var, orad: 'a var}
34        | D_CYLINDER of {pt1: vec3f var, pt2: vec3f var, irad: float var, orad: float var}        | D_CYLINDER of {pt1: 'a var, pt2: 'a var, irad: float var, orad: float var}
35        | D_CONE of {pt1: vec3f var, pt2: vec3f var, irad: float var, orad: float var}        | D_CONE of {pt1: 'a var, pt2: 'a var, irad: float var, orad: float var}
36        | D_BLOB of {center: vec3f var, stddev: float var}        | D_BLOB of {center: 'a var, stddev: float var}
37        | D_DISC of {pt: vec3f var, normal: vec3f var, irad: float var, orad: float var}        | D_DISC of {pt: 'a var, normal: 'a var, irad: float var, orad: float var}
38    
39    (* get the free variables of a domain *)    (* get the free variables of a domain *)
40      fun fvsOfDomain (D_POINT x) = VSet.singleton x      fun fvsOfDomain (D_POINT x) = VSet.singleton x
# Line 66  Line 66 
66      fun blob {center, stddev} = D_BLOB{center=center, stddev=stddev}      fun blob {center, stddev} = D_BLOB{center=center, stddev=stddev}
67      fun disc {center, normal, irad, orad} =      fun disc {center, normal, irad, orad} =
68        D_DISC{pt=center, normal=normal, irad=irad, orad=orad}        D_DISC{pt=center, normal=normal, irad=irad, orad=orad}
69        fun range r = box r
70    
71    
72    (***** ACTIONS *****)    (***** ACTIONS *****)
# Line 76  Line 77 
77       * now. The specific direction and amount of turn is dependent on the kind of domain being       * now. The specific direction and amount of turn is dependent on the kind of domain being
78       * avoided.       * avoided.
79       *)       *)
80        = AVOID of domain        = AVOID of vec3f domain
81      (* Particles are tested to see whether they will pass from being outside the specified domain to      (* Particles are tested to see whether they will pass from being outside the specified vec3f domain to
82       * being inside it if the next Move() action were to occur now. If they would pass through the       * being inside it if the next Move() action were to occur now. If they would pass through the
83       * surface of the domain, they are instead bounced off it. That is, their velocity vector is       * surface of the vec3f domain, they are instead bounced off it. That is, their velocity vector is
84       * decomposed into components normal to the surface and tangent to the surface. The direction of       * decomposed into components normal to the surface and tangent to the surface. The direction of
85       * the normal component is reversed, and friction, resilience and cutoff are applied to the       * the normal component is reversed, and friction, resilience and cutoff are applied to the
86       * components. They are then recomposed into a new velocity heading away from the surface.       * components. They are then recomposed into a new velocity heading away from the surface.
87       *)       *)
88        | BOUNCE of {friction : float PSV.var, resilience : float PSV.var, cutoff : float PSV.var, d : domain}        | BOUNCE of {friction : float PSV.var, resilience : float PSV.var, cutoff : float PSV.var, d : vec3f domain}
89      (* If a particle's velocity magnitude is within vlow and vhigh, then multiply each component of      (* If a particle's velocity magnitude is within vlow and vhigh, then multiply each component of
90       * the velocity by the respective damping constant. Typically, the three components of damping       * the velocity by the respective damping constant. Typically, the three components of damping
91       * will have the same value.       * will have the same value.
# Line 111  Line 112 
112       * each time step.       * each time step.
113       *)       *)
114        | ACCEL of float PSV.var        | ACCEL of float PSV.var
115      (* For each particle within the jet's domain of influence, dom, Jet chooses an acceleration      (* For each particle within the jet's vec3f domain of influence, dom, Jet chooses an acceleration
116       * vector from the domain acc and applies it to the particle's velocity.       * vector from the vec3f domain acc and applies it to the particle's velocity.
117       *)       *)
118        | JET        | JET
119      (*  Removes all particles older than age_limit. But if kill_less_than is true, it instead      (*  Removes all particles older than age_limit. But if kill_less_than is true, it instead
# Line 139  Line 140 
140       * particle in the vector direction.       * particle in the vector direction.
141       *)       *)
142        | ORBITPOINT        | ORBITPOINT
143      (* For each particle, chooses an acceleration vector from the specified domain and adds it to      (* For each particle, chooses an acceleration vector from the specified vec3f domain and adds it to
144       * the particle's velocity. Reducing the time step, dt, will make a higher probability of being       * the particle's velocity. Reducing the time step, dt, will make a higher probability of being
145       * near the original velocity after unit time. Smaller dt approach a normal distribution of       * near the original velocity after unit time. Smaller dt approach a normal distribution of
146       * velocity vectors instead of a square wave distribution.       * velocity vectors instead of a square wave distribution.
147       *)       *)
148        | RANDOMACCEL of domain        | RANDOMACCEL of vec3f domain
149      (* Chooses a displacement vector from the specified domain and adds it to the particle's      (* Chooses a displacement vector from the specified vec3f domain and adds it to the particle's
150       * position. Reducing the time step, dt, will make a higher probability of being near the       * position. Reducing the time step, dt, will make a higher probability of being near the
151       * original position after unit time. Smaller dt approach a normal distribution of particle       * original position after unit time. Smaller dt approach a normal distribution of particle
152       * positions instead of a square wave distribution.       * positions instead of a square wave distribution.
153       *)       *)
154        | RANDOMDISP of domain        | RANDOMDISP of vec3f domain
155      (* For each particle, sets the particle's velocity vector to a random vector in the specified      (* For each particle, sets the particle's velocity vector to a random vector in the specified
156       * domain. This function is not affected by dt.       * vec3f domain. This function is not affected by dt.
157       *)       *)
158        | RANDOMVEL of domain        | RANDOMVEL of vec3f domain
159    (* Computes each particle’s speed (the magnitude of its velocity vector) and if it is less than    (* Computes each particle’s speed (the magnitude of its velocity vector) and if it is less than
160     * min_speed or greater than max_speed the velocity is scaled to within those bounds, while     * min_speed or greater than max_speed the velocity is scaled to within those bounds, while
161     * preserving the velocity vector’s direction.     * preserving the velocity vector’s direction.
# Line 188  Line 189 
189    
190      datatype cond      datatype cond
191        (* Tests whether or not the particle is within the given domain. *)        (* Tests whether or not the particle is within the given domain. *)
192        = WITHIN of domain        = WITHIN of vec3f domain
193        | WITHINVEL of domain        | WITHINVEL of vec3f domain
194        (* ... *)        (* ... *)
195    
196      datatype combinator      datatype combinator
# Line 209  Line 210 
210    
211      val nop = PSAE{action=[], vars=VSet.empty}      val nop = PSAE{action=[], vars=VSet.empty}
212    
213      fun within {d : domain, thenStmt : action, elseStmt : action} = let      fun within {d : vec3f domain, thenStmt : action, elseStmt : action} = let
214        val PSAE{action=elseAct, vars=elseVars} = elseStmt        val PSAE{action=elseAct, vars=elseVars} = elseStmt
215        val PSAE{action=thenAct, vars=thenVars} = thenStmt        val PSAE{action=thenAct, vars=thenVars} = thenStmt
216       in       in
# Line 224  Line 225 
225      in      in
226      fun avoid {      fun avoid {
227            magnitude : float PSV.var, epsilon : float PSV.var,            magnitude : float PSV.var, epsilon : float PSV.var,
228            lookAhead : float PSV.var, d : domain            lookAhead : float PSV.var, d : vec3f domain
229          } = mkAct(VSet.addList(fvsOfDomain(d), [magnitude, epsilon, lookAhead]), [AVOID d])          } = mkAct(VSet.addList(fvsOfDomain(d), [magnitude, epsilon, lookAhead]), [AVOID d])
230      fun bounce {      fun bounce {
231            friction : float PSV.var, resilience : float PSV.var,            friction : float PSV.var, resilience : float PSV.var,
232            cutoff : float PSV.var, d : domain            cutoff : float PSV.var, d : vec3f domain
233          } = mkAct(VSet.addList(fvsOfDomain(d), [friction, resilience, cutoff]),          } = mkAct(VSet.addList(fvsOfDomain(d), [friction, resilience, cutoff]),
234                    [BOUNCE {friction = friction, resilience = resilience, cutoff = cutoff, d  = d}]                    [BOUNCE {friction = friction, resilience = resilience, cutoff = cutoff, d  = d}]
235              )              )
# Line 318  Line 319 
319    
320      datatype emitter = EMIT of {      datatype emitter = EMIT of {
321          maxNum : int PSV.var,          maxNum : int PSV.var,
322          posDomain : domain,          posDomain : vec3f domain,
323          velDomain : domain,          velDomain : vec3f domain,
324          colDomain : domain,          colDomain : vec3f domain,
325          vars : VSet.set          vars : VSet.set
326        }        }
327    

Legend:
Removed from v.1007  
changed lines
  Added in v.1008

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0