! Copyright (C) 2010 Erik Charlebois.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays classes.struct destructors game.loop
-game.worlds gpu gpu.buffers gpu.effects.blur gpu.framebuffers
-gpu.render gpu.shaders gpu.state gpu.textures gpu.util images
-images.loader kernel literals locals make math math.rectangles
-math.vectors namespaces opengl.gl sequences specialized-arrays
-ui.gadgets.worlds ui.gestures ui.pixel-formats gpu.effects.step
-images.pgm images.ppm ;
+USING: accessors alien.data classes.struct destructors game.loop
+game.worlds gpu gpu.effects.blur gpu.effects.step gpu.state
+gpu.textures gpu.util images.loader kernel literals make math
+math.vectors namespaces sequences specialized-arrays
+ui.gadgets.worlds ui.gestures ui.pixel-formats ;
FROM: alien.c-types => float ;
SPECIALIZED-ARRAY: float
IN: fluids
particle [ p>> ] [ v>> ] bi dt v*n v+
gravity dt dt * particle m>> 2 * / v*n v+ :> p'
p' particle p>> v- dt v/n :> v'
- p' v' particle m>> particle_t <struct-boa> ; inline
+ p' v' particle m>> particle_t boa ; inline
CONSTANT: initial-particles
particle_t-array{
S{ particle_t f float-array{ 0.5 0.6 } float-array{ 0 0.1 } 1.0 }
S{ particle_t f float-array{ 0.5 0.6 } float-array{ 0.1 0 } 3.0 }
-
+
S{ particle_t f float-array{ 0.5 0.5 } float-array{ 0.1 0.1 } 2.0 }
S{ particle_t f float-array{ 0.5 0.6 } float-array{ -0.1 0 } 1.0 }
S{ particle_t f float-array{ 0.6 0.5 } float-array{ 0 -0.1 } 3.0 }
<texture-2d>
]
[
- 0 swap [ allocate-texture-image ] 3keep 2drop
+ 0 swap [ allocate-texture-image ] keepdd
] bi ;
SYMBOL: fluid
: integrate ( world -- )
- particles>> $[ 60 fps 1000000 /f ] integrate-particles! drop ;
+ particles>> 1/60 integrate-particles! drop ;
: pause ( -- )
fluid get [ not ] change-paused drop ;
world particles>> [
[ p>> [ first , ] [ second , ] bi ] each
] curry float-array{ } make :> verts
-
- [
+
+ [
verts world texture>> 30.0 world dim>> { 4 4 } v/
blended-point-sprite-batch &dispose
blend-state new set-gpu-state
{ pixel-format-attributes {
windowed double-buffered T{ depth-bits { value 24 } } } }
{ pref-dim { 1024 768 } }
- { tick-interval-micros $[ 60 fps ] }
+ { tick-interval-nanos $[ 60 fps ] }
} ;
fluids-world H{
{ T{ button-down } [ [
- hand-loc get >float-array
- world get dim>> >float-array v/ 2 v*n 1 v-n { 1 -1 } v*
- float-array{ 0 0.2 } 2.0 particle_t <struct-boa> suffix
+ hand-loc get float >c-array
+ world get dim>> float >c-array v/ 2 v*n 1 v-n { 1 -1 } v*
+ float-array{ 0 0.2 } 2.0 particle_t boa suffix
] change-particles drop ] }
} set-gestures