LWJGL Forum
Programming => OpenAL => Topic started by: KKSystem on February 06, 2017, 03:12:03

Hi everybody,
I am using OpanGL in lwjgl according to karl (ThinMatrix) youtube tutorial, and I try this 3 weeks to find out how do I make the music to know in which direction my camera is on.
For example, when I looking with my camera forward the music needs to be in my right ear, and when I looking with my camera to back, the music needs to be in my left ear.
Do someone know how do I can do it?
Thanks for help,
Korel.

http://forum.lwjgl.org/index.php?topic=6080.0

I don't have the functions:
transformDirection
positiveZ
positiveY
In my Matrix4f objects, so it doesn't works for me :(
My camera objects:
private Vector3f _position = new Vector3f(0, 40f, 0);
private float _pitch;
private float _yaw;
private float _roll;
Set listener datat method:
public static void setListenerData(float x, float y, float z, float directionX, float directionY, float directionZ)
{
AL10.alListener3f(AL10.AL_POSITION, x, y, z);
AL10.alListener3f(AL10.AL_VELOCITY, 0, 0, 0);
AL10.alListener3f(AL10.AL_DIRECTION, directionX, directionY, directionZ);
}
Audio source init/creation:
buffer = AudioMaster.loadSound("StartBlurMusicMono");
for (int i = 0; i < 8; i++)
{
list.add(new Source(buffer));
currentSource = list.get(list.size()  1);
currentSource.setLooping(true);
currentSource.setPosition(100 + i * 100, 50, 100);
currentSource.setRefferenceDistance(105);
currentSource.setMaxDistance(200);
currentSource.setRollOffFactor(10f);
currentSource.setVolume(0.6f);
currentSource.play();
currentSource.pause();
currentSource.setDirection(1f, 0f, 0f);
}

'transformDirection()' is just a multiplication of the upperleft 3x3 submatrix with a 3D vector.
And you also only need 'invert()' additionally. See the first code snippet of the referenced post.
What you generally need to do (which is also described in the referenced forum post) is to transform the base axes of the camera/eyespace into worldspace and use those for OpenAL's AL_ORIENTATION.
Also, AL_DIRECTION is not defined for the listener. It is only used for the source.

"'transformDirection()' is just a multiplication of the upperleft 3x3 submatrix with a 3D vector."  can you show me in code how can I do this thing please?
I tried something like this:
Matrix4f cam = Maths.createTransformationMatrix(camera.getPosition(), camera.getRoll(), camera.getPitch(), camera.getYaw(), 1);
Matrix4f invCam;
Matrix4f.invert(cam, invCam);
Vector3f at = new Vector3f(0, 0, 1);
//invCam.transformDirection(at);
Vector3f up = new Vector3f(0, 1, 0);
//invCam.transformDirection(up);
createTransformationMatrix method:
public static Matrix4f createTransformationMatrix(Vector3f translation, float rx, float ry, float rz, float scale)
{
Matrix4f matrix = new Matrix4f();
matrix.setIdentity();
Matrix4f.translate(translation, matrix, matrix);
Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix);
Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix);
Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), matrix, matrix);
Matrix4f.scale(new Vector3f(scale,scale,scale), matrix, matrix);
return matrix;
}
Thank you for your help :)