Rotation Matrix from direction vector (Forward, Up, Right)

I need to get rotation matrix from direction vector (vForward) I also have vRight and vUp vectors. All those vectors are unit vectors.

I just need to get rotation matrix.

To get rotation matrix for rotation in only one plane (xy) parallel to ground, I do this: XMMATRIX xmResult;

Vec3f vFwd = pPlayer->VForward;
vFwd.z = 0;
vFwd.Normalize();

xmResult = XMMatrixSet( vFwd.y,     -vFwd.x,    0,      0,
    vFwd.x,      vFwd.y,    0,      0,
    0,          0,          1,      0,
    0,          0,          0,      1);

Above code only get rotation matrix to rotate around Z axis:

I would like to get the code to rotate around all axis. This is coordinate system I'm forced to use. I know it is strange:

我正在使用的坐标系统

This is how I'm using my matrix later in code:

XMStoreFloat3((XMFLOAT3*)&vStart, XMVector3Transform(XMLoadFloat3((XMFLOAT3*)&vStart), xmTransformation));
XMStoreFloat3((XMFLOAT3*)&vEnd, XMVector3Transform(XMLoadFloat3((XMFLOAT3*)&vEnd), xmTransformation));

根据你使用矩阵的方式,Right,Up和Forward应该对应矩阵的行或列。

xmResult = XMMatrixSet( vRight.x, vRight.y, vRight.z, 0, vFwd.x, vFwd.y, vFwd.z, 0, vUp.x, vUp.y, vUp.z, 0, 0, 0, 0, 1);
链接地址: http://www.djcxy.com/p/81808.html

上一篇: 如何找到魔方的方向?

下一篇: 方向矢量的旋转矩阵(向前,向上,向右)