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 6 of 6

Thread: Matrix Math

  1. #1
    Intern Newbie
    Join Date
    May 2000
    Posts
    40

    Matrix Math

    I know this is a basic quaestion, but does anyone know how to convert a right-handed matrix into a left-handed matrix. Thanks in advance.

    Tone

  2. #2
    Junior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Sweden
    Posts
    130

    Re: Matrix Math

    I am no matrix expert, but I think you only have to change the sign of one of the axes:
    right,up and forward.

    This is simply done by setting one of the top three 1's in the identity matrix to -1.

    Code :
    // Righthanded system
    1,0,0,0,
    0,1,0,0,
    0,0,1,0,
    0,0,0,1
     
    // Lefthanded system using left vector instead of right vector
    -1,0,0,0,
     0,1,0,0,
     0,0,1,0,
     0,0,0,1
     
     
    // I dont know if this is general but:
     
    // In a column major matrix (GL matrix):
     rx, ux, ax, px,
     ry, uy, ay, py,
     rz, uz, az, pz,
     sx, sy, sz, D
     
     
    Then 
     
    (rx,ry,rz) is the rightvector
    (ux,uy,uz) is the upvector
    (ax,ay,az) is the 'at' vector (forward)
     
    and
     
    (px,py,pz) is the position (translation)
     
     
    I don't know for sure, but I think that:
    (sx,sy,sz) is the shear of the matrix
     
    I have no clue of what D is, it is usually set to 1.
    // For rotations, I do believe you also have to change sign of all the sin components.
    (Maybe multiplying a righthand rotationmatrix with a lefthand identity matrix will do this for you, anyone?)

    Tell me if I am wrong.

    [This message has been edited by Hull (edited 05-15-2001).]

    [This message has been edited by Hull (edited 05-15-2001).]

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: Matrix Math

    Either swap the Y and Z lines, or negate one of them (typically the Z).
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  4. #4
    Intern Newbie
    Join Date
    May 2000
    Posts
    40

    Re: Matrix Math

    So for example, I created a matrix emulating what gluLookAt does. It goes as follows:

    rightX upX fwdX posX
    rightY upY fwdY posY
    rightZ upZ fwdZ posZ
    0 0 0 1

    Are you saying that the left-handed version would look like this?

    rightX fwdX upX posX
    rightY fwdY upY posY
    rightZ fwdZ upZ posZ
    0 0 0 1

    [This message has been edited by Tone (edited 05-15-2001).]

  5. #5
    Junior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Sweden
    Posts
    130

    Re: Matrix Math

    A left-isometry is like a mirroring of the entire 3D space, because one axis of the three axes in 3D space will point in the opposite direction. This is a consequence of changing the way all matrix transformations are made. But that is not all.

    In a left-isometric environment, ALL transformations, such as rotations and shearing, are done in opposite direction (I think) because of the mirroring effect.

    I don't really know if changing the identity matrix (the one you always start with before doing any transformations on it) by either negating one axis or swapping two of the axes will suffice, or if you have to alter the transformations themselves to suit the new isometry (such as rotations rotating the other way around).

    Try it out!
    -----------
    Code :
    Note that if you change 
    the axes like this:
     
    // Swapped at with up.
    rx, atx, upx, 0,
    rx, atx, upx, 0,
    rx, atx, upx, 0,
     0,   0,   0, 1,
     
     
    It would be a left-isometry, 
    if the previous isometry was 
    a right one, but the matrix 
    would still have its right, 
    forward, up and whatever at 
    the locations I previously stated.
    [This message has been edited by Hull (edited 05-15-2001).]

  6. #6
    Junior Member Regular Contributor
    Join Date
    May 2001
    Location
    Germany, Hannover
    Posts
    224

    Re: Matrix Math

    glScaled(-1.0, 1.0, 1.0); ?!?

Posting Permissions

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