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: 4x4 Matrix multiplication doing odd things

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2014
    Posts
    5

    4x4 Matrix multiplication doing odd things

    Hello hopefully I posted this in the right sub-forum. I am trying to create a simple simulator and because I need to rotate and translate things along their local axises and when I looked around it looked like most people used matrices to do that sort of thing. Because glMultMatrix takes in 1-d arrays and I didn't really want to switch between types I stored all my matrices in float arrays. Where I am getting stuck is when I try to multiply a rotation matrix like

    Code :
    matrixFloat[0] = 1; matrixFloat[4] = 0;           matrixFloat[8] = 0;            matrixFloat[12] = 0;
    matrixFloat[1] = 0; matrixFloat[5] = cos(angleX); matrixFloat[9] = -sin(angleX); matrixFloat[13] = 0;
    matrixFloat[2] = 0; matrixFloat[6] = sin(angleX); matrixFloat[10] = cos(angleX); matrixFloat[14] = 0;
    matrixFloat[3] = 0; matrixFloat[7] = 0;           matrixFloat[11] = 0;           matrixFloat[15] = 1;

    by my main ship matrix it causes weird things to happen like the model gets skewed, becomes smaller, and moves away from the camera. The problem I think lies in the multiplication system I am using

    Code :
    matrixFloat[0] = a[0] * b[0] + a[4] * b[1] + a[8] * b[2] + a[12] * b[3];
    matrixFloat[1] = a[1] * b[0] + a[5] * b[1] + a[9] * b[2] + a[13] * b[3];
    matrixFloat[2] = a[2] * b[0] + a[6] * b[1] + a[10] * b[2] + a[14] * b[3];
    matrixFloat[3] = a[3] * b[0] + a[7] * b[1] + a[11] * b[2] + a[15] * b[3];
    matrixFloat[4] = a[0] * b[4] + a[4] * b[5] + a[8] * b[6] + a[12] * b[7];
    matrixFloat[5] = a[1] * b[4] + a[5] * b[5] + a[9] * b[6] + a[13] * b[7];
    matrixFloat[6] = a[2] * b[4] + a[6] * b[5] + a[10] * b[6] + a[14] * b[7];
    matrixFloat[7] = a[3] * b[4] + a[7] * b[5] + a[11] * b[6] + a[15] * b[7];
    matrixFloat[8] = a[0] * b[8] + a[4] * b[9] + a[8] * b[10] + a[12] * b[11];
    matrixFloat[9] = a[1] * b[8] + a[5] * b[9] + a[9] * b[10] + a[13] * b[11];
    matrixFloat[10] = a[2] * b[8] + a[6] * b[9] + a[10] * b[10] + a[14] * b[11];
    matrixFloat[11] = a[3] * b[8] + a[7] * b[9] + a[11] * b[10] + a[15] * b[11];
    matrixFloat[12] = a[0] * b[12] + a[4] * b[13] + a[8] * b[14] + a[12] * b[15];
    matrixFloat[13] = a[1] * b[12] + a[5] * b[13] + a[9] * b[14] + a[13] * b[15];
    matrixFloat[14] = a[2] * b[12] + a[6] * b[13] + a[10] * b[14] + a[14] * b[15];
    matrixFloat[15] = a[3] * b[12] + a[7] * b[13] + a[11] * b[14] + a[15] * b[15];

    maybe that only works on major-column matrices? Any help would be really appreciated.

    Thanks
    Mitchell

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Have a look the glm library.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2014
    Posts
    5
    OK I'll take a look into it thanks for your help.

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2014
    Posts
    5
    Ok I looked into the function mesa3d uses for glMultMatrix in order to fix the problem and now everything works fine
    Last edited by Mitchell M; 01-03-2014 at 04:53 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
  •