Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: translation using my own matrices

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2000
    Location
    New Orleans, La, USA
    Posts
    14

    translation using my own matrices

    I have an object located at the origin and I'm trying to translate it using my own matrix(instead of glTranslate). My matrix looks like this:
    float translate[16] = { 1.0, 0.0, 0.0, 5.0,
    0.0, 1.0, 0.0,-3.0,
    0.0, 0.0, 1.0, 0.0,
    0.0, 0.0, 0.0, 1.0 };
    Simple right? Well the problem is that I don't what to do to make it translate my object. I tried using glLoadMatrix and then glMultMatrix, but my object doesn't move. Am I doing something wrong?

    Thanks, Bino

    [This message has been edited by Bino (edited 09-12-2000).]

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: translation using my own matrices

    Almost correct.
    The order in which the matrices are stored in the array is colunm-wise. Yours is row-wise.

    See the image in the glLoadMatrix help here: http://msdn.microsoft.com/library/de...galgl_62pa.htm

    So
    GLfloat translate[16] =
    {
    1.0, 0.0, 0.0, 0.0,
    0.0, 1.0, 0.0, 0.0,
    0.0, 0.0, 1.0, 0.0,
    5.0, -3.0, 0.0, 1.0
    };

    should do the trick.
    Also look at the glMultMatrix command if you want to integrate your matrix in between some other tansformation calls.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2000
    Location
    New Orleans, La, USA
    Posts
    14

    Re: translation using my own matrices

    Forget that first question. I have a new one How do I rotate an object using matrices? I how to set up the matrix, but what do I do after that?(Since glMultMatrix doesn't work anymore) I heard you have to use loops or something like that, is that right?

    Thanks, Bino

    [This message has been edited by Bino (edited 09-12-2000).]

  4. #4
    Intern Contributor
    Join Date
    Apr 2000
    Posts
    78

    Re: translation using my own matrices

    The opengl call glRotate work this way:

    typedef float Matrixf[16];
    void CreateRotateMatrixf (Matrixf mat, float a, float x, float y, float z)
    {
    float InvSqrt = isqrt (x * x + y * y + z * z);
    float Ux = x * InvSqrt,
    Uy = y * InvSqrt,
    Uz = z * InvSqrt;

    float sinA = (float) sin (a * PI / 180.0f), cosA = (float) cos (a * PI / 180.0f);
    Matrixf SsinA, UUt, ImUUt;

    SsinA[4] = -Uz * sinA;
    SsinA[8] = Uy * sinA;
    SsinA[1] = Uz * sinA;
    SsinA[9] = -Ux * sinA;
    SsinA[2] = -Uy * sinA;
    SsinA[6] = Ux * sinA;

    UUt[0] = Ux * Ux;
    UUt[4] = Uy * Ux;
    UUt[8] = Uz * Ux;
    UUt[1] = UUt[4];
    UUt[5] = Uy * Uy;
    UUt[9] = Uz * Uy;
    UUt[2] = UUt[8];
    UUt[6] = UUt[9];
    UUt[10]= Uz * Uz;

    ImUUt[0] = (1 - UUt[0]) * cosA;
    ImUUt[4] = -UUt[4] * cosA;
    ImUUt[8] = -UUt[8] * cosA;
    ImUUt[1] = -UUt[1] * cosA;
    ImUUt[5] = (1 - UUt[5]) * cosA;
    ImUUt[9] = -UUt[9] * cosA;
    ImUUt[2] = -UUt[2] * cosA;
    ImUUt[6] = -UUt[6] * cosA;
    ImUUt[10]= (1 - UUt[10]) * cosA;

    mat[0] = UUt[0] + ImUUt[0];
    mat[4] = UUt[4] + ImUUt[4] + SsinA[4];
    mat[8] = UUt[8] + ImUUt[8] + SsinA[8];
    mat[12] = 0.0f;
    mat[1] = UUt[1] + ImUUt[1] + SsinA[1];
    mat[5] = UUt[5] + ImUUt[5];
    mat[9] = UUt[9] + ImUUt[9] + SsinA[9];
    mat[13] = 0.0f;
    mat[2] = UUt[2] + ImUUt[2] + SsinA[2];
    mat[6] = UUt[6] + ImUUt[6] + SsinA[6];
    mat[10] = UUt[10] + ImUUt[10];
    mat[14] = 0.0f;
    mat[3] = 0.0f;
    mat[7] = 0.0f;
    mat[11] = 0.0f;
    mat[15] = 1.0f;
    }

    Use that... it works...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •