add gratuitous audio to gpu.demos.raytrace

db4
Joe Groff 2010-01-19 17:41:05 -08:00
parent a99f1fd20e
commit 7a14b4ce61
6 changed files with 27 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View 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 generalizations gpu gpu.render gpu.shaders gpu.util gpu.util.wasd
kernel literals math math.matrices math.order math.vectors kernel literals math math.matrices math.order math.vectors
method-chains sequences ui ui.gadgets ui.gadgets.worlds method-chains sequences ui ui.gadgets ui.gadgets.worlds
ui.pixel-formats ; ui.pixel-formats audio.engine audio.loader locals ;
IN: gpu.demos.raytrace IN: gpu.demos.raytrace
GLSL-SHADER-FILE: raytrace-vertex-shader vertex-shader "raytrace.v.glsl" 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 ] [ [ axis>> ] [ theta>> ] bi rotation-matrix4 ]
[ home>> ] bi m.v ; [ home>> ] bi m.v ;
M: sphere audio-position sphere-center ; inline
: <sphere-uniforms> ( world -- uniforms ) : <sphere-uniforms> ( world -- uniforms )
[ wasd-mv-inv-matrix ] [ wasd-mv-inv-matrix ]
[ fov>> ] [ 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 } } 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 M: raytrace-world begin-game-world
init-gpu init-gpu
{ -2.0 6.25 10.0 } 0.19 0.55 set-wasd-view { -2.0 6.25 10.0 } 0.19 0.55 set-wasd-view
initial-spheres [ clone ] map >>spheres initial-spheres [ clone ] map >>spheres
raytrace-program <program-instance> <window-vertex-array> >>vertex-array raytrace-program <program-instance> <window-vertex-array> >>vertex-array
drop ; set-up-audio ;
CONSTANT: fov 0.7 CONSTANT: fov 0.7
@ -103,6 +122,8 @@ GAME: raytrace-game {
} } } }
{ grab-input? t } { grab-input? t }
{ use-game-input? t } { use-game-input? t }
{ use-audio-engine? t }
{ audio-engine-buffer-count 4 }
{ pref-dim { 1024 768 } } { pref-dim { 1024 768 } }
{ tick-interval-micros $[ 60 fps ] } { tick-interval-micros $[ 60 fps ] }
} ; } ;

Binary file not shown.

Binary file not shown.

View File

@ -4,7 +4,7 @@ game.input.scancodes game.loop game.worlds
gpu.render gpu.state kernel literals gpu.render gpu.state kernel literals
locals math math.constants math.functions math.matrices locals math math.constants math.functions math.matrices
math.order math.vectors opengl.gl sequences 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 ; FROM: alien.c-types => float ;
SPECIALIZED-ARRAY: float SPECIALIZED-ARRAY: float
IN: gpu.util.wasd IN: gpu.util.wasd
@ -87,6 +87,9 @@ CONSTANT: fov 0.7
[ yaw>> ] [ ?pitch ] [ wasd-movement-speed ] tri [ yaw>> ] [ ?pitch ] [ wasd-movement-speed ] tri
{ 1.0 0.0 0.0 } n*v eye-rotate ; { 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 -- ) : walk-forward ( world -- )
dup forward-vector [ v+ ] curry change-location drop ; dup forward-vector [ v+ ] curry change-location drop ;
: walk-backward ( world -- ) : walk-backward ( world -- )