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"
[ [ 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>> ]
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
} }
{ 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 ] }
} ;
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
[ 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 -- )