俯仰偏航的开放式侦听器方向并且滚动

时间:2017-01-20 15:09:21

标签: java opengl audio openal

我正在制作游戏,目前正在使我的音频监听器工作。我做了一切,我甚至可以听到一些声音,但我的相机(一个定义的类)的方向与我的音频不一致。我试图通过使用它来实现它:

AL10.alListener3f(AL10.AL_ORIENTATION , cam.getPitch(),cam.getYaw(), cam.getRoll());

但是那个源不起作用。我能做些什么来让我的游戏发挥作用?

OpenGL 2.0版和(我认为OpenAl版本2.0) 谢谢!

编辑: 从答案我已设法理解它需要在浮动缓冲区。所以这就是我用俯仰和偏航创建我的摄像机视图矩阵的方法:

    viewMatrix.setIdentity();
    Matrix4f.rotate((float) Math.toRadians(pitch), rotateX, viewMatrix, viewMatrix);
    Matrix4f.rotate((float) Math.toRadians(yaw), rotateZ, viewMatrix, viewMatrix);
    Vector3f negativeCameraPos = new Vector3f(-position.x, -position.y, -position.z);
    Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);

我目前使用的方法是:

    ByteBuffer bb = ByteBuffer.allocateDirect( 6 * 4);
    bb.order( ByteOrder.nativeOrder() );
    FloatBuffer listenerOrientation = bb.asFloatBuffer();
    listenerOrientation.put( 0, cam.getViewMatrix().m01 );
    listenerOrientation.put( 1, cam.getViewMatrix().m02 );
    listenerOrientation.put( 2, cam.getViewMatrix().m03 );
    listenerOrientation.put( 3, cam.getViewMatrix().m11 );
    listenerOrientation.put( 4, cam.getViewMatrix().m12 );
    listenerOrientation.put( 5, cam.getViewMatrix().m13 );

    AL10.alListener( AL10.AL_ORIENTATION, listenerOrientation );
    AL10.alListener3f(AL10.AL_POSITION, cam.getPosition().x, cam.getPosition().y, cam.getPosition().z);

1 个答案:

答案 0 :(得分:1)

您必须从俯仰/偏航/滚动表示计算视图矢量和向上矢量。很可能你已经有了这些数据,因为它们存储在相机矩阵的第2行和第3行(或列)中。

使用此值,您可以调用alListener(int pname, java.nio.FloatBuffer value)方法,pname = AL10.AL_ORIENTATIONvalue包含与此代码示例类似的两个向量:

listenerOrientation.put( 0, lookX );
listenerOrientation.put( 1, lookY );
listenerOrientation.put( 2, lookZ );
listenerOrientation.put( 3, upX );
listenerOrientation.put( 4, upY );
listenerOrientation.put( 5, upZ );

AL10.alListener( AL10.AL_ORIENTATION, listenerOrientation );

来源:
wp_editor()https://www.openal.org/documentation/OpenAL_Programmers_Guide.pdf