Jump to content
  • Advertisement
Sign in to follow this  
K A Z E

How to calculate aim for gluLookAt

This topic is 4679 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
Advertisement
For what you want to do, gluLookAt is not appropriate.

I didn't look very closely at the code that jyk posted in his link, but I'm sure it works great.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!