PDA

View Full Version : Polygons overlapping detection based on camera?



mini3D
05-09-2011, 08:53 PM
I found some algorithms for 2D polygons collision detection. It's relatively simpler than 3D space.

Let me simplify my question: There are two polygons in 3D space. According to camera operation (projection transformation), one polygon may seem to be completely or partially behind the other one.
Here is the setting method for the camera:


/**
* @param gl The GL context.
* @param glu The GL unit.
* @param distance The distance from the screen.
*/
private void setCamera(GL2 gl, GLU glu, float distance) {
// Change to projection matrix.
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();

// Perspective.
float widthHeightRatio = (float) getWidth() / (float) getHeight();
glu.gluPerspective(45, widthHeightRatio, 1, 1000);
glu.gluLookAt(0, 0, distance, 0, 0, 0, 0, 1, 0);
gl.glRotatef(-45, 0, 1, 0);

// Change back to model view matrix.
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
}
How can I detect if one polygon is in back of the other one?
Should I apply the projection matrix to these polygons for setting up their axes as camera view?

Thank you for your help!!

mini3D
05-10-2011, 07:58 AM
I have the position (x,y,z) of my camera, and also have the center point of both polygons.
Therefore, I can calculate their distances to the camera from their center points. However, by comparing their distances, it's not sufficient to determine if one is in back of the other one.

Should I have to transform the objects coordinate system based on the rotation and translation of my camera?
Could someone know some approaches to solve this issue? Thank you so much~ :)