C++ DirectX-从XMMATRIX获取俯仰偏航滚转

C++ DirectX-从XMMATRIX获取俯仰偏航滚转,c++,3d,directx-11,direct3d,C++,3d,Directx 11,Direct3d,我想做以下相反的事情: DirectX::XMMATRIX Rotation = DirectX::XMMatrixRotationRollPitchYaw( m_flt_Pitch, m_flt_Yaw, m_flt_Roll); 所以我有“旋转”,我想得到俯仰、偏航和横滚: m_flt_Pitch = GetPitchFromXMMATRIX(Rotation); m_flt_Yaw = GetYawFromXMMATRIX(Rotation); m_flt_Roll = GetRollF

我想做以下相反的事情:

DirectX::XMMATRIX Rotation = DirectX::XMMatrixRotationRollPitchYaw( m_flt_Pitch, m_flt_Yaw, m_flt_Roll);
所以我有“旋转”,我想得到俯仰、偏航和横滚:

m_flt_Pitch = GetPitchFromXMMATRIX(Rotation);
m_flt_Yaw = GetYawFromXMMATRIX(Rotation);
m_flt_Roll = GetRollFromXMMATRIX(Rotation);
这能做到吗


谢谢。

可能不是最有效的方法,但是:

void ExtractPitchYawRollFromXMMatrix(float* flt_p_PitchOut, float* flt_p_YawOut, float* flt_p_RollOut, const DirectX::XMMATRIX* XMMatrix_p_Rotation)
{
    DirectX::XMFLOAT4X4 XMFLOAT4X4_Values;
    DirectX::XMStoreFloat4x4(&XMFLOAT4X4_Values, DirectX::XMMatrixTranspose(*XMMatrix_p_Rotation));
    *flt_p_PitchOut = (float)asin(-XMFLOAT4X4_Values._23);
    *flt_p_YawOut = (float) atan2(XMFLOAT4X4_Values._13, XMFLOAT4X4_Values._33);
    *flt_p_RollOut = (float) atan2(XMFLOAT4X4_Values._21, XMFLOAT4X4_Values._22);
}
生成的角度可能与用于创建矩阵的原始角度不匹配。但它们一起创造了相同的矩阵


谢谢。

可能不是最有效的方法,但是:

void ExtractPitchYawRollFromXMMatrix(float* flt_p_PitchOut, float* flt_p_YawOut, float* flt_p_RollOut, const DirectX::XMMATRIX* XMMatrix_p_Rotation)
{
    DirectX::XMFLOAT4X4 XMFLOAT4X4_Values;
    DirectX::XMStoreFloat4x4(&XMFLOAT4X4_Values, DirectX::XMMatrixTranspose(*XMMatrix_p_Rotation));
    *flt_p_PitchOut = (float)asin(-XMFLOAT4X4_Values._23);
    *flt_p_YawOut = (float) atan2(XMFLOAT4X4_Values._13, XMFLOAT4X4_Values._33);
    *flt_p_RollOut = (float) atan2(XMFLOAT4X4_Values._21, XMFLOAT4X4_Values._22);
}
生成的角度可能与用于创建矩阵的原始角度不匹配。但它们一起创造了相同的矩阵

谢谢。


滚动(x轴旋转)俯仰(y轴旋转)和偏航(z轴旋转)值是旋转矩阵的欧拉角。计算欧拉角,你就会得到它们。关于这个主题的页面很多,甚至在维基上。但我无法让它与DirectX一起工作。知道怎么做吗?
XMMatrixDecompose
?尝试了XMatrixDecompose,但无法从四元数中获得任何有用的信息。滚动(x轴旋转)俯仰(y轴旋转)和偏航(z轴旋转)值是旋转矩阵的欧拉角。计算欧拉角,你就会得到它们。关于这个主题的页面很多,甚至在维基上。但我无法让它与DirectX一起工作。知道怎么做吗?
XMMatrixDecompose
?尝试了XMatrixDecompose,但无法从四元数中得到任何有用的东西。这对我很有帮助。谢谢,这对我很有帮助。非常感谢。