skooter500/BGE — pull request #6 by ymko13 (2013-12-25 00:37:45+00:00)
Title: Updated the camera

Updated the camera to allow following an object from a distance and perspective view on an object(from a distance under a certain angle).

The camera's position and look vectors are smoothed using linear interpolation.

For a perspective camera:
camera->PerspectiveView(ship1, glm::vec3(20,5,0), glm::radians(20.0f), glm::radians(60.0f), 1.0f, 0.85f);
where:
ship1 is the pointer to a game component to follow
glm::vec3(20,5,0) is the distance from the object
glm::radians(20.0f) is the x angle
glm::radians(60.0f) is the z angle
1.0f is the multiplier of the look vector(how far from an object you want to look at in the direction which the object is looking)
0.85f is the interpolation value between 0 and 1, the bigger the value the smoother the transition, but if the value is too high it can stop following properly when the speed of the object is high.

For a rear camera:
camera->RearView(ship1, -12.0f, 5.0f, 1.0f, 0.85f);
where:
ship1 is the pointer to a game component to follow
-12.0f is the distance at which to follow
5.0f is the height at which to follow
1.0f is the multiplier of the look vector(how far from an object you want to look at in the direction which the object is looking)
0.85f is the interpolation value between 0 and 1, the bigger the value the smoother the transition, but if the value is too high it can stop following properly when the speed of the object is high.

Interpolation value can also be coded using the variables, such as taking the distance between the real and fake cameras and depending on how close they are having the value range from 0 to 1 or multiply the passed interpolation by that value, but it hasn't been done here as I think it's a limitation rather than a good addition.