I'm new to Android App programming and working on a very small 2D Engine with OpenGL ES.
I've done most of drawing stuff and now i want to start with inputs.
My engine works like a 3d engine, i use relative coordinates (0.1f for example, not in pixels).
How can i now detect on which sprite for example the user touched?
I've tried to get opengl working with absolute coordinates (pixels), but i couldn't get it to work, so i think i must go on with the relative coordinates (And its better because of the different display size of some phones).
I hope someone can give me a hint how to do this.
-KennuX
Edit://
I found gluUnProject after hours of searching.
I wrote a little function that should re-calculate the coordinates.
Here's the code:
- Code: Select all
public static void getCoords(int[] viewPort, float[] projection, float[] modelview, float x, float y)
{
float[] pos = new float[4];
int view[] = {0, 0, (int)320, (int)480};
y = view[3] - y;
GLU.gluUnProject(x, y, 0.0f, modelview, 0, projection, 0, view, 0, pos, 0);
}
This is how i get the viewPort, projectionMatrix and modelviewMatrix:
- Code: Select all
FloatBuffer TempBuffer = ByteBuffer.allocateDirect(16*4).asFloatBuffer();
((GL11)gl).glGetFloatv(GL11.GL_PROJECTION_MATRIX, TempBuffer);
projectionMatrix = CoordinateCalculator.getFloatArray(TempBuffer);
TempBuffer = ByteBuffer.allocateDirect(16*4).asFloatBuffer();
((GL11)gl).glGetFloatv(GL11.GL_MODELVIEW_MATRIX, TempBuffer);
modelviewMatrix = CoordinateCalculator.getFloatArray(TempBuffer);
IntBuffer intBuffer = ByteBuffer.allocateDirect(4*4).asIntBuffer();
((GL11)gl).glGetIntegerv(GL11.GL_VIEWPORT, intBuffer);
viewMatrix = CoordinateCalculator.getIntArray(intBuffer);
From my function i always see NaN NaN NaN NaN in Logcat in Eclipse.
So i've just debugged the program a bit and got this viewPort Matrix:
- Code: Select all
x: 0
y: 0
width: 1073807360
height: -536805376
I think this can't be right.
Here's the projection matrix:
- Code: Select all
0: -1.4558682E-6
1: 0.0
2: 0.0
3: 0.0
4: 0.0
5: 8.444138E34
6: 0.0
7: 0.0
8: 0.0
9: 0.0
10: -4.0015465E-23
11: 4.6185E-41
12: 0.0
13: 0.0
14: 132406.97
15: 0.0
And here is the modelview matrix:
- Code: Select all
0: 4.6006E-41
1: 0.0
2: 0.0
3: 0.0
4: 0.0
5: 4.6006E-41
6: 0.0
7: 0.0
8: 0.0
9: 0.0
10: 4.6006E-41
11: 0.0
12: 0.0
13: 0.0
14: 0.0
15: 4.6006E-41
I hope someone can say me if these matrices are right and my functions to get them are right, too.

