Author Topic: How to detect the object have moved behind the camera?  (Read 1886 times)

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
How to detect the object have moved behind the camera?
« on: November 19, 2014, 06:32:17 am »
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  :)
« Last Edit: November 19, 2014, 10:33:49 am by gamenewer »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to detect the object have moved behind the camera?
« Reply #1 on: November 19, 2014, 07:38:25 am »
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...

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: How to detect the object have moved behind the camera?
« Reply #2 on: November 19, 2014, 10:37:34 am »
Thanks for your help ,I will try it :)