Having both "2D" and "3D" sound.

Started by Eternity, August 24, 2010, 14:09:27

Previous topic - Next topic

Eternity

I have a complete game engine thats only missing sound support. Ive been implementing OpenAL into it for the past 3 days but now ive run into a problem.

In my engine theres a "SceneObject" class. which is extended by "Object3D" and "Object2D". Object3D gets extended by all 3D objects (nodes) in the world like model instances, billboards and cameras. Object2D gets extended by all 2D componants (nodes) like text boxes and 2D images.

My engine has a 3D scenegraph for all Object3D's and a 2D scenegraph for all Object2D's.

SceneObjects now have a source field that gets populated when the object gets created and a playSound method that will play the passed sound effect through the SceneObjects source.

So every SceneObject (Object2D's and Object3D) has its own source.

Object3D's will keep their source updated with their absolute world coordinates.
Object 2D's wont update their source thus it will always be at (0,0,0)

The listiner gets attached to the camera.

3D surround sound works perfectly with what i have so far. But my problem comes with things like background music or GUI sounds (like a button click sound). I play them through my Object2D's but since a Object2D's source will always be at (0,0,0) and my camera could be anywhere it obviously does not work. I could constantly update the Object2D's sources to the camera's position but thats a waiste of CPU cycles. alternitively i thought i could just use the camera's source (since the camera is also a Object3D) to play all "2D" sounds but i dont know if its possible/good practice to play that many different sounds with different start/stop times through the same source.

Any ideas?

thnx in Advance!

Ciardhubh

If I understand you correctly, you can just set the source property AL_SOURCE_RELATIVE of your 2D sources to AL_TRUE. That way the source stays relative to the listener, i.e. a source position of (0,0,0) will always be directly at the listener.

Eternity