Simple Viewing Question

Started by
2 comments, last by Digitalfragment 17 years, 6 months ago
I'm trying to implement gluLookAt by using glTranslatef, glScalef and glRotatef but I'm having some serious problems doing so. I'm working in a parallel projection model as well. Basically I have a point in space at 20,20,0 and I'd like to view towards the point 5,10,5. So first I move my camera to the point 20,20,20 using glTranslatef, then I rotate it about the z-axis to be facing in the right direction, but after that rotation when I try and rotate about the y-axis it becomes distorted because I have already made the z rotation... So should I do something like instead of using two rotation calls, just use one with a normal pointing at like Normalize(20-5, 20-10, 0-5)? Then find the angle between the current viewing angle and where I want it to be? I'm really lost on this problem... Any help would be greatly appreciated.
"Real men don''t use parachutes" -Guy in Firearms
Advertisement
It might be easier to just construct the viewing matrix for the camera instead of having to go through the trouble of translating, rotating, and scaling.

void SetLookAt( const Vector & vEye,                const Vector & vLookat,                const Vector & vUp ){    // determine the new n    Vector vN = vEye - vLookat;    // determine the new u by crossing with the up vector    Vector vU = vUp ^ vN;    // normalize both the u and n vectors    vU.Normalize(); vN.Normalize();    // determine v by crossing n and u    Vector vV = vN ^ vU;    // create a model view matrix    float fModelView[16] =    {       vU.fX,        vV.fX,        vN.fX,        0.0f,       vU.fY,        vV.fY,        vN.fY,        0.0f,       vU.fZ,        vV.fZ,        vN.fZ,        0.0f,       -(vEye * vU), -(vEye * vV), -(vEye * vN), 1.0f    }    // load the model view matrix    // the model view matrix should already be active    glLoadMatrixf(fModelView);}


This is a vector camera and might do the trick that you are looking for.

U is the unit vector that points to the right of the camera position. V is the unit vector that points upward from the camera position. N is the unit vector that points in the opposite direction of the view. For example, if the camera was looking down the negative z-axis, then the unit N would be pointing in the positive z direction. The upper 3x3 matrix then describes the orientation of the camera.

The translation portion of the matrix maps the camera to the origin.

Hope this helps.
Thanks for the answer but unfortunately my professor is asking us to just use glRotatef, glTranslatef and glScalef... for some stupid reason.
"Real men don''t use parachutes" -Guy in Firearms
@Xero_Tolerance, the reason is so you understand how how matrix math works and dont just take the functionality for granted.

The information you are looking for IIRC is in the OpenGL Red Book (available in this site's Resources area)

This topic is closed to new replies.

Advertisement