GLU.gluUnProject problem

Problems with Canvas, OpenGL, etc...

GLU.gluUnProject problem

Postby kenjinsakura » Tue Jul 20, 2010 2:51 am

Hi, I'm having some trouble using gluUnProject. Right now, it seems you cant get the model and projection matrix from the gl renderer, so to use them in gluUnproject, you have to store them yourself, right? So I calculate the projection and model matrices separately and use pass those values themselves to the renderer to make sure that they're correct:
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?
kenjinsakura
Freshman
Freshman
 
Posts: 6
Joined: Fri Jun 04, 2010 5:27 am

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 1 guest