Hi,
I am a newbie to opengl and currently trying to build a simple app
using opengl which will add my object on touch. But I cannot get the
right 3D coordinate of the touch to add my object.
Here is my code for draw:
public void draw(GL10 gl) {
for (GLObject glObject : list) {
if (glObject != null) {
gl.glLoadIdentity();
glObject.draw(gl);
}
}
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
// only for test so whatever action the ontouchlistener return
(ACTION_MOVE or ACTION_DOWN, only add one // object)
if (isTouching) {
boolean addObject = false;
for (GLObject glObject : list) {
addObject = glObject.checkTouch(gl, x, y);
}
if (!addObject) {
i++;
Log.d("i", i + "");
addGLObject(gl);
}
isTouching = false;
}
}
code for getting 3d coordinate
private float[] getWorldCoordinate(GL10 gl, int x, int y) {
float[] modelMatrix = new float[16];
float[] projMatrix = new float[16];
int[] viewport = {0, 0, Main.SCREEN_WIDTH, Main.SCREEN_HEIGHT};
getMatrix(gl, GL10.GL_MODELVIEW, modelMatrix);
getMatrix(gl, GL10.GL_PROJECTION, projMatrix);
float[] output = new float[4];
// z always = -10
GLU.gluUnProject(x, viewport[1] + viewport[3] - y, -10,
modelMatrix,
0, projMatrix, 0, viewport, 0, output, 0);
return output;
}
code for get gl matrix
private void getMatrix(GL10 gl, int mode, float[] mat) {
GLView.matrixTrackingGL.glMatrixMode(mode); //matrix tracking
from
api sample
GLView.matrixTrackingGL.getMatrix(mat, 0);
}
So can anyone helps me find out what my problem is?
Many thanks
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en