Author Topic: Camera moving towards an object  (Read 1791 times)

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Camera moving towards an object
« on: July 19, 2013, 11:23:33 pm »
Hey!
I try to move my camera to an object with this line:
Code: [Select]
world.getCamera().moveCamera(planet.getCenter(), speed);Shouldn't the camera stop moving in the center?
The Camera actually moves through the center and on the other side out.
I watched the distance between the camera and the center of the object, and the center is on the right place.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Camera moving towards an object
« Reply #1 on: July 20, 2013, 08:53:50 pm »
You are mixing spaces here. What you want to feed into this method is the camera's translation in world space. What you do feed it is the center of an object in object space. That this makes the object move towards the center of your object is just a coincidence. What you actually want is to calculate the direction vector between the camera and what Object3D.getTransformedCenter() returns and move the camera by a fraction of it until you reach the center (or are very close).

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: Camera moving towards an object
« Reply #2 on: July 21, 2013, 03:49:16 pm »
Ok, but how do i calculate the direction vector between the camera and Object3D.getTransformedCenter()?
I thought this would do it, but i was wrong:
Code: [Select]
world.getCamera().moveCamera(world.getCamera().getPosition().calcAdd(planet.getTransformedCenter()), speed);

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Camera moving towards an object
« Reply #3 on: July 23, 2013, 09:44:13 pm »
Just subtract the camera's position from the transformed center. It's basic vector math: