3

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.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
lindexi
  • 4,182
  • 3
  • 19
  • 65
  • any formulae would be slower than the hit test as the hit test is using the best formula, the idea is simple calculate a line from the camera to the point, then with bounding boxes eliminate all shapes that don't intersect the line, next using plane geometry find any shapes that have a plane that intersects the line, next check the transparency of any intersections if there are no opaque intersections you can see the point – MikeT Mar 29 '17 at 12:26
  • @MikeT I cant use the Z-Buffer to calculate.I try the hit test that have a poor performence. – lindexi Mar 29 '17 at 12:33
  • i never mentioned the Zbuffer and hit test will have better performance than anything else as it already does exactly what you would be doing if you want more details of the process see here http://ericsink.com/wpf3d/6_RayTracing.html – MikeT Mar 29 '17 at 12:38
  • @MikeT Thx,but the hit test will wait the Rendering.So I want to have a formula that cant wait it. – lindexi Mar 29 '17 at 12:42
  • What do you want to achieve with this information? – wkl Apr 07 '17 at 10:16
  • @wkl I want do a education application to high school student who want understand the 3D – lindexi Apr 08 '17 at 11:23
  • An easy way to do this would be to raycast from that point to the camera and see if you intersect the cube (you would need to do this for every point of the cube, so 8x per frame). if you are looking for raycasting algorithms, look here : https://gamedev.stackexchange.com/questions/18436/most-efficient-aabb-vs-ray-collision-algorithms – Timothy Groote Apr 18 '17 at 07:37
  • @TimothyGroote Thx for your reply. – lindexi Apr 18 '17 at 07:56

2 Answers2

1

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.

1

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.

Drew Sands
  • 211
  • 2
  • 8