Jump to content
  • Advertisement

Archived

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

Nibbles

x, y, z point in view?

This topic is 6250 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, How do I check to see if an (x,y,z) point is within the viewport? Thank ya kindly, Scooter Email Website
"If you try and don''t succeed, destroy all evidence that you tried."

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Do a search for frustum culling.

Share this post


Link to post
Share on other sites
use gluProject on the point and check if x is >= 0 and < viewport[2] and y is >= 0 and y is < viewport[3]. the z part is just for depth testing. You don''t need it.

example code: (Am I nice or what?)

inline bool pointisonscreen(float x, float y, float z)
{
GLdouble modelMatrix[16];
GLdouble projMatrix[16];
GLdouble sx,sy,sz;
GLint viewport[4];

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

gluProject(x,y,z,modelMatrix,projMatrix,viewport,&sx,&sy,&sz);

if(sx >= 0 && sx < viewport[2] && sy >= 0 && sy < viewport[3])
return true;
else
return false;
}

I just threw that together. I can''t say for sure that it will work.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!