Alright, I have to find out if an object in my world is 100% visible.
What I’m doing right now to find this out is color picking. Rendering in unique colors is going fine, it was very easy to accomplish this.
After rendering in unique colors I make use of gluProject to find out which pixels I must test for possible other colors then my to be scanned object. But this is not working at all, I’m getting weird pixel locations like -y results while I have the to be scanned object in plain sight and other bad stuff like that.
At the part of drawing the to be scanned object I store the movelview, projection and viewport in public variables so that the object that is doing the scan can use send those to gluProject.
Here is the part where I’m drawing the to be scanned object and also saving the modelview, projection and viewport:
glRotatef(xRotation, 1, 0, 0); //Camera rotation
glRotatef(yRotation, 0, 1, 0); //Camera rotation
glPushMatrix();
set_color4f(0.5, 0.5, 0.5, m_Alpha); /* !!!This is not an OpenGL function, this is a local function which looks if the current render is in color picking mode or not!!! */
glTranslatef(m_Location.x,
m_Location.y,
m_Location.z);
glRotatef(huniplacer::utils::deg(m_Rotation), 0, 1, 0);
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
glGetDoublev(GL_PROJECTION_MATRIX, projection);
glGetIntegerv(GL_VIEWPORT, viewport);
... drawing code - not important ...
glPopMatrix();
glSwapBuffers();
And here is the part where gluProject is used to find out at which pixels the to be scanned object should be visible if nothing is in front of it:
for (float x = -scan_target->getSize().x/2; x < scan_target->getSize().x/2; x+= precision) {
for (float z = -scan_target->getSize().z/2; z < scan_target->getSize().z/2; z+= precision) {
GLdouble pixel_x = -1;
GLdouble pixel_y = -1;
GLdouble pixel_z = -1; //This value always ends up as 1, the screen has no depth. Pay no attention to this value here & below
GLint testtt = gluProject(x + scan_target->getLocation().x,
scan_target->getLocation().y + scan_target->getSize().y/2,
z + scan_target->getLocation().z,
scan_target->get_modelview(),
scan_target->get_projection(),
scan_target->get_viewport(),
&pixel_x,
&pixel_y,
&pixel_z);
... more code that is not of interest right now ...
}
}
Am I not understanding how the matrices in OpenGL work? Because I guess it must be that I’m giving gluProject wrong matrices (the modelview, projection and viewport matrices).