Java Code Examples for android.opengl.GLU#gluUnProject()

The following examples show how to use android.opengl.GLU#gluUnProject() . 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: TouchSurfaceView.java    From retrobreaker with MIT License 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent e) {
	switch (e.getAction()) {
	case MotionEvent.ACTION_MOVE:
		final float screenX = e.getX();
		final float screenY = mScreenHeight - e.getY();

		final int[] viewport = {
				0, 0, mScreenWidth, mScreenHeight
		};

		float[] resultWorldPos = {
				0.0f, 0.0f, 0.0f, 0.0f
		};

		GLU.gluUnProject(screenX, screenY, 0, mUnprojectViewMatrix, 0, mUnprojectProjMatrix, 0,
				viewport, 0, resultWorldPos, 0);
		resultWorldPos[0] /= resultWorldPos[3];
		resultWorldPos[1] /= resultWorldPos[3];
		resultWorldPos[2] /= resultWorldPos[3];
		resultWorldPos[3] = 1.0f;

		mRenderer.updatePaddlePosition(resultWorldPos[0]);
		break;
	
	case MotionEvent.ACTION_DOWN:
		// Only start the game when the user clicks on the screen
		State.setGamePaused(false);
		break;
	}
	return true;
}
 
Example 2
Source File: CollisionDetection.java    From android-3D-model-viewer with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Map window coordinates to object coordinates.
 *
 * @param height                viewport height
 * @param width                 viewport width
 * @param modelViewMatrix       model view matrix
 * @param modelProjectionMatrix model projection matrix
 * @param rx                    x point
 * @param ry                    y point
 * @param rz                    z point
 * @return the corresponding near and far vertex for the specified window coordinates
 */
private static float[] unProject(int width, int height, float[] modelViewMatrix, float[] modelProjectionMatrix,
                                 float rx, float ry, float rz) {
    float[] xyzw = {0, 0, 0, 0};
    ry = (float) height - ry;
    int[] viewport = {0, 0, width, height};
    GLU.gluUnProject(rx, ry, rz, modelViewMatrix, 0, modelProjectionMatrix, 0,
            viewport, 0, xyzw, 0);
    xyzw[0] /= xyzw[3];
    xyzw[1] /= xyzw[3];
    xyzw[2] /= xyzw[3];
    xyzw[3] = 1;
    return xyzw;
}