I have an isometric camera for an RTS that looks like this:

Screenshot of game

Basically, I don't know how to set the listener's position in OpenAL because I represent the camera's position with only two coordinates.

I build my projection matrix as a standard orthographic projection:

projectionMatrix = new Matrix4f()
            .setOrtho(-25, 25, -25 / aspect, 25 / aspect, -300, 300);

and my view matrix like so:

            .rotate(-rotation.x / 180.0f * Util.PI, 1, 0, 0)
            .rotate(-225.0f / 180.0f * Util.PI, 0, 1, 0)
            .rotate(-rotation.z / 180.0f * Util.PI, 0, 0, 1)
            .translate(-position.x, 0, -position.y);

Where rotation is a 3D vector of the Euler angles, and position is a 2D vector controlled by the keyboard or dragging the mouse. (rotation.y is ignored)

How would I translate this 2D position into the 3 coordinates required for OpenAL? I tried to give a y-offset like: alListener3f(AL_POSITION, position.x, 20, position.z);, but it gave really weird attenuation results.

(PS: I'm using Java, LWJGL, and JOML for math)

  • \$\begingroup\$ Why are you even using a 3d sound system for a 2d game? It will make everything very quiet, since you're essentially listening to them from a bird's perspective. \$\endgroup\$ – Bálint Jun 9 '18 at 23:37
  • \$\begingroup\$ @Bálint "Quiet" is relative, and I can just change the attenuation settings to make it louder. You can also zoom in/out in the game, and the sounds get quieter and louder when doing so. \$\endgroup\$ – user5074736 Jun 9 '18 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.