3
votes

I have been searching on the internet for a while now, for a solution with nothing. What I want to know is how to implement a swing/bobbing motion in a 3D Camera in OpenGL(or DirectX) like you find in Minecraft, Call of Duty, etc. I tried cycloids, while they work I can't get the direction to work correctly.

1

1 Answers

7
votes

What do you think about the following.

  1. compute cam_pos, cam_dest, cam_up as usual.
  2. compute cam_right as cross (cam_pos, cam_up)
  3. create a float camera_time (if walking, camera_time += delta_time; )
  4. compute offset_factor = sin(camera_time);

Then you can call gluLookAt or similar function as follows.

gluLookAt(cam_pos + cam_right * offset_factor, cam_des + cam_right * offset_factort, cam_up)

This will make the camera swing from right to left. You can add the same for the cam_up vector with some tweaking.