我目前正在使用 Cardboard SDK 开展一个项目,我现在比较震惊。
我想在视线的中心显示一个十字,就像在 FPS 中一样,并在用户移动头部时将其保持在视线的中心。
我知道在这段代码中:
public void onNewFrame(HeadTransform headTransform) {
float[] headView = new float[16];
headTransform.getHeadView(headView, 0);
}
headView 参数将包含头部的变换矩阵(旋转 + 平移)(感谢这个 SO:Android VR 工具包 - HeadTransform getHeadView 矩阵表示)。
我试图这样做:
private float[] mHeadView = new float[16];
public void onNewFrame(HeadTransform headTransform) {
headTransform.getHeadView(mHeadView, 0);
}
public void onDrawEye(Eye eye) {
float[] mvpMatrix = new float[16];
float[] modelMatrix = new float[16];
float[] mvMatrix = new float[16];
float[] camera = new float[16];
Matrix.setLookAt(camera, 0, 0, 0, -2, 0, 0, -1, 0, 1, 0);
Matrix.multiplyMM(modelMatrix, 0, mHeadView, 0, camera, 0);
Matrix.multiplyMM(mvMatrix, 0, eye.getEyeView(), 0, modelMatrix, 0);
Matrix.multiplyMM(mvpMatrix, 0, eye.getEyePerspective(0.1, 100), 0, mvMatrix, 0);
// Pass the mvpMatrix and vertices buffer to the vertex shader.
}
这是我的顶点着色器:
uniform mat4 uMatrix;
attribute vec4 vPosition;
attribute vec4 vColors;
varying vec4 color;
void main() {
color = vColors;
gl_Position = uMatrix * vPosition;
}
但是十字架仍然锚定在它的初始位置并且不跟随头部。
我错过了什么吗?我怎样才能让我的十字架跟随我的头并保持在视线的中心?
预先感谢您的回答:)
(PS:我不想使用Unity,因为这个项目只能使用Java SDK)。
慕后森
相关分类