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."
x, y, z point in view?
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.
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.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement