tags:

views:

43

answers:

1

Right now my application rotates on camera.rotationX, Y Z and does a -translation of camera.x,y,z on the modelview matrix. How could I equivocate this to a call to gluLookAt?

Thanks

basically how could I get this:

    glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();

//starts here
     glRotatef(Camera.rotx,1,0,0);
     glRotatef(Camera.roty,0,1,0);
     glRotatef(Camera.rotz,0,0,1);

     glTranslatef(-Camera.x , -Camera.y - 4.5,-Camera.z );

Instead into a call to gluLookAt which would make it look the same.

Thanks

The reason I want to do this is because I found a fustrum culling class that works with gluLookAt as seen below

void FrustumG::setCamDef(Vec3 &p, Vec3 &l, Vec3 &u) {

    Vec3 dir,nc,fc,X,Y,Z;

    Z = p - l;
    Z.normalize();

    X = u * Z;
    X.normalize();

    Y = Z * X;

    nc = p - Z * nearD;
    fc = p - Z * farD;

    ntl = nc + Y * nh - X * nw;
    ntr = nc + Y * nh + X * nw;
    nbl = nc - Y * nh - X * nw;
    nbr = nc - Y * nh + X * nw;

    ftl = fc + Y * fh - X * fw;
    ftr = fc + Y * fh + X * fw;
    fbl = fc - Y * fh - X * fw;
    fbr = fc - Y * fh + X * fw;

    pl[TOP].set3Points(ntr,ntl,ftl);
    pl[BOTTOM].set3Points(nbl,nbr,fbr);
    pl[LEFT].set3Points(ntl,nbl,fbl);
    pl[RIGHT].set3Points(nbr,ntr,fbr);
    pl[NEARP].set3Points(ntl,ntr,nbr);
    pl[FARP].set3Points(ftr,ftl,fbl);
}
A: 

Well your eye position E will be (Camera.x, Camera.y + 4.5, Camera.z). The default view vector V is (0, 0, -1) in OpenGL, if I remember correctly and default up vector U is (0, 1, 0).

So you rotate these two vectors with your camera rotation. See http://en.wikipedia.org/wiki/Rotation_matrix or http://en.wikipedia.org/wiki/Quaternion. Center is then the rotated view vector View vector + Camera vector. Up vector is simply the rotated up vector.

gluLookAt(Camera.x, Camera.y + 4.5, Camera.z, Camera.x + V.x, Camera.y + V.y, Camera.z + V.z, U.x, U.y, U.z)
gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz : glDouble);
tauran