How to detect the object have moved behind the camera?

Started by gamenewer, November 19, 2014, 06:32:17 AM

Previous topic - Next topic

gamenewer

Hello ,   I have some trees in my game ,   when one tree  out of view ( behind the camera and no long see)  I will tranlate this tree to ahead , do this again and again  , so looks there have many trees on road side.  My question is  How to detect the tree  is behind the camera (or out of view) ? I think maybe have simple way to do this , Thanks a lot  :)

EgonOlsen

You can use the dot product for that. Take the camera direction and the vector from the camera's position to the tree's position in world space (you can get that from tree.getTransformedCenter() for example) and do dirCam.calcDot(camTree);. If it's <0, the tree is behind the camera. However, keep in mind that what is behind might move in front again if the camera turns...

gamenewer