Results 1 to 7 of 7

Thread: Matrices

  1. #1
    Guest

    Matrices

    Hi folks

    First question:

    I have a float[16] matrix named matrixA. Now I am searching for the matrix named matrixB. This:

    glLoadMatrixf(matrixB);
    glMultMatrixf(matrixA);

    should be the same as:

    glLoadIdentity();

    How do I get the second matrix (the one first loaded).

    Second question:

    Is there somewhere a tutorial how to translate and rotate without OpenGL with float[16] matrices which I can load later with glLoadMatrixf? Till know I used float[3][3]s (only rotation), but they are not supported by OpenGL and I want to put the translation into the matrix now too.

    Does somebody know a question

  2. #2
    Member Contributor
    Join Date
    Aug 2001
    Posts
    62

    Re: Matrices

    as far as the first question i have no clue.

    as for the second, this hopefully will explain the math and give the idea behind coding what you need.
    http://www.geocities.com/SiliconVall.../matrices.html

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Matrices

    glLoadMatrixf(matrixB);
    glMultMatrixf(matrixA);

    should be the same as:

    glLoadIdentity();
    That means B*A==I.
    Code :
    B*A == I - Remove A from left side by multiplying with A^-1, on both sides, to the right
    B*A*A^-1 == I*A^1
    B == A^-1
    So, there's your unknown matrix. matrixB is the inverse of matrixA.

    For your own rotation matrices, there's no difference with OpenGL's 4x4 matrices. It's well explained in no-one's link above. But in short, if you have your rotation matrix like this
    Code :
    [ a d g ]
    [ b e h ]
    [ c f i ]
    then just pad with some extra zeros and ones. This 4x4 matrix will do the same thing, and is perfectly valid in OpenGL.
    Code :
    [ a d g 0 ]
    [ b e h 0 ]
    [ c f i 0 ]
    [ 0 0 0 1 ]

  4. #4
    Guest

    Re: Matrices

    Thanks no-one and Bob, both questions are answered. But now a new question to no-one:
    http://www.geocities.com/SiliconVall.../matrices.html
    shows how to use float[4][4] matrices. Can I simply do this:

    glLoadMatrixf((float *)matrix);

    or are the x and y values then in the wrong order? Do I first have to do this:

    for(i = 0; i < 4; i++)
    for(j = 0; j < 4; j++)
    mat16[(i << 2) + j] = matrix[i][j];

    glLoadMatrixf(mat16);

    or this (other order)?:

    for(i = 0; i < 4; i++)
    for(j = 0; j < 4; j++)
    mat16[(j << 2) + i] = matrix[i][j];

    glLoadMatrixf(mat16);

    Thanks for your help,
    Thomas

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Matrices

    Even though you said the question was for no-one, I answer it anyway

    I don't know if you must transpose it matrix before you upload it to OpenGL, but it should be easy to find out. Upload a translation matrix, and see what happens. If you get some strange result (i.e. not a translation), the elements are obvisouly in the wrong order. Then you must transpose the matrix. You can either do that manually, as your described with your code, or you can let OpenGL do it for you.

    Use the extensions GL_ARB_transpose_matrix, or if you have OpenGL 1.2, you don't need the extensions since it's added into the core. glLoadTransposeMatrix/glMultTransposeMatrix will load/multiply a matrix whose element are tranposed.

  6. #6
    Member Contributor
    Join Date
    Aug 2001
    Posts
    62

    Re: Matrices

    thank you, Bob.

  7. #7
    Guest

    Re: Matrices

    Hmm okay, it will take a time until I can try that out... Thanks

    Thomas

Similar Threads

  1. GL matrices vs. D3D matrices
    By glfreak in forum OpenGL: General
    Replies: 9
    Last Post: 01-29-2011, 02:31 PM
  2. GL3 and matrices
    By V-man in forum OpenGL: Advanced Coding
    Replies: 99
    Last Post: 11-26-2007, 06:39 AM
  3. matrices...
    By VinceDeNice in forum OpenGL: General
    Replies: 2
    Last Post: 03-30-2005, 07:10 AM
  4. matrices
    By paneb in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-01-2003, 05:21 AM
  5. matrices
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-16-2002, 12:05 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