1

How can I check if a node in my scene graph is actually seen by my main camera?

In my particular use-case, I want to know if a node is (in the area) behind the camera.

Thanks.

cassava
  • 578
  • 6
  • 14

1 Answers1

2

You only need to know 3 things to do this: the view direction, the position of the camera and the position of the node (all in the same coordinate system).

Then the test is easy: dot(view, nodePos-cameraPos)<0 where dot(v1, v2) is the dot product of 2 vectors in other words v1.x*v2.x + v1.y*v2.y + v1.z*v2.z.

ratchet freak
  • 47,288
  • 5
  • 68
  • 106
  • I have `cam->getViewMatrixAsLookAt(eye, center, up)`. And `n = node->getBound()->center()`. Then I do `center * (n - eye)`? Do I understand that correctly? – cassava Nov 27 '14 at 20:48
  • 1
    `(center-eye)*(n-eye)` actually – ratchet freak Nov 27 '14 at 20:52
  • It works, but I have to do something like `(center-eye)*(n-eye) < ε`. If I set it to zero, it doesn't catch all objects (maybe I have a strange setup.) Otherwise it seems to work, so I'll accept this answer. :-) – cassava Nov 29 '14 at 11:43