Changing a matrix from right-handed to left-handed coordinate system

前端 未结 7 1580
鱼传尺愫
鱼传尺愫 2020-11-28 06:52

I would like to change a 4x4 matrix from a right handed system where:
x is left and right, y is front and back and z is up and down

to a left-handed system where

7条回答
  •  臣服心动
    2020-11-28 07:31

    I think I understand your problem because I am currently facing a similar one.

    • You start with a world matrix which transforms a vector in a space where Z is up (e.g. a world matrix).

    • Now you have a space where Y is up and you want to know what to do with your old matrix.

    Try this:

    There is a given world matrix

    Matrix world = ...  //space where Z is up
    

    This Matrix changes the Y and Z components of a Vector

    Matrix mToggle_YZ = new Matrix(
    {1, 0, 0, 0}
    {0, 0, 1, 0}
    {0, 1, 0, 0}
    {0, 0, 0, 1})
    

    You are searching for this:

    //same world transformation in a space where Y is up
    Matrix world2 = mToggle_YZ * world * mToggle_YZ;
    

    The result is the same matrix cmann posted below. But I think this is more understandable as it combines the following calculation:

    1) Switch Y and Z

    2) Do the old transformation

    3) Switch back Z and Y

提交回复
热议问题