libgdx/libgdx — pull request #1797 by florianbaethge (2014-05-03 10:18:56+00:00)
Title: CameraMovementController for managing camera transitions

Hi everybody,

inspired by a StackOverflow question about camera transitions I've create a "high-level" tool to control the movement of camera positions and look-at positions.

For this I've created a `CameraPath` class, which basically represents a spline with additional parameters to hold the state of the movement as well as how to move it. Also, I've written a `CameraMovementController`, which can be used to control the paths and run the transition animations.

A `Camera` instance can be assigned with a `CameraMovementController` which then will manage the transformations.

`CameraMovementController movementController = new CameraMovementController(camera);`

A `CameraMovementController` will hold up to two `CameraPath` objects, one for animating the camera position and one for animating the lookAt position of that camera. To do so, the controller needs to be updated on each `render()` call:

`movementController.update(Gdx.graphics.getDeltaTime());`

Currently, this allows arbitrary open or close-looped smooth paths which also allow looping a given number of times or infinitely. Also, through simply not assigning a `positionPath` or `lookAtPath` to the controller, it's possible to limit the movement on just animating the position around a fixed lookAt point or changing the lookAt position, but leaving the camera position constant.

Also, a `CameraPath` can be set to use a constant speed instead of the speed that results from the parametrization of the curve it travels along. For starting the animation of the camera position, you simply have to call the `start(...)` method on the CameraPath:

`movementController.positionPath.start(20.0f, -1, true);`
(This will start the animation of the camera position with a duration of 20 seconds for the movement, infinite looping and using a constant speed)

For demonstrating the function of the classes, I've created a new test, which basically extends the Basic3dSceneTest by animating the camera along a path.

![cameramovementcontrollertest](https://cloud.githubusercontent.com/assets/5558920/2870071/64312e8a-d2a9-11e3-96f1-dfcf24f4de31.png)

When using more than one camera, the `CameraMovementController` also provides a `debugDraw(Camera)` method that uses a `ShapeRenderer` to render the paths of that controller from the view of the passed `debugCamera`. As it can be seen in the new test, this allows using some kind of overview-camera to visualize the paths of the camera.

I hope you like this little enhancement. I'm sure there are some users for this, since the 3D api is getting used more and more recently. Also, I'd be happy to write a wiki entry about how to use it, if it gets merged...