Results 1 to 2 of 2

Thread: glulookat replacement

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2001
    Location
    Bend,No,No
    Posts
    8

    glulookat replacement

    hmm... okay i am writing a 3d engine(isn't everyone?) but i am trying to stay away from glu library not glut or glaux but glu.h... and so i put together some thoughts and came up with a glulookat replacement... but it doesn't seem to work in theory it should but maybe i am missing something small.

    all the functions do what they sound like...

    vec is declared as

    typdef float vec[3];

    used an array for various reasons as opposed to a struct.

    the last parameter of functions is always the result... i replaced gltranslatef with just adding the values to the matrix.

    Maybe someone could help me... maybe i am forgetting to set a certain modelview matrix or something...

    void lookAt(float eyex, float eyey, float eyez,
    float centerx,float centery,float centerz,
    float upx, float upy, float upz)
    {
    vec F,f={0},UP, up={0},s={0},u={0};
    matrix M;

    F[0]=centerx-eyex;
    F[1]=centery-eyey;
    F[2]=centerz-eyez;

    UP[0]=upx;
    UP[1]=upy;
    UP[2]=upz;

    NormalizeVector(F,&f);
    NormalizeVector(UP,&up);

    MultiplyVecs(f,up,&s);
    MultiplyVecs(s,f,&u);

    Reverse(f,&f);


    ZeroMemory(&M,MATRIX4SIZE);

    M[0][0]= s[0]; M[0][1]= s[1]; M[0][2]= s[2]; M[0][3]= 0;
    M[1][0]= u[0]; M[1][1]= u[1]; M[1][2]= u[2]; M[1][3]= 0;
    M[2][0]= f[0]; M[2][1]= f[1]; M[2][2]= f[2]; M[2][3]= 0;
    M[3][0]= -eyex; M[3][1]= -eyey; M[3][2]= -eyez; M[3][3]= 1;


    glMultMatrixf(M);
    //glTranslatef (-eyex, -eyey, -eyez);
    }


    thanks a ton...


    Dan
    --
    Dan
    (average joe)

  2. #2
    Junior Member Newbie
    Join Date
    Oct 2001
    Posts
    5

    Re: glulookat replacement

    I don't know what is wrong in your code, but
    there are two glu implementations I'm aware of.
    MESA www.mesa3d.org and SGI OpenGL sample implementation (don't remember url, somewhere on the www.sgi.com)
    you can download them and check your code.
    here is SGI's code
    Code :
    [B]
    void GLAPI
    gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx,
         GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy,
         GLdouble upz)
    {
        int i;
        float forward[3], side[3], up[3];
        GLfloat m[4][4];
     
        forward[0] = centerx - eyex;
        forward[1] = centery - eyey;
        forward[2] = centerz - eyez;
     
        up[0] = upx;
        up[1] = upy;
        up[2] = upz;
     
        normalize(forward);
     
        /* Side = forward x up */
        cross(forward, up, side);
        normalize(side);
     
        /* Recompute up as: up = side x forward */
        cross(side, forward, up);
     
        __gluMakeIdentityf(&m[0][0]);
        m[0][0] = side[0];
        m[1][0] = side[1];
        m[2][0] = side[2];
     
        m[0][1] = up[0];
        m[1][1] = up[1];
        m[2][1] = up[2];
     
        m[0][2] = -forward[0];
        m[1][2] = -forward[1];
        m[2][2] = -forward[2];
     
        glMultMatrixf(&m[0][0]);
        glTranslated(-eyex, -eyey, -eyez);
    }
    [/B]


    And remember all matrix functions multiply generated matrix with the current(texture/projection/color/modelview...) matrix, don't forget to load identity matrix when needed, if you want place your viewing origin in the 3d scene use

    MatrixMode(MODELVIEW)
    LoadIdentity()
    LookAt()

Similar Threads

  1. glTranslated replacement?
    By kzanol in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 12-07-2015, 09:23 AM
  2. gl_NormalMatrix Replacement
    By ViolentHamster in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 09-29-2010, 07:02 PM
  3. EXT_paletted_texture replacement for FX
    By SergeVrt in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 07-27-2003, 09:57 PM
  4. replacement for GVS
    By Rarlund in forum OpenGL: General
    Replies: 2
    Last Post: 03-01-2001, 03:37 PM
  5. GVS replacement on Linux
    By Rarlund in forum OpenGL: Linux
    Replies: 0
    Last Post: 01-24-2001, 05:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean