Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Best way to tell if a 2D polygon is in front of another 2D polygon?

Asked by 7 years ago
Edited 7 years ago

Ok I know this may sound confusing but what I'm basically doing is I'm taking 3D points in the world-space and converting them to 2D points in the screen-space based on the CFrame of an artificial camera. I know that was hard to understand so here's a gif of what I'm doing.

The code runs fine, but my only problem is that I have no way of placing triangles in front of each to prevent issues like this.

The camera is looking up at the object from the bottom and the red surface is the bottom so all that should be visible is the red surface, but as seen from that picture, that's not the case.

My question is this: what is the most efficient way for me to check if the 3D triangle is in front of or covering another 3D triangle so that I can change the ZIndices of the respective 2D triangle?

1 answer

Log in to vote
0
Answered by 7 years ago

Z Depth

When you convert the spaces, you're converting it into the object space of the camera (Or it's defaultly from the object space of the camera, if it's being represented internally). In this case, you've already translated the X/Y to the respective X/Y projected values. All you need to do now is check the magnitude of the vector or the Z depth for occlusion.

Doesn't make sense? Tell us more about how you're representing/translating and drawing, and I'll have a look and come up with a less generalized answer.

Ad

Answer this question