Sign in to follow this  

How to calculate aim for gluLookAt

This topic is 4334 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Posted this on OpenGL.org and didn't get but one response who directed me to a book, so I'll try here. I'm programming in C++ and using OpenGL. I want a completely free camera that can rotate on all three axes. When I press up, I want my camera to rotate up in relation to my current view. Err as in, rotate in whatever direction LOOKS like up to me at the time. Like if I was at 0, 0, 0 and looking at 0, 1, 0 with my up at 1, 0, 0 and I press up and rotate 90 degrees that way, I should be looking at 1, 0, 0 with my up at 0, -1, 0. And if I hit left I want it to rotate in whatever direction looks left to me. This seems pretty complicated to me. I know how to use sin, cos, tan. I don't know what arctangent is or quaternions or any of those other words I hear used on this forum. So using baby words, can anyone explain to me how to calculate what position my aim and up should be at after rotating? And if it involves complicated concepts or new trig functions could you do your best to explain them to me? In short, could you explain it like you were trying to explain it to Jack O'Neill from Stargate. If he wouldn't understand it, chances are I won't either =). Thanks in advance.

Share this post


Link to post
Share on other sites
To jyk:
Right now I'm only worrying about a FPS/spectator camera, so I'll just ask about that. Where did you derive those methods from? Is there somewhere that would explain it more? Also would it be better to use quaternions for camera orientation/rotation?

Share this post


Link to post
Share on other sites
Quote:
Original post by Ganoosh_
To jyk:
Right now I'm only worrying about a FPS/spectator camera, so I'll just ask about that. Where did you derive those methods from?
You can think of this sort of motion in terms of spherical coordinates, or Euler angle pairs (either way it reduces to basically the same thing).
Quote:
Is there somewhere that would explain it more?
I would start by googling 'spherical coordinates', 'spherical cartesian coordinates conversion', 'euler angles', and 'euler angles matrix conversion', after which the code I linked to should make a bit more sense. Keep in mind that the examples you find online might not match the examples in the code exactly due to differences in which direction is considered up, and how latitude is measured.
Quote:
Also would it be better to use quaternions for camera orientation/rotation?
Short answer: no.

Longer answer: I can't think of a single reason to use quaternions for FPS/spectator motion; for 6DOF motion they still aren't strictly necessary, but may offer some advantages in certain circumstances.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ganoosh_
Also would it be better to use quaternions for camera orientation/rotation?


For a camera, I've found that it is generally better to use a matrix than a quaternion. The usual reasons for using a quaternion (speed, stability, and size) are not that strong.
  • Any speed advantage is nullified because you must convert the quaternion to a matrix anyway.
  • If stability is a problem, you can orthonormalize the matrix occasionally. The performance cost of an occasional orthonomalize would be negligible.
  • Even if you had 100 cameras, the savings (in terms of size) would only be 2k (with 4-byte floats).

Share this post


Link to post
Share on other sites

This topic is 4334 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this