@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("onDrawEye"); if (DEBUG_CARDBOARD) { Viewport viewport = eye.getViewport(); String e = "MONOCULAR"; if (eye.getType() == Eye.Type.RIGHT) e = "RIGHT"; else if (eye.getType() == Eye.Type.LEFT) e = "LEFT"; Log.d(TAG, "onDrawEye " + e + " viewport " + viewport.x + " " + viewport.y + " " + viewport.width + " " + viewport.height); } sketch.handleDraw(eye); }
@Override public void onDrawEye(Eye eye) { GLES20.glEnable(GLES20.GL_DEPTH_TEST); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); // Keep the model in front of the camera by applying the inverse of the head matrix Matrix.multiplyMM(finalViewMatrix, 0, inverseHeadView, 0, viewMatrix, 0); // Apply the eye transformation to the final view Matrix.multiplyMM(finalViewMatrix, 0, eye.getEyeView(), 0, finalViewMatrix, 0); // Rotate based on Euler angles, so the user can look around the model. Matrix.rotateM(finalViewMatrix, 0, headEulerAngles[0], 1.0f, 0.0f, 0.0f); Matrix.rotateM(finalViewMatrix, 0, -headEulerAngles[1], 0.0f, 1.0f, 0.0f); Matrix.rotateM(finalViewMatrix, 0, headEulerAngles[2], 0.0f, 0.0f, 1.0f); float[] perspective = eye.getPerspective(Z_NEAR, Z_FAR); if (model != null) { model.draw(finalViewMatrix, perspective, light); } Util.checkGLError("onDrawEye"); }
/** * Set the left eye viewport only */ public void leftEyeViewport(Eye eye) { // Adjusts viewport based on stereo type if(this.stereoType == StereoType.SIDE_BY_SIDE) { Viewport vp = eye.getViewport(); pgl.viewport(vp.x, vp.y, vp.width, vp.height); } else { pgl.viewport(0, 0, this.width, this.height); } } }
class RegisteredMethods { int count; Object[] objects; // Because the Method comes from the class being called, // it will be unique for most, if not all, objects. Method[] methods; Object[] emptyArgs = new Object[]{}; void handle() { handle(emptyArgs); } void handle(Object[] args) { for (int i = 0; i < count; i++) { try { methods[i].invoke(objects[i], args); } catch (Exception e) { // check for wrapped exception, get root exception Throwable t; if (e instanceof InvocationTargetException) { InvocationTargetException ite = (InvocationTargetException) e; t = ite.getCause(); } else { t = e; } // check for RuntimeException, and allow to bubble up if (t instanceof RuntimeException) { // re-throw exception
/** * Set the left eye view */ public void leftEye(Eye eye) { // Adjusts viewport based on stereo type if(this.stereoType == StereoType.SIDE_BY_SIDE) { Viewport vp = eye.getViewport(); aspectRatio = ((float)vp.width)/((float) vp.height); pgl.viewport(vp.x, vp.y, vp.width, vp.height); } else { pgl.viewport(0, 0, this.width, this.height); } // Set frustum float top = widthdiv2; float bottom = -widthdiv2; float left = (-aspectRatio * widthdiv2 + 0.5f * eyeSeparation * nearPlane / convPlane); float right = (aspectRatio * widthdiv2 + 0.5f * eyeSeparation * nearPlane / convPlane); app.frustum(left, right, bottom, top, nearPlane, farPlane); // Set camera app.camera( posx - rightx, posy - righty, posz - rightz, posx - rightx + dirx, posy - righty + diry, posz - rightz + dirz, upx, upy, upz ); } /**
void leftDraw(Eye eye) { boolean monocular = eye.getType()==Eye.Type.MONOCULAR; g.beginDraw();
@Override public void onDrawFrame(HeadTransform headTransform, Eye leftEye, Eye rightEye) { glThread = Thread.currentThread(); sketch.handleHeadTransform(headTransform); if (DEBUG_CARDBOARD) { Viewport vleft = leftEye.getViewport(); Log.d(TAG, "onDrawFrame left viewport " + vleft.x + " " + vleft.y + " " + vleft.width + " " + vleft.height); } sketch.handleDraw(leftEye.getType()); if (rightEye != null) { if (DEBUG_CARDBOARD) { Viewport vright = rightEye.getViewport(); Log.d(TAG, "onDrawFrame right viewport " + vright.x + " " + vright.y + " " + vright.width + " " + vright.height); } sketch.handleDraw(rightEye.getType()); } }
public void rightEye(Eye eye) { // Adjusts viewport based on stereo type if(this.stereoType == StereoType.SIDE_BY_SIDE) { Viewport vp = eye.getViewport(); aspectRatio = ((float)vp.width)/((float) vp.height); pgl.viewport(vp.x, vp.y, vp.width, vp.height); } else { pgl.viewport(0, 0, this.width, this.height); } // Set frustum float top = widthdiv2; float bottom = -widthdiv2; float left = (-aspectRatio * widthdiv2 - 0.5f * eyeSeparation * nearPlane / convPlane); float right = (aspectRatio * widthdiv2 - 0.5f * eyeSeparation * nearPlane / convPlane); app.frustum(left, right, bottom, top, nearPlane, farPlane); // Set camera app.camera( posx + rightx, posy + righty, posz + rightz, posx + rightx + dirx, posy + righty + diry, posz + rightz + dirz, upx, upy, upz ); }
void rightDraw(Eye eye) { boolean monocular = eye.getType()==Eye.Type.MONOCULAR; if (frameCount == 0) { g.endDraw();