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!!