loadsa particles

This commit is contained in:
Dave Griffiths 2009-06-23 08:31:12 +01:00
parent 057656012d
commit c465ec71ae
3 changed files with 232 additions and 133 deletions

View file

@ -38,15 +38,15 @@
(rotate (vector 0 -90 0)))
(else (rotate (vmul (crndvec) 20))))))
(define/public (update)
(define/public (update t)
(for-each
(lambda (child)
(send child update))
(send child update t))
child-twigs)
(when (and (< age size) (< next-ring-time (time)))
(set! next-ring-time (+ (time) speed))
(when (and (< age size) (< next-ring-time t))
(set! next-ring-time (+ t speed))
(let ((p (with-state
(parent root)
(hint-depth-sort)
@ -75,16 +75,84 @@
(super-new)))
(define pickup%
(class object%
(init-field
(pos (vector 0 0 0)))
(field
(col (vmul (rndvec) 0.1))
(root (let ((p (with-state
(translate pos)
(hint-depth-sort)
(blend-mode 'src-alpha 'one)
(texture (load-texture "textures/particle.png"))
(build-particles 20))))
(with-primitive p
(pdata-add "vel" "v")
(pdata-map!
(lambda (vel)
(vmul (vector (crndf) (* 2 (rndf)) (crndf)) 0.02))
"vel")
(pdata-map!
(lambda (s)
(vector 2 2 2))
"s")
(pdata-map!
(lambda (c)
col)
"c"))
p)))
(define/public (get-pos)
pos)
(define/public (update t)
(with-primitive root
(pdata-op "+" "p" "vel")
(pdata-op "*" "c" 0.996)
(pdata-op "*" "s" 1.005)
(when (zero? (random 5))
(let ((reset (random (pdata-size))))
(pdata-set! "c" reset col)
(pdata-set! "p" reset (vector 0 0 0))
(pdata-set! "s" reset (vector 2 2 2))))))
(super-new)))
(define seed%
(class object%
(field
(twigs '())
(pickups (build-list 10 (lambda (_)
(make-object pickup% (vmul (vsub (crndvec) (vector 0 1 0)) 50)))))
(indicator (let ((p (with-state
(hint-depth-sort)
;(blend-mode 'src-alpha 'one )
(texture (load-texture "textures/particle.png"))
(build-particles 200))))
(with-primitive p
(pdata-add "vel" "v")
(pdata-map!
(lambda (vel)
(srndvec))
"vel")
(pdata-map!
(lambda (c)
(vector 0 0 0.1))
"c")
(pdata-map!
(lambda (s)
(let ((sz (rndf)))
(vector sz sz sz)))
"s"))
p))
(debounce #t)
(debounce-time 0)
(pos (vector 0 0 0))
(root (with-state
(scale 5)
(translate (vector 0 0 0))
(translate pos)
(texture (load-texture "textures/skin.png"))
(backfacecull 0)
(opacity 0.6)
@ -100,22 +168,46 @@
(send t build (vector 0 0 0) dir) t) twigs))))
(define/public (update)
(define/public (update t)
(let ((closest (foldl
(lambda (pickup r)
(if (< (vdist (send pickup get-pos) pos)
(vdist pos r))
(send pickup get-pos) r))
(vector 999 999 999)
pickups)))
(with-primitive indicator
(pdata-op "+" "p" "vel")
(when (< (sin (* 2 t)) 0)
(let ((reset (random (pdata-size))))
(let ((pos (vmul (vnormalise (vsub closest pos)) 10)))
(pdata-set! "vel" reset (vadd (vmul (srndvec) 0.01)
(vmul (vsub closest pos) (* (rndf) 0.01))))
(pdata-set! "p" reset pos))))))
(with-primitive root
(scale (+ 1 (* 0.001 (sin (* 2 t))))))
(when (key-pressed "r") (with-primitive camera (parent 1)))
(when (and debounce (key-pressed " "))
(add-twig (vtransform-rot (vector 0 0 1) (minverse (get-camera-transform))))
(set! debounce #f)
(set! debounce-time (+ (time) 1)))
(set! debounce-time (+ t 1)))
(when (> (time) debounce-time)
(when (> t debounce-time)
(set! debounce #t))
(for-each
(lambda (twig)
(send twig update))
twigs))
(send twig update t))
twigs)
(for-each
(lambda (pickup)
(send pickup update t))
pickups))
(super-new)))
@ -125,7 +217,7 @@
(scale 5 )
(translate (vector 0 0 0))
(with-state
(with-state
(texture (load-texture "textures/top.png"))
(translate (vector 0 20 0))
(rotate (vector 90 0 0))
@ -133,7 +225,7 @@
(hint-unlit)
(build-plane))
(with-state
(with-state
(texture (load-texture "textures/left.png"))
(translate (vector 0 0 -20))
(rotate (vector 0 0 0))
@ -141,7 +233,7 @@
(hint-unlit)
(build-plane))
(with-state
(with-state
(texture (load-texture "textures/back.png"))
(translate (vector 20 0 0))
(rotate (vector 0 90 0))
@ -149,7 +241,7 @@
(hint-unlit)
(build-plane))
(with-state
(with-state
(texture (load-texture "textures/right.png"))
(translate (vector 0 0 20))
(rotate (vector 0 0 0))
@ -157,7 +249,7 @@
(hint-unlit)
(build-plane))
(with-state
(with-state
(texture (load-texture "textures/front.png"))
(translate (vector -20 0 0))
(rotate (vector 0 90 0))
@ -165,7 +257,7 @@
(hint-unlit)
(build-plane))
(with-state
(with-state
(texture (load-texture "textures/bottom.png"))
(opacity 0.8)
(hint-depth-sort)
@ -175,9 +267,9 @@
(hint-unlit)
(build-plane))
; soil
; soil
(with-state
(with-state
(texture (load-texture "textures/sback.png"))
(translate (vector 0 -15 -19.99))
(rotate (vector 0 0 0))
@ -185,7 +277,7 @@
(hint-unlit)
(build-plane))
(with-state
(with-state
(texture (load-texture "textures/sleft.png"))
(translate (vector 19.9 -15 0))
(rotate (vector 0 90 0))
@ -193,7 +285,7 @@
(hint-unlit)
(build-plane))
(with-state
(with-state
(texture (load-texture "textures/sfront.png"))
(translate (vector 0 -15 19.9))
(rotate (vector 0 0 0))
@ -201,7 +293,7 @@
(hint-unlit)
(build-plane))
(with-state
(with-state
(texture (load-texture "textures/sright.png"))
(translate (vector -19.9 -15 0))
(rotate (vector 0 90 0))
@ -222,4 +314,11 @@
(fog (vector 0.2 0.5 0.3) 0.01 1 100)
(define s (make-object seed%))
(every-frame (send s update))
(define t 0)
(define (animate)
(send s update t)
(set! t (+ t 0.02)))
(every-frame (animate))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB