]> gitweb.factorcode.org Git - factor.git/commitdiff
add gratuitous audio to gpu.demos.raytrace
authorJoe Groff <arcata@gmail.com>
Wed, 20 Jan 2010 01:41:05 +0000 (17:41 -0800)
committerJoe Groff <arcata@gmail.com>
Wed, 20 Jan 2010 01:54:25 +0000 (17:54 -0800)
extra/gpu/demos/raytrace/green-ball.aiff [new file with mode: 0644]
extra/gpu/demos/raytrace/mirror-ball.aiff [new file with mode: 0644]
extra/gpu/demos/raytrace/raytrace.factor
extra/gpu/demos/raytrace/red-ball.aiff [new file with mode: 0644]
extra/gpu/demos/raytrace/yellow-ball.aiff [new file with mode: 0644]
extra/gpu/util/wasd/wasd.factor

diff --git a/extra/gpu/demos/raytrace/green-ball.aiff b/extra/gpu/demos/raytrace/green-ball.aiff
new file mode 100644 (file)
index 0000000..2ccf57e
Binary files /dev/null and b/extra/gpu/demos/raytrace/green-ball.aiff differ
diff --git a/extra/gpu/demos/raytrace/mirror-ball.aiff b/extra/gpu/demos/raytrace/mirror-ball.aiff
new file mode 100644 (file)
index 0000000..23aa009
Binary files /dev/null and b/extra/gpu/demos/raytrace/mirror-ball.aiff differ
index fd8ae6b157911d5b30257073e782d535dbc5a770..53e8c63ddf378edac444a553fec7b523ea3409a2 100644 (file)
@@ -3,7 +3,7 @@ USING: accessors arrays combinators.tuple game.loop game.worlds
 generalizations gpu gpu.render gpu.shaders gpu.util gpu.util.wasd
 kernel literals math math.matrices math.order math.vectors
 method-chains sequences ui ui.gadgets ui.gadgets.worlds
-ui.pixel-formats ;
+ui.pixel-formats audio.engine audio.loader locals ;
 IN: gpu.demos.raytrace
 
 GLSL-SHADER-FILE: raytrace-vertex-shader vertex-shader "raytrace.v.glsl"
@@ -49,6 +49,8 @@ TUPLE: raytrace-world < wasd-world
     [ [ axis>> ] [ theta>> ] bi rotation-matrix4 ]
     [ home>> ] bi m.v ;
 
+M: sphere audio-position sphere-center ; inline
+
 : <sphere-uniforms> ( world -- uniforms )
     [ wasd-mv-inv-matrix ]
     [ fov>> ]
@@ -69,12 +71,29 @@ CONSTANT: initial-spheres {
     T{ sphere f { 1.0 0.0  0.0 } {  0.0 5.0 0.0 } 0.025 1.0 { 1.0 1.0 0.0 1.0 } }
 }
 
+:: set-up-audio ( world -- )
+    world audio-engine>> :> audio-engine
+    world spheres>> :> spheres
+
+    audio-engine world >>listener update-audio
+
+    audio-engine "vocab:gpu/demos/raytrace/mirror-ball.aiff" read-audio
+    spheres first t (audio-clip)
+    audio-engine "vocab:gpu/demos/raytrace/red-ball.aiff" read-audio
+    spheres second t (audio-clip)
+    audio-engine "vocab:gpu/demos/raytrace/green-ball.aiff" read-audio
+    spheres third t (audio-clip)
+    audio-engine "vocab:gpu/demos/raytrace/yellow-ball.aiff" read-audio
+    spheres fourth t (audio-clip)
+    
+    4array play-clips ;
+
 M: raytrace-world begin-game-world
     init-gpu
     { -2.0 6.25 10.0 } 0.19 0.55 set-wasd-view
     initial-spheres [ clone ] map >>spheres    
     raytrace-program <program-instance> <window-vertex-array> >>vertex-array
-    drop ;
+    set-up-audio ;
 
 CONSTANT: fov 0.7
 
@@ -103,6 +122,8 @@ GAME: raytrace-game {
         } }
         { grab-input? t }
         { use-game-input? t }
+        { use-audio-engine? t }
+        { audio-engine-buffer-count 4 }
         { pref-dim { 1024 768 } }
         { tick-interval-micros $[ 60 fps ] }
     } ;
diff --git a/extra/gpu/demos/raytrace/red-ball.aiff b/extra/gpu/demos/raytrace/red-ball.aiff
new file mode 100644 (file)
index 0000000..3afd9c9
Binary files /dev/null and b/extra/gpu/demos/raytrace/red-ball.aiff differ
diff --git a/extra/gpu/demos/raytrace/yellow-ball.aiff b/extra/gpu/demos/raytrace/yellow-ball.aiff
new file mode 100644 (file)
index 0000000..31aa8cd
Binary files /dev/null and b/extra/gpu/demos/raytrace/yellow-ball.aiff differ
index 7935ffce6d4c2f2a3769f6a8877ea3cdf770090b..8251fe21b6dd9723b5d21584fad3a76e06783ba5 100644 (file)
@@ -4,7 +4,7 @@ game.input.scancodes game.loop game.worlds
 gpu.render gpu.state kernel literals
 locals math math.constants math.functions math.matrices
 math.order math.vectors opengl.gl sequences
-ui ui.gadgets.worlds specialized-arrays ;
+ui ui.gadgets.worlds specialized-arrays audio.engine ;
 FROM: alien.c-types => float ;
 SPECIALIZED-ARRAY: float
 IN: gpu.util.wasd
@@ -87,6 +87,9 @@ CONSTANT: fov 0.7
     [ yaw>> ] [ ?pitch ] [ wasd-movement-speed ] tri
     { 1.0 0.0 0.0 } n*v eye-rotate ;
 
+M: wasd-world audio-position location>> ; inline
+M: wasd-world audio-orientation forward-vector { 0.0 1.0 0.0 } <audio-orientation> ; inline
+
 : walk-forward ( world -- )
     dup forward-vector [ v+ ] curry change-location drop ;
 : walk-backward ( world -- )