Reputation: 4357
I want to show a Perspective cube, so I should calculate whether the point in cube is Visibility.
Like the picture, the red vertex should be invisible, while the others should be visible.
Can anyone give me a formula to calculate it?
The cube may be Rotated that I have no way to do it.
I try use HitTest to do it but it have a Poor performance.
I want to know a formula to calculate whether the point and face and line is visibility.
Edit:
The point is any point on the line.
I build it with Media3D.
Upvotes: 3
Views: 1049
Reputation: 231
Try taking the dot product of the "camera vector" (this is usually (0,0,1)) and all of the normal vectors of the cube faces that the vertex in question touches.
If any of the dot products return a negative value, then the angle between the camera vector and the normal vector of the respective cube face is greater that 90 degrees and is therefore "facing" the camera.
If the point of interest is a vertex, you'll be running three dot products. If the point of interest is along a line between vertices, you will only calculate two.
Upvotes: 1
Reputation: 314
If any of the faces connected to the vertex has a normal facing the camera (see back face culling), the vertex is visible. This should be pretty quick to calculate.
Upvotes: 1