diff --git a/extra/gpu/demos/raytrace/green-ball.aiff b/extra/gpu/demos/raytrace/green-ball.aiff new file mode 100644 index 0000000000..2ccf57ef62 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 index 0000000000..23aa009883 Binary files /dev/null and b/extra/gpu/demos/raytrace/mirror-ball.aiff differ diff --git a/extra/gpu/demos/raytrace/raytrace.factor b/extra/gpu/demos/raytrace/raytrace.factor index fd8ae6b157..53e8c63ddf 100644 --- a/extra/gpu/demos/raytrace/raytrace.factor +++ b/extra/gpu/demos/raytrace/raytrace.factor @@ -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 + : ( 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 >>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 index 0000000000..3afd9c96ba 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 index 0000000000..31aa8cd750 Binary files /dev/null and b/extra/gpu/demos/raytrace/yellow-ball.aiff differ diff --git a/extra/gpu/util/wasd/wasd.factor b/extra/gpu/util/wasd/wasd.factor index 7935ffce6d..8251fe21b6 100644 --- a/extra/gpu/util/wasd/wasd.factor +++ b/extra/gpu/util/wasd/wasd.factor @@ -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 } ; inline + : walk-forward ( world -- ) dup forward-vector [ v+ ] curry change-location drop ; : walk-backward ( world -- )