import com.google.vr.sdk.base.Viewport; //导入依赖的package包/类
@Override
public void onDrawEye(Eye eye) {
Viewport curView = eye.getViewport();
Viewport initViewport = new Viewport();
initViewport.setViewport(curView.x, curView.y, curView.width, curView.height);
FieldOfView curFov = eye.getFov();
FieldOfView initFov = new FieldOfView(curFov.getLeft(), curFov.getRight(), curFov.getBottom(), curFov.getTop());
// Change to camera resolution for scene render
eye.getViewport().setViewport(0, 0, mPreviewSize.getWidth(), mPreviewSize.getHeight());
eye.getFov().setAngles((float)mFov.x / 2.0f, (float)mFov.x / 2.0f, (float)mFov.y / 2.0f, (float)mFov.y / 2.0f);
eye.getViewport().setGLViewport();
eye.getViewport().setGLScissor();
eye.setProjectionChanged();
// Apply the eye transformation to the camera.
float[] viewMat = new float[16];
Matrix.multiplyMM(viewMat, 0, eye.getEyeView(), 0, mCamera, 0);
// Get the perspective matrix for 3D objects rendering
// Create FOV identical to physical
float[] perspective = new float[16];
perspective = eye.getPerspective(Z_NEAR, Z_FAR);
//Matrix.perspectiveM(perspective, 0, (float)mFov.y, (float)mPreviewSize.getWidth() / (float)mPreviewSize.getHeight(), Z_NEAR, Z_FAR);
// FieldOfView physFov = new FieldOfView((float)mFov.x, (float)mFov.x, (float)mFov.y, (float)mFov.y);
// physFov.toPerspectiveMatrix(Z_NEAR, Z_FAR, perspective, 0);
// First draw object scene texture through frame buffer
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFboIdObjects);
if (eye.getType() == Eye.Type.LEFT) {
GLES20.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
} else {
GLES20.glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
}
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
//GLES20.glViewport(0, 0, mPreviewSize.getWidth(), mPreviewSize.getHeight());
//GLES20.glViewport(0, 0, 100, 100);
drawObjects(viewMat, perspective);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, DEFAULT_FBO_ID);
// Change back to initial res
eye.getViewport().setViewport(initViewport.x, initViewport.y, initViewport.width, initViewport.height);
eye.getFov().setAngles(initFov.getLeft(), initFov.getRight(), initFov.getBottom(), initFov.getTop());
eye.getViewport().setGLViewport();
eye.getViewport().setGLScissor();
eye.setProjectionChanged();
// Recalculate the perspective matrix for vr view
perspective = eye.getPerspective(Z_NEAR, Z_FAR);
// Matrix.perspectiveM(perspective, 0, eye.getFov().getTop(), (float)eye.getViewport().width / (float)eye.getViewport().height, Z_NEAR, Z_FAR);
// Now draw actual screen for cardboard viewer
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
//eye.getViewport().setGLViewport();
screenRenderer.draw(viewMat, perspective);
}
请发表评论