尋找谷歌地圖cardboard example我想知道,在哪裏發生了頭部運動轉換,以便通過場景或視圖來反映頭部運動。CardboardView如何照顧頭部運動?
有趣的方法應該是MainActivity
類中的public void onNewFrame(HeadTransform headTransform)
和public void onDrawEye(Eye eye)
。 這裏是一個片段:
@Override
public void onNewFrame(HeadTransform headTransform) {
// Build the Model part of the ModelView matrix.
Matrix.rotateM(modelCube, 0, TIME_DELTA, 0.5f, 0.5f, 1.0f);
// Build the camera matrix and apply it to the ModelView.
Matrix.setLookAtM(camera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
headTransform.getHeadView(headView, 0);
// Update the 3d audio engine with the most recent head rotation.
headTransform.getQuaternion(headRotation, 0);
cardboardAudioEngine.setHeadRotation(
headRotation[0], headRotation[1], headRotation[2], headRotation[3]);
checkGLError("onReadyToDraw");
}
@Override
public void onDrawEye(Eye eye) {
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
checkGLError("colorParam");
// Apply the eye transformation to the camera.
Matrix.multiplyMM(view, 0, eye.getEyeView(), 0, camera, 0);
// Set the position of the light
Matrix.multiplyMV(lightPosInEyeSpace, 0, view, 0, LIGHT_POS_IN_WORLD_SPACE, 0);
// Build the ModelView and ModelViewProjection matrices
// for calculating cube position and light.
float[] perspective = eye.getPerspective(Z_NEAR, Z_FAR);
Matrix.multiplyMM(modelView, 0, view, 0, modelCube, 0);
Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);
drawCube();
// Set modelView for the floor, so we draw floor in the correct location
Matrix.multiplyMM(modelView, 0, view, 0, modelFloor, 0);
Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);
drawFloor();
}
我的第一個假設是,根據從headTransform
數據模型(或攝像機)被修改在onNewFrame()
。但這似乎並非如此,因爲只有兩次訪問。一個用於識別我們正在尋找哪個立方體(headTransform.getHeadView(headView, 0);
),另一個用於音頻引擎。
所以我的下一個假設,只有我看到的可能性是,它被處理的eye
傳遞給onDrawEye()
。但另一方面,在disassembly內部進行簡短的檢查之後,我無法找到headTransform
和eye
之間的關係(這並不意味着沒有關係,因爲我沒有投入太多時間)。
所以我的問題:
是我的假設嗎?渲染是否通過將camera
乘以eyeView來考慮頭部運動?