# 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.

## 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 on other sites
Code for this can be found here. Feel free to ask if you have any questions about the code (or the concepts behind it).

##### Share on other sites
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 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 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?

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 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).

1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633431
• Total Posts
3011834
• ### Who's Online (See full list)

There are no registered users currently online

×