www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Yerst on July 19, 2013, 11:23:33 pm

Title: Camera moving towards an object
Post by: Yerst 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.
Title: Re: Camera moving towards an object
Post by: EgonOlsen 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).
Title: Re: Camera moving towards an object
Post by: Yerst 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);
Title: Re: Camera moving towards an object
Post by: EgonOlsen on July 23, 2013, 09:44:13 pm
Just subtract the camera's position from the transformed center. It's basic vector math:

(http://cnx.org/content/m12112/latest/norm5.png)