# Thread: Polygons overlapping detection based on camera?

1. ## Polygons overlapping detection based on camera?

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:
Code :
```    /**
* @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);

// 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);
}```
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!!

2. ## Re: Polygons overlapping detection based on camera?

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~

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•