Archived

This topic is now archived and is closed to further replies.

OpenGL_Guru

gluUnProject -- having problems...

Recommended Posts

i am having issues with gluUnProject. what i have is a big bathemetry data set. what i want to do is to be able to draw a "box" around a certain area of the bathemetry. the bathemetry of course has different depths so when i click on the data i would like to click on the level plane of the terrain, as if there were a plane to click on. has anyone ever successfully done this? i used gluUnProject before, but it was in windows and i am doing the same thing here as well. the only thing that is different that i can see is that i dont have the windows version of RECT which holds the windows dimensions. i am doing this now with GLUT. any help, thoughts or ideas would be appreciated! thanks!

Share this post


Link to post
Share on other sites
Check out Chapter 13 of the OpenGL Red Book.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan

Share this post


Link to post
Share on other sites
if you are talking about the Object Selection that is not what i am looking for. i want to be able to pick anywhere on my height map and for it to give me the corresponding 3D x,y,z coordinate. the thing is is that my heightmap has different depth values to it. so somehow i have to be able to say i want the surface of the heightmap to be where i want to check. here is my conversion code..

so basically if my mouse is in a down state i want to be to call the world_coords function...like i said, this code worked in windows but now i am just using glut not a win32 environment.

bool world_coords(GLuint x, GLuint y, GLdouble *wpos)
{
GLdouble model[16], proj[16];
GLint view[4];
GLfloat z;

glGetDoublev(GL_MODELVIEW_MATRIX, model);
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetIntegerv(GL_VIEWPORT, view);

y = view[3] - (GLfloat) y - 1;
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);

if(z == 1.0)
return false;

gluUnProject(x, y, z, model, proj, view, wpos, wpos+1, wpos+2);
return true;
}

void mouse(int button, int state, int x, int y)
{
if (state == GLUT_DOWN)
{
if(world_coords(x, y, world))
mytraj.getFirstPt(world); //retrieve 3D point..hopefully

}

...................
..................
}

Share this post


Link to post
Share on other sites
Ok, something you need to check out: is the depth range returned by glReadPixel() compatible with the range expected by gluUnProject()?

Also, the GL_FEEDBACK render mode was what I was thinking about. It doesn''t depend on you naming your objects.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan

Share this post


Link to post
Share on other sites