Archived

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

BlackBox

screen visible border question / visual range object

Recommended Posts

When drawing objects in 3d, How do I know when an object gets out of the visual range of the screen? Example I have a cube in the middle of the screen 0,0,0 (x,y,z), if I move the cube in the x axis when it will go out of the screen and stop being visible? I know it depends on the z axis but is there a way of knowing when it goes out of screen without doing the time wastefull test programs? Thank you. ps. Im writing this because I want to have a mouse on screen draw by a simple figure, but how do I prevent the mouse going out of screen! ARRHH ---------------------------- ^_^

Share this post


Link to post
Share on other sites
quote:
Original post by vincoof
gluProject or gluUnProject may help you too.



Any tip on how can I implement this.

Thankyou for your answers!


----------------------------
^_^

Share this post


Link to post
Share on other sites
quote:
It all depends on your projection matrix.

Not only. It also depends on the modelview matrix.

gluProject and gluUnProject are GLU functions. Please wait a few seconds...

[edited by - vincoof on January 28, 2003 8:49:17 AM]

Share this post


Link to post
Share on other sites

  
int is_point_visible(GLdouble x, GLdouble y, GLdouble z)
{
GLdouble modelMatrix[16];
GLdouble projMatrix[16];
GLint viewport[4];
GLdouble winx, winy, winz;

glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
glGetIntegerv(GL_VIEWPORT, viewport);

gluProject(x, y, z, modelMatrix, projMatrix, viewport, &winx, &winy, &winz);

return (winx >= viewport[0]) && (winx <= viewport[0]+viewport[2]) && (winy >= viewport[1]) && (winy <= viewport[1]+viewport[3]);
}

Please note there are alot of calls to glGet which are pretty slow. If you have to do it for one point only, it''s really affordable. For more points you may want to optimize it by grouping calls to glGet.

Share this post


Link to post
Share on other sites