]> git.jsancho.org Git - gacela.git/commitdiff
Function for update one particle engine-draft
authorJavier Sancho <jsf@jsancho.org>
Sun, 26 Jun 2016 08:32:14 +0000 (10:32 +0200)
committerJavier Sancho <jsf@jsancho.org>
Sun, 26 Jun 2016 08:32:14 +0000 (10:32 +0200)
examples/particle-system.scm

index 2b2c1b52d331484b480754b8e405d3b659b20185..a0d659a842f2f703be492cb05a4bc149e6839a9a 100644 (file)
          (draw-quad (list x y z) #:color (list r g b))))))
    particles))
 
+(define (update-particle particle)
+  (match particle
+    ((x y z vx vy vz)
+     (let* ((distance-squared (+ (* x x) (* y y) (* z z)))
+           (distance (sqrt distance-squared))
+           (F (/ -200 distance-squared))
+           (ax (* F (/ x distance)))
+           (ay (* F (/ y distance)))
+           (az (* F (/ z distance))))
+       (list (+ x (* vx dt) (* ax half-dt-squared))
+            (+ y (* vy dt) (* ay half-dt-squared))
+            (+ z (* vz dt) (* az half-dt-squared))
+            (+ vx (* ax dt))
+            (+ vy (* ay dt))
+            (+ vz (* az dt)))))))
+
 (define (update-particles dt)
   (let ((half-dt-squared (* 0.5 dt dt)))
     (set! *particles*
-      (map
-       (lambda (particle)
-        (match particle
-          ((x y z vx vy vz)
-           (let* ((distance-squared (+ (* x x) (* y y) (* z z)))
-                  (distance (sqrt distance-squared))
-                  (F (/ -200 distance-squared))
-                  (ax (* F (/ x distance)))
-                  (ay (* F (/ y distance)))
-                  (az (* F (/ z distance))))
-             (list (+ x (* vx dt) (* ax half-dt-squared))
-                   (+ y (* vy dt) (* ay half-dt-squared))
-                   (+ z (* vz dt) (* az half-dt-squared))
-                   (+ vx (* ax dt))
-                   (+ vy (* ay dt))
-                   (+ vz (* az dt)))))))
-       *particles*))))
+      (map update-particle *particles*))))
 
 (define (prepare-particles n)
   (cond ((= n 0)