cutting_crew

01-21-2004, 11:18 AM

i am in need of dire help and i know i am close to finishing this but i have been looking at the code for too too long now i think. i have a 3D terrain drawn with GL_TRIANGLE_STRIPS and with variating depths, so when you click on it you get a litttle probe where you clicked with the mouse with the corresponding depth value. i do this through the gluUnProject call -- i shall give you the code here:

//give the mouse coordinates and the vector wpos will be set to the world coordinates under the pointer

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;

//if((x >= 0 && x <= 5) && (y >= -1 && y <= 1))

glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z); //get the pixel(in 2D) w/respect to 3D Coordinates

if(z == 1.0) //depth buffer max depth 1.0 is the default, PIXEL at mouse pointer is below the heightmap plane

return FALSE;

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

return TRUE;

}

wpos is updated and the depth is printed out. what i NEED to do for myself if figure out what actual point on the heightmap corresponds to that certain depth. so lets say the terrain has 1,000 points in it. when i click and receive a depth value of the terrain i also want to print out what point it is. so if i get a depth of 456(feet) maybe point # 278 would be the point at or closest to this depth value. how would i go about getting this point? thanks in advance and i hope i was clear and maybe even helped someone with that snippet of code.

//give the mouse coordinates and the vector wpos will be set to the world coordinates under the pointer

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;

//if((x >= 0 && x <= 5) && (y >= -1 && y <= 1))

glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z); //get the pixel(in 2D) w/respect to 3D Coordinates

if(z == 1.0) //depth buffer max depth 1.0 is the default, PIXEL at mouse pointer is below the heightmap plane

return FALSE;

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

return TRUE;

}

wpos is updated and the depth is printed out. what i NEED to do for myself if figure out what actual point on the heightmap corresponds to that certain depth. so lets say the terrain has 1,000 points in it. when i click and receive a depth value of the terrain i also want to print out what point it is. so if i get a depth of 456(feet) maybe point # 278 would be the point at or closest to this depth value. how would i go about getting this point? thanks in advance and i hope i was clear and maybe even helped someone with that snippet of code.