I'm trying to rotate a camera in c++ but all I succeeded to do is rotate the object himself or rotate the camera around the object i can't figure it out. What I want is rotate the camera on itself without moving it.

For example to rotate left, I did this:

camera.orientation = (Quaternion<float>(1,Direction<float,3>({0,-1,0}))*camera.orientation).to_norm();

Each time I draw, i apply the transformation below to all the point of the object.

transformation = cameraProj.getInverse() * (translation * (scale * rotation))

where camera.orientation is a quaternion and 1 is the angle.

I'm using apparently the global axis but it feels like the camera isn't at the origin while it's well 0,0,0.

Here a sample of what happens when i rotate to the left: https://www.youtube.com/watch?v=g4XsO08iqEw&feature=youtu.be

Thank you

  • \$\begingroup\$ Have you tried exchanging the order of multiplication? \$\endgroup\$ – DMGregory Dec 1 '18 at 13:02
  • \$\begingroup\$ Yes I did it changes the way of rotation but not as expected. when the camera is at a position (0,0,0), the environnement will turn around the camera if i'm using global axis, will not it ? \$\endgroup\$ – Antigone Dec 1 '18 at 13:20
  • \$\begingroup\$ Can you describe the symptoms that are unexpected? \$\endgroup\$ – DMGregory Dec 1 '18 at 13:22
  • \$\begingroup\$ Here what happens when i want to rotate to the left: youtube.com/watch?v=g4XsO08iqEw&feature=youtu.be I never touch to the camera position when i draw, i only transform the object. Do i have to do something else ? \$\endgroup\$ – Antigone Dec 1 '18 at 13:48
  • \$\begingroup\$ Also, no matter what action i do (rotate, scale...) I always transform the object with this: transformation = cameraProj.getInverse() * (translation * (scale * rotation)). Would it be the problem ? \$\endgroup\$ – Antigone Dec 1 '18 at 14:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.