Hi All,
Right, I've got a nice camera that I can move about my scene. I can rotate and translate and do anything that I like to it (within the context of use). Now I'm using gluLookAt() to do all of the manipulations and calculate the modelview matrix that opengl uses to rasterize the scene. However I want get rid of this function call and therefore the utility library that I'm statically linking in (also reduces the size of my final exe ;)). But I do not know what operations the gluLookAt function does in order to get the final modelview matrix. I know that it takes three vectors: the eye position, the focal point and the up vector (an orthonormal system) but that is as far as my knowledge goes. Any help on this greatly appreciated.
netwalker.
Ditching gluLookAt
Started by netwalker, Aug 15 2007 10:52 AM
6 replies to this topic
#1
Posted 15 August 2007 - 10:52 AM
#2
#3
Posted 15 August 2007 - 11:23 AM
Additionally, if you have access to the game programming gems books, there are some very interesting articles about building camera matrices in less-obvious ways.
http://iki.fi/sol - my schtuphh
#4
Posted 15 August 2007 - 11:43 AM
I believe there's also a degenerate case that you need to handle. If the forward vector is 0 in the x and z-axis, you need to set the x-axis of the up-vector to the negative of the forward y-axis, and also set the y and z axis in the up-vector equal to 0.
"Say WTF?!" ;)
"Say WTF?!" ;)
r - right vector, u = up, f = forward matrix = | r.x r.y r.z | | u.x u.y u.z | | f.x f.y f.z | degen case: f.x = f.z = 0 | r.x r.y r.z | | -f.y 0 0 | | f.x f.y f.z |
http://www.nutty.ca - Being a nut has its advantages.
#5
Posted 15 August 2007 - 12:03 PM
@Sol_HSA: Many thanks. The explainations given by Reedbeta are very clear about what to do. I'm going to give this a try. As far as the Game Programming Gems goes unfortunately I don't have access. They are too expensive and the local library can't get a hold of them :(.
@TheNut. OK WTF!. :). I don't understand though. Why do I have to this?. In my implementation if the forward vector is (0.0f, y, 0.0f) then my up vector would be (0.0f, 0.0f, 1.0f) and right (1.0f, 0.0f, 0.0f). If I formed the 4x4 matrix from those and multiplied that by the modelview matrix what would happen?. Please explain further.
@TheNut. OK WTF!. :). I don't understand though. Why do I have to this?. In my implementation if the forward vector is (0.0f, y, 0.0f) then my up vector would be (0.0f, 0.0f, 1.0f) and right (1.0f, 0.0f, 0.0f). If I formed the 4x4 matrix from those and multiplied that by the modelview matrix what would happen?. Please explain further.
#6
Posted 15 August 2007 - 01:11 PM
It's been a while so I may be a bit rusty on the explanation. It has to do with the way you're going to calculate the up and right vectors, because they're derived from the forward vector. When the forward vector is aligned with the x and z-axis, your up-vector (in my case, up is defined as (0, 1, 0)) will be calculated incorrectly. It's the same problem you have when calculating normals. You never really know if the normal is pointing inside or out. The degenerate case I explained above is one of those cases, so without correction your camera will look backwards instead of forwards.
If you treat your up-vector as something different, your degen case might be different. It's worth exploring to see if you have any issues when your matrix is facing along the plane.
If you treat your up-vector as something different, your degen case might be different. It's worth exploring to see if you have any issues when your matrix is facing along the plane.
http://www.nutty.ca - Being a nut has its advantages.
#7
Posted 15 August 2007 - 06:31 PM
I wrote this a while ago:
http://topmost.se/pe...ming/3dmath.zip
There's a pretty neat camera class in there. Beware, though! I used some not-so-standardized conventions.
http://topmost.se/pe...ming/3dmath.zip
There's a pretty neat camera class in there. Beware, though! I used some not-so-standardized conventions.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












