Java Code Examples for android.opengl.Matrix#invertM()
The following examples show how to use
android.opengl.Matrix#invertM() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InGameManager.java From Alite with GNU General Public License v3.0 | 6 votes |
private void performViewTransformation(float deltaTime) { // Kudos to Quelo!! // Thanks for getting me started on OpenGL -- from simply // looking at this method, one cannot immediately grasp the // complexities of the ideas behind it. // And without Quelo, I certainly would not have understood! GLES11.glMatrixMode(GLES11.GL_MODELVIEW); GLES11.glLoadIdentity(); GLES11.glLightfv(GLES11.GL_LIGHT1, GLES11.GL_POSITION, lightPosition, 0); if (!paused) { ship.applyDeltaRotation((float) Math.toDegrees(deltaYawRollPitch.z * deltaTime), (float) Math.toDegrees(deltaYawRollPitch.x * deltaTime), (float) Math.toDegrees(deltaYawRollPitch.y * deltaTime)); } ship.orthoNormalize(); Matrix.invertM(viewMatrix, 0, ship.getMatrix(), 0); GLES11.glLoadMatrixf(viewMatrix, 0); }
Example 2
Source File: VRUtil.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 5 votes |
public static boolean invertM(float[] output, float[] input){ if (input == output){ return false; } return Matrix.invertM(output, 0, input, 0); }
Example 3
Source File: ImmersiveSensorNavigation.java From Spectaculum with Apache License 2.0 | 5 votes |
@Override public void onSensorChanged(SensorEvent event) { if(mEffect != null && mActive) { // TODO understand those sensor coordinate spaces // TODO find out how the sensor rotation can be mapped to the sphere shader correctly // TODO should we store the initial rotation value to set the zero rotation point to the current phone rotation? // Get the rotation matrix from the sensor SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values); // When the first sensor data comes in, we set the initial rotation matrix as // "zero rotation point" to be able to calculate the relative rotation from the initial // device rotation, instead of the absolute rotation from true north. // Later, we subtract the initial rotation from the rotation matrix to get the relative rotation if(mInitialRotationMatrix == null) { mInitialRotationMatrix = new float[16]; // Matrix subtraction works by multiplying the inverse (Mb - Ma == inv(Ma) * Mb), // so we directly store the inverse Matrix.invertM(mInitialRotationMatrix, 0, mRotationMatrix, 0); } // Remove initial rotation Matrix.multiplyMM(mRotationMatrix, 0, mInitialRotationMatrix, 0, mRotationMatrix, 0); // Some axes seem like they need to be exchanged Matrix.invertM(mRemappedRotationMatrix, 0, mRotationMatrix, 0); // FIXME this does not seem to remap axes at all!? //SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, mRemappedRotationMatrix); // Debug output //float[] orientation = new float[3]; //SensorManager.getOrientation(mRemappedRotationMatrix, orientation); //debugOutputOrientationInDegree(orientation); // Update effect and thus the viewport too mEffect.setRotationMatrix(mRemappedRotationMatrix); } }
Example 4
Source File: VRUtil.java From MD360Player4Android with Apache License 2.0 | 5 votes |
public static boolean invertM(float[] output, float[] input){ if (input == output){ return false; } return Matrix.invertM(output, 0, input, 0); }
Example 5
Source File: Renderer.java From ParaViewTangoRecorder with Apache License 2.0 | 5 votes |
/** * Update the view matrix of the Renderer to follow the position of the * device in the current perspective. */ public void updateViewMatrix() { mDevicePosition = mModelMatCalculator.getTranslation(); switch (viewId) { case FIRST_PERSON: float[] invertModelMat = new float[MATRIX_4X4]; Matrix.setIdentityM(invertModelMat, 0); float[] temporaryMatrix = new float[MATRIX_4X4]; Matrix.setIdentityM(temporaryMatrix, 0); Matrix.setIdentityM(mViewMatrix, 0); Matrix.invertM(invertModelMat, 0, mModelMatCalculator.getModelMatrix(), 0); Matrix.multiplyMM(temporaryMatrix, 0, mViewMatrix, 0, invertModelMat, 0); System.arraycopy(temporaryMatrix, 0, mViewMatrix, 0, 16); break; case THIRD_PERSON: Matrix.setLookAtM(mViewMatrix, 0, mDevicePosition[0] + mCameraPosition[0], mCameraPosition[1] + mDevicePosition[1], mCameraPosition[2] + mDevicePosition[2], mDevicePosition[0], mDevicePosition[1], mDevicePosition[2], 0f, 1f, 0f); break; case TOP_DOWN: // Matrix.setIdentityM(mViewMatrix, 0); Matrix.setLookAtM(mViewMatrix, 0, mDevicePosition[0] + mCameraPosition[0], mCameraPosition[1], mCameraPosition[2] + mDevicePosition[2], mDevicePosition[0] + mCameraPosition[0], mCameraPosition[1] - 5, mCameraPosition[2] + mDevicePosition[2], 0f, 0f, -1f); break; default: viewId = THIRD_PERSON; return; } }
Example 6
Source File: ModelMatCalculator.java From ParaViewTangoRecorder with Apache License 2.0 | 5 votes |
/** * Updates the model matrix (rotation and translation). * * @param translation * a three-element array of translation data. * @param quaternion * a four-element array of rotation data. */ public void updatePointCloudModelMatrix(float[] translation, float[] quaternion) { float[] tempMultMatrix = new float[16]; Matrix.setIdentityM(tempMultMatrix, 0); Matrix.multiplyMM(tempMultMatrix, 0, mColorCamera2IMUMatrix, 0, mOpengl2ColorCameraMatrix, 0); float[] tempInvertMatrix = new float[16]; Matrix.setIdentityM(tempInvertMatrix, 0); Matrix.invertM(tempInvertMatrix, 0, mDevice2IMUMatrix, 0); float[] tempMultMatrix2 = new float[16]; Matrix.setIdentityM(tempMultMatrix2, 0); Matrix.multiplyMM(tempMultMatrix2, 0, tempInvertMatrix, 0, tempMultMatrix, 0); float[] quaternionMatrix = new float[16]; Matrix.setIdentityM(quaternionMatrix, 0); quaternionMatrix = quaternionMatrixOpenGL(quaternion); float[] tempMultMatrix3 = new float[16]; Matrix.setIdentityM(tempMultMatrix3, 0); Matrix.setIdentityM(mPointCloudModelMatrix, 0); Matrix.multiplyMM(tempMultMatrix3, 0, quaternionMatrix, 0, tempMultMatrix2, 0); Matrix.multiplyMM(mPointCloudModelMatrix, 0, mConversionMatrix, 0, tempMultMatrix3, 0); mPointCloudModelMatrix[12] += translation[0]; mPointCloudModelMatrix[13] += translation[2]; mPointCloudModelMatrix[14] += -1f * translation[1]; }
Example 7
Source File: ModelMatCalculator.java From ParaViewTangoRecorder with Apache License 2.0 | 5 votes |
/** * Updates the model matrix (rotation and translation). * * @param translation * a three-element array of translation data. * @param quaternion * a four-element array of rotation data. */ public void updateModelMatrix(float[] translation, float[] quaternion) { float[] tempMultMatrix = new float[16]; Matrix.setIdentityM(tempMultMatrix, 0); Matrix.multiplyMM(tempMultMatrix, 0, mColorCamera2IMUMatrix, 0, mOpengl2ColorCameraMatrix, 0); float[] tempInvertMatrix = new float[16]; Matrix.setIdentityM(tempInvertMatrix, 0); Matrix.invertM(tempInvertMatrix, 0, mDevice2IMUMatrix, 0); float[] tempMultMatrix2 = new float[16]; Matrix.setIdentityM(tempMultMatrix2, 0); Matrix.multiplyMM(tempMultMatrix2, 0, tempInvertMatrix, 0, tempMultMatrix, 0); float[] quaternionMatrix = new float[16]; Matrix.setIdentityM(quaternionMatrix, 0); quaternionMatrix = quaternionMatrixOpenGL(quaternion); float[] tempMultMatrix3 = new float[16]; Matrix.setIdentityM(tempMultMatrix3, 0); Matrix.setIdentityM(mModelMatrix, 0); Matrix.multiplyMM(tempMultMatrix3, 0, quaternionMatrix, 0, tempMultMatrix2, 0); Matrix.multiplyMM(mModelMatrix, 0, mConversionMatrix, 0, tempMultMatrix3, 0); mModelMatrix[12] += translation[0]; mModelMatrix[13] += translation[2]; mModelMatrix[14] += -1f * translation[1]; }
Example 8
Source File: CN1Matrix4f.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public boolean invert() { boolean res = Matrix.invertM(factory.sTemp, 0, data, 0); if (!res) { return res; } else { System.arraycopy(factory.sTemp, 0, data, 0, 16); return res; } }
Example 9
Source File: GLESCamera.java From geoar-app with Apache License 2.0 | 5 votes |
public static void updateFrustum(float[] projectionMatrix, float[] viewMatrix) { float[] projectionViewMatrix = new float[16]; float[] invertPVMatrix = new float[16]; Matrix.multiplyMM(projectionViewMatrix, 0, projectionMatrix, 0, viewMatrix, 0); Matrix.invertM(invertPVMatrix, 0, projectionViewMatrix, 0); for (int i = 0; i < 8; i++) { float[] point = Arrays.copyOf(clipSpace[i], 3); float rw = point[0] * invertPVMatrix[3] + point[1] * invertPVMatrix[7] + point[2] * invertPVMatrix[11] + invertPVMatrix[15]; planePoints[i] = clipSpace[i]; float[] newPlanePoints = new float[3]; newPlanePoints[0] = (point[0] * invertPVMatrix[0] + point[1] * invertPVMatrix[4] + point[2] * invertPVMatrix[8] + invertPVMatrix[12]) / rw; newPlanePoints[1] = (point[0] * invertPVMatrix[1] + point[1] * invertPVMatrix[5] + point[2] * invertPVMatrix[9] + invertPVMatrix[13]) / rw; newPlanePoints[2] = (point[0] * invertPVMatrix[2] + point[1] * invertPVMatrix[6] + point[2] * invertPVMatrix[10] + invertPVMatrix[14]) / rw; planePoints[i] = newPlanePoints; } frustumPlanes[0].set(planePoints[1], planePoints[0], planePoints[2]); frustumPlanes[1].set(planePoints[4], planePoints[5], planePoints[7]); frustumPlanes[2].set(planePoints[0], planePoints[4], planePoints[3]); frustumPlanes[3].set(planePoints[5], planePoints[1], planePoints[6]); frustumPlanes[4].set(planePoints[2], planePoints[3], planePoints[6]); frustumPlanes[5].set(planePoints[4], planePoints[0], planePoints[1]); }
Example 10
Source File: Joint.java From android-3D-model-viewer with GNU Lesser General Public License v3.0 | 4 votes |
/** * This is called during set-up, after the joints hierarchy has been * created. This calculates the model-space bind transform of this joint * like so: </br> * </br> * {@code bindTransform = parentBindTransform * bindLocalTransform}</br> * </br> * where "bindTransform" is the model-space bind transform of this joint, * "parentBindTransform" is the model-space bind transform of the parent * joint, and "bindLocalTransform" is the bone-space bind transform of this * joint. It then calculates and stores the inverse of this model-space bind * transform, for use when calculating the final animation transform each * frame. It then recursively calls the method for all of the children * joints, so that they too calculate and store their inverse bind-pose * transform. * * @param parentBindTransform - the model-space bind transform of the parent joint. */ public void calcInverseBindTransform(float[] parentBindTransform, boolean override) { float[] bindTransform = new float[16]; Matrix.multiplyMM(bindTransform, 0, parentBindTransform, 0, data.getBindLocalTransform(), 0); if (data.index >= 0 && (override)) { // when model has inverse bind transforms available, don't overwrite it // this way we calculate only the joints with no animations which has no inverse bind transform available float[] inverseBindTransform = new float[16]; if (!Matrix.invertM(inverseBindTransform, 0, bindTransform, 0)) { Log.w("Joint", "Couldn't calculate inverse matrix for " + data.getId()); } data.setInverseBindTransform(inverseBindTransform); } for (Joint child : children) { child.calcInverseBindTransform(bindTransform, override); } }
Example 11
Source File: Joint.java From react-native-3d-model-view with MIT License | 3 votes |
/** * This is called during set-up, after the joints hierarchy has been * created. This calculates the model-space bind transform of this joint * like so: </br> * </br> * {@code bindTransform = parentBindTransform * localBindTransform}</br> * </br> * where "bindTransform" is the model-space bind transform of this joint, * "parentBindTransform" is the model-space bind transform of the parent * joint, and "localBindTransform" is the bone-space bind transform of this * joint. It then calculates and stores the inverse of this model-space bind * transform, for use when calculating the final animation transform each * frame. It then recursively calls the method for all of the children * joints, so that they too calculate and store their inverse bind-pose * transform. * * @param parentBindTransform * - the model-space bind transform of the parent joint. */ public void calcInverseBindTransform(float[] parentBindTransform) { float[] bindTransform = new float[16]; Matrix.multiplyMM(bindTransform, 0, parentBindTransform,0, localBindTransform, 0); Matrix.invertM(inverseBindTransform, 0, bindTransform, 0); for (Joint child : children) { child.calcInverseBindTransform(bindTransform); } }