List of usage examples for android.opengl Matrix multiplyMM
public static native void multiplyMM(float[] result, int resultOffset, float[] lhs, int lhsOffset, float[] rhs, int rhsOffset);
From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java
/** * Draws a frame for an eye.//from w ww . j a va 2 s.co m * * @param eye The eye to render. Includes all required transformations. */ @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(); float[] mRotationCube = new float[16]; //Not sure if we can just reuse modelView like this Matrix.multiplyMM(modelView, 0, view, 0, modelMiniCube, 0); //Matrix.multiplyMM(mRotationCube, 0, view, 0, modelView, 0); //Not working //float[] ident = new Matrix(eye.getPerspective(Z_NEAR, Z_FAR)); //Matrix.setIdentityM(ident, 0); //Cheating so that we have relative hand movement //end not working Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0); //Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, mRotationCube, 0); //doesn't work :( //Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelMiniCube, 0); drawMiniCube(); // 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(); }
From source file:com.tumblr.cardboard.Tumblr3DActivity.java
/** * Draws a frame for an eye. The transformation for that eye (from the camera) is passed in as * a parameter./* www. ja va 2s. co m*/ * * @param eye The transformations to apply to render this eye. */ @Override public void onDrawEye(Eye eye) { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position"); mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal"); mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color"); mRectTextureCoordinateParam = GLES20.glGetAttribLocation(mGlProgram, "a_TexCoordinate"); GLES20.glEnableVertexAttribArray(mPositionParam); GLES20.glEnableVertexAttribArray(mNormalParam); GLES20.glEnableVertexAttribArray(mColorParam); checkGLError("mColorParam"); // Apply the eye transformation to the camera. Matrix.multiplyMM(mView, 0, eye.getEyeView(), 0, mCamera, 0); // Set the position of the light Matrix.multiplyMV(mLightPosInEyeSpace, 0, mView, 0, mLightPosInWorldSpace, 0); GLES20.glUniform3f(mLightPosParam, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]); // Set mModelView for the floor, so we draw floor in the correct location Matrix.multiplyMM(mModelView, 0, mView, 0, mModelFloor, 0); Matrix.multiplyMM(mModelViewProjection, 0, eye.getPerspective(Z_NEAR, Z_FAR), 0, mModelView, 0); drawFloor(eye.getPerspective(Z_NEAR, Z_FAR)); // Build the ModelView and ModelViewProjection matrices // for calculating rect position and light. for (int i = 0; i < mModelRect.length; i++) { Matrix.multiplyMM(mModelView, 0, mView, 0, mModelRect[i], 0); Matrix.multiplyMM(mModelViewProjection, 0, eye.getPerspective(Z_NEAR, Z_FAR), 0, mModelView, 0); drawRect(i); } }
From source file:com.sveder.cardboardpassthrough.MainActivity.java
/** * Draws a frame for an eye. The transformation for that eye (from the camera) is passed in as * a parameter./*from w w w .j a v a 2 s .com*/ * @param transform The transformations to apply to render this eye. */ @Override public void onDrawEye(EyeTransform transform) { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); GLES20.glUseProgram(mProgram); GLES20.glActiveTexture(GL_TEXTURE_EXTERNAL_OES); GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture); mPositionHandle = GLES20.glGetAttribLocation(mProgram, "position"); GLES20.glEnableVertexAttribArray(mPositionHandle); GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); mTextureCoordHandle = GLES20.glGetAttribLocation(mProgram, "inputTextureCoordinate"); GLES20.glEnableVertexAttribArray(mTextureCoordHandle); GLES20.glVertexAttribPointer(mTextureCoordHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, textureVerticesBuffer); mColorHandle = GLES20.glGetAttribLocation(mProgram, "s_texture"); GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer); // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); GLES20.glDisableVertexAttribArray(mTextureCoordHandle); Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0); // mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position"); // mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal"); // mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color"); // // GLES20.glEnableVertexAttribArray(mPositionParam); // GLES20.glEnableVertexAttribArray(mNormalParam); // GLES20.glEnableVertexAttribArray(mColorParam); // checkGLError("mColorParam"); // // // Apply the eye transformation to the camera. // Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0); // // // Set the position of the light // Matrix.multiplyMV(mLightPosInEyeSpace, 0, mView, 0, mLightPosInWorldSpace, 0); // GLES20.glUniform3f(mLightPosParam, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], // mLightPosInEyeSpace[2]); // // // Build the ModelView and ModelViewProjection matrices // // for calculating cube position and light. // Matrix.multiplyMM(mModelView, 0, mView, 0, mModelCube, 0); // Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0, mModelView, 0); // drawCube(); // // // Set mModelView for the floor, so we draw floor in the correct location // Matrix.multiplyMM(mModelView, 0, mView, 0, mModelFloor, 0); // Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0, // mModelView, 0); // drawFloor(transform.getPerspective()); }
From source file:com.projecttango.examples.java.modelcorrespondence.ModelCorrespondenceActivity.java
/** * Update the pose of the model.//ww w . j a v a2 s. c o m */ public void transformModel(float[] newTransform) { float[] newOpenGlTModel = new float[16]; Matrix.multiplyMM(newOpenGlTModel, 0, newTransform, 0, mOpenGlTHouse, 0); mOpenGlTHouse = newOpenGlTModel; mModelUpdated = true; mCorrespondenceDone = true; }
From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java
/** * Check if user is looking at object by calculating where the object is in eye-space. * * @return true if the user is looking at the object. *//* www . j ava2s . com*/ private boolean isLookingAtObject() { float[] initVec = { 0, 0, 0, 1.0f }; float[] objPositionVec = new float[4]; // Convert object space to camera space. Use the headView from onNewFrame. Matrix.multiplyMM(modelView, 0, headView, 0, modelCube, 0); Matrix.multiplyMV(objPositionVec, 0, modelView, 0, initVec, 0); float pitch = (float) Math.atan2(objPositionVec[1], -objPositionVec[2]); float yaw = (float) Math.atan2(objPositionVec[0], -objPositionVec[2]); return Math.abs(pitch) < PITCH_LIMIT && Math.abs(yaw) < YAW_LIMIT; }
From source file:com.tumblr.cardboard.Tumblr3DActivity.java
private static void placePhoto(float[][] modelRects, float[][] imageRects, int texIndex, float scale, float azimuth, float inclination, float yTranslate) { float[] azimuthMatrix = new float[16]; Matrix.setRotateM(azimuthMatrix, 0, azimuth, 0, 1, 0); float[] inclinationMatrix = new float[16]; Matrix.setRotateM(inclinationMatrix, 0, inclination, 1, 0, 0); float[] rotationMatrix = new float[16]; Matrix.multiplyMM(rotationMatrix, 0, azimuthMatrix, 0, inclinationMatrix, 0); Matrix.multiplyMM(modelRects[texIndex], 0, imageRects[texIndex], 0, rotationMatrix, 0); Matrix.translateM(modelRects[texIndex], 0, 0f, 0f, yTranslate); Matrix.scaleM(modelRects[texIndex], 0, scale, scale, 1f); }
From source file:com.tumblr.cardboard.Tumblr3DActivity.java
private boolean isLookingAtObject(float[] initVec, float[] objPositionVec, int texIndex) { // Convert object space to camera space. Use the headView from onNewFrame. Matrix.multiplyMM(mModelView, 0, mHeadView, 0, mModelRect[texIndex], 0); Matrix.multiplyMV(objPositionVec, 0, mModelView, 0, initVec, 0); float pitch = (float) Math.atan2(objPositionVec[1], -objPositionVec[2]); float yaw = (float) Math.atan2(objPositionVec[0], -objPositionVec[2]); Log.v(TAG, "Object position: X: " + objPositionVec[0] + " Y: " + objPositionVec[1] + " Z: " + objPositionVec[2]);//www. ja v a 2s. c o m Log.v(TAG, "Object Pitch: " + pitch + " Yaw: " + yaw); return (Math.abs(pitch) < PITCH_LIMIT) && (Math.abs(yaw) < YAW_LIMIT); }