如何从 Directx 11 的投影 XMMatrix 获取左右上下值?

问题描述 投票:0回答:1

我正在尝试使用 OPENXR 将 VR 耳机合并到我的 DIRECTX11 应用程序中。 我需要使用 DirectX::XMMatrixPerspectiveOffCenterLH 创建投影矩阵。 我有 openXR XrCompositionLayerProjectionView 视图。

在 OpenXR 示例中,他们使用

计算了视图和投影矩阵
const DirectX::XMMATRIX viewMatrix = DirectX::XMMatrixTranspose(DirectX::XMMatrixInverse(nullptr, poseToXmMatrix(view.pose)));
    //XMStoreFloat4x4(&m_constants.data.view, viewMatrix);
    Matrix4x4f projectionMatrix{};
    createProjectionFov(&projectionMatrix, view.fov, nearZ, farZ);
    const DirectX::XMMATRIX projection = DirectX::XMMatrixTranspose(LoadXrMatrix(projectionMatrix));

inline DirectX::XMMATRIX XM_CALLCONV ToXmMatrix(const XrPosef& pose, float scale)
{
    return XMMatrixAffineTransformation(DirectX::XMVectorReplicate(scale), DirectX::g_XMZero,
        XMLoadFloat4(reinterpret_cast<const DirectX::XMFLOAT4*>(&pose.orientation)), XMLoadFloat3(reinterpret_cast<const DirectX::XMFLOAT3*>(&pose.position)));
}

DirectX::XMMATRIX XM_CALLCONV poseToXmMatrix(const XrPosef& pose)
{
    return XMMatrixAffineTransformation(DirectX::g_XMOne, DirectX::g_XMZero, XMLoadFloat4(reinterpret_cast<const DirectX::XMFLOAT4*>(&pose.orientation)),
        XMLoadFloat3(reinterpret_cast<const DirectX::XMFLOAT3*>(&pose.position)));
}

我需要左上右下的值

void FI3PerspectiveOffCenterProjection::Calculate()
    {
        //float w = fabs(r-l);
        //float h = fabs(t-b);
        FI3MATRIX matProjection = FI3MatrixPerspectiveOCFOVLH(m_fNearClip * l, m_fNearClip * r, m_fNearClip * b, m_fNearClip * t, m_fNearClip, m_fFarClip);
        FI3Matrix4x4AFromMatrix(&m_matProjection, matProjection);
    }


    void FI3PerspectiveOffCenterProjection::setParams(float _l, float _t, float _r, float _b, float _fFarClip, float _fNearClip, bool _bAngular /*= false*/)
    {
        if (_bAngular)
        {
            l = tan(_l);
            t = tan(_t);
            r = tan(_r);
            b = tan(_b);
            //      float w = r - l;
            //      float h = b - t;
        }
        else
        {
            l = _l;
            r = _r;
            t = _t;
            b = _b;
        }
        Calculate();
    }
projection directx-11 openxr
1个回答
0
投票

对于矩阵的单个元素访问,请将其存储到

XMFLOAT4X4
XMFLOAT4X4A
并直接访问。这通常比对
XMVectorGet*
的各个行使用
XMMATRIX
方法更有效。

请参阅 Microsoft Learn

© www.soinside.com 2019 - 2024. All rights reserved.