- Code: Select all
//the camera matrix
//save the matrix
Matrix.setIdentityM(mtxModel, 0);
Matrix.rotateM(mtxModel, 0, -incline, 1, 0, 0);
Matrix.rotateM(mtxModel, 0, -yRotation, 0, 1, 0);
Matrix.translateM(mtxModel, 0, -position.x, -position.y, -position.z);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glMultMatrixf(FloatBuffer.wrap(mtxModel));
- Code: Select all
//Projection matrix
Matrix.frustumM(mtxProjection, 0, xmin, xmax, ymin, ymax, near, far);
//use the projection matrix
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glMultMatrixf(FloatBuffer.wrap(mtxProjection));
So it displays everything correctly. However, when I use it in gluUnproject, using a point in the center of the screen:
- Code: Select all
int view[] = {0, 0, screenWidth, screenHeight}; //view
gluUnProject(screenWidth/2, screenHeight/2, 0, mtxModel, 0, mtxProjection, 0, view, 0, rayVec, 0);
The vector returned in rayVec is wrong. And somehow, when I move the camera without changing its orientation, the value changes, when it shouldn't since It should just return the vector of the ray from the camera to the center of the screen, right? Am I doing something wrong?
Edit:
Apparently, part of the problem was my confusion with the returned result of gluUnProject. It doesn't return the ray vector from the camera to the screen as I thought, but instead the location in 3D space. With the third parameter ranging from 0 for the near plane and 1 for the far plane (which the android reference pages failed to explain). So I took the returned value, subtractedthe camera position and normalized to get the ray vector.
Also, even after fixing that, the values were quite off. I had to search around the net for another version of gluUnProject before I got the correct values.
It's ok now, but I was just wondering if the android opengl es1.0 gluUnproject is really wrong/incomplete of I'm not getting something right? Anyone else having problems with gluUnProject?

