0

I am trying to incorporate VR headset into my DIRECTX11 application using OPENXR. I need to create projection matrix using DirectX::XMMatrixPerspectiveOffCenterLH. I have openXR XrCompositionLayerProjectionView view.

in the OpenXR sample, they have calculated view and projection matrix using

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)));
}

and i need left right top bottom values for this

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();
    }

1 Answers1

0

For individual element access for a matrix, store it to a XMFLOAT4X4 or XMFLOAT4X4A and access it directly. This is generally more efficient than using the XMVectorGet* methods for individual rows of the XMMATRIX.

See Microsoft Learn.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81