面向方向向量的旋转矩阵
rotation matrix to facing direction vector
例如,我有一个字符的位置作为 xyz 坐标 x= 102,y= 0.75,z= -105.7。我有角色的旋转矩阵
M11 = -0.14
M12 = 0
M13 = -0.99
M21 = 0
M22 = 1
M23 = 0
M31 = 0.99
M32 =0
M33 = 0.14
我不太了解图形以及这些数据如何与角色的朝向相关联。我想找到一个向量,这样我就可以使用该向量来瞄准角色所面对的方向。我该怎么做?
你的角色面向的方向是旋转矩阵的第 3 行。那将是:
Vector3 facingDirection = new Vector3(0.99f, 0f, 0.14f);//(m31,m32,m33)
这个向量似乎是规范化的,但如果不是,你会这样做:
Vector3 facingDirection = Vector3.Normalize(new Vector3(0.99f, 0f, 0.14f));
如果矩阵是 XNA 矩阵,那么您只需使用矩阵结构的 Matrix.Forward
属性 即可获得相同的结果。
终于可以解决了。实际上它是非常简单的矢量数学。旋转矩阵已经为我提供了上面史蒂夫建议的方向向量,但我必须沿着那条线发射到某个特定点以使我的动画工作......所以我实际上需要沿着方向向量表示的线的一个点。所以,我只是沿着方向向量计算了一个距离角色当前位置大约 1000 个单位的点,然后朝这条线开火,它成功了!
Vector3 facingDirection = new Vector3(RotMatrix[2, 0], RotMatrix[2, 1], RotMatrix[2, 2]); // direction vector
Vector3 currentPos = new Vector3(character.PosX, character.PosY, character.PosZ); // I also have position of the character
// Now calculate a point 10000 units away along the vector line
var px = currentPos.X + facingDirection.X * 10000;
var py = currentPos.Y + facingDirection.Y * 10000;
var pz = currentPos.Z + facingDirection.Z * 10000;
return new Vector3(px, py, pz);
例如,我有一个字符的位置作为 xyz 坐标 x= 102,y= 0.75,z= -105.7。我有角色的旋转矩阵
M11 = -0.14
M12 = 0
M13 = -0.99
M21 = 0
M22 = 1
M23 = 0
M31 = 0.99
M32 =0
M33 = 0.14
我不太了解图形以及这些数据如何与角色的朝向相关联。我想找到一个向量,这样我就可以使用该向量来瞄准角色所面对的方向。我该怎么做?
你的角色面向的方向是旋转矩阵的第 3 行。那将是:
Vector3 facingDirection = new Vector3(0.99f, 0f, 0.14f);//(m31,m32,m33)
这个向量似乎是规范化的,但如果不是,你会这样做:
Vector3 facingDirection = Vector3.Normalize(new Vector3(0.99f, 0f, 0.14f));
如果矩阵是 XNA 矩阵,那么您只需使用矩阵结构的 Matrix.Forward
属性 即可获得相同的结果。
终于可以解决了。实际上它是非常简单的矢量数学。旋转矩阵已经为我提供了上面史蒂夫建议的方向向量,但我必须沿着那条线发射到某个特定点以使我的动画工作......所以我实际上需要沿着方向向量表示的线的一个点。所以,我只是沿着方向向量计算了一个距离角色当前位置大约 1000 个单位的点,然后朝这条线开火,它成功了!
Vector3 facingDirection = new Vector3(RotMatrix[2, 0], RotMatrix[2, 1], RotMatrix[2, 2]); // direction vector
Vector3 currentPos = new Vector3(character.PosX, character.PosY, character.PosZ); // I also have position of the character
// Now calculate a point 10000 units away along the vector line
var px = currentPos.X + facingDirection.X * 10000;
var py = currentPos.Y + facingDirection.Y * 10000;
var pz = currentPos.Z + facingDirection.Z * 10000;
return new Vector3(px, py, pz);