I have read about the damping. Basically it is smooth camera movement. However, I am not sure how to implement damping using C++, OpenGL, and GLM.
Help me with a small sample code.
I have read about the damping. Basically it is smooth camera movement. However, I am not sure how to implement damping using C++, OpenGL, and GLM.
Help me with a small sample code.
You can implement inertia. This would make your camera slow down smoothly. To do this, you can declare the camera as an object. You can do this:
class Movable
{
public:
float x;
float y;
float z;
float xmovement;
float ymovement;
float zmovement;
float xrot;
float yrot;
}
Movable camera;
//omitted code that handles camera acceleration itself
camera.x+=camera.xmovement;
camera.y+=camera.ymovement;
camera.z+=camera.zmovement;
camera.xmovement*=0.99f;
camera.ymovement*=0.99f;
camera.zmovement*=0.99f;
glm::mat4 ViewMatrix=glm::perspective(90f, 1.0f, 0.001f, 30.0f)*glm::lookAt(glm::vec3(camera.x, camera.y, camera.z), glm::vec3(camera.x+sin(xrot), camera.y+tan(yrot), camera.z+cos(xrot)), glm::vec3(0.0f, 1.0f, 0.0f));
//Then pass ViewMatrix into your Vertex Shader.
Modify the 0.99
constant to a higher value to make the camera stop more slowly, or lower to stop faster.
Please note that the camera might never truly stop. But from a certain point it'll move so slowly that it'll be unnoticeable.