IHmdDevice::IAsyncCameraCallback

IHmdDevice::IAsyncCameraCallbackabstract

#include

Public Member Functions

virtual bool OnAsyncCameraCallback (const HmdTrackingState &state, AsyncCameraContext &context)=0

Detailed Description

Used to support asynchronous camera injection, called from the render thread to update the VR camera as late as possible to minimize HMD movement <-> rendered frame mismatch

#include 
#include 

// Minimal example for how to implement asynchronous camera injection for VR on the game side
class CMyAsyncCameraCallback final : public IHmdDevice::IAsyncCameraCallback
{
    CMyAsyncCameraCallback()
    {
        // If there is an HMD device available, set the async camera callback to this object
        if (IHmdDevice* pDevice = gEnv->pSystem->GetHmdManager()->GetHmdDevice())
        {
            pDevice->SetAsyncCameraCallback(this);
        }
    }

    virtual ~CMyAsyncCameraCallback()
    {
        // Clear the async camera callback on the HMD, assuming that we set it in our constructor
        if (IHmdDevice* pDevice = gEnv->pSystem->GetHmdManager()->GetHmdDevice())
        {
            pDevice->SetAsyncCameraCallback(nullptr);
        }
    }

    virtual bool OnAsyncCameraCallback(const HmdTrackingState& state, IHmdDevice::AsyncCameraContext& context) override
    {
        // For the sake of this example we choose not to scale our camera
        const Vec3 cameraScale = Vec3(1.f);
        // Keep the camera at the default rotation (identity matrix)
        const Quat cameraRotation = IDENTITY;
        // Position the camera at the world-space coordinates {50,50,50}
        const Vec3 cameraPosition = Vec3(50, 50, 50);

        // Create a matrix from the units specified above
        const Matrix34 cameraMatrix = Matrix34::Create(cameraScale, cameraRotation, cameraPosition);

        // Apply the latest HMD orientation to our desired camera matrix (thus allowing the user to turn their head around)
        context.outputCameraMatrix = cameraMatrix * Matrix34::Create(Vec3(1.f), state.pose.orientation, state.pose.position);

        // Indicate that we returned a valid output camera matrix
        return true;
    }
};

Member Function Documentation

◆ OnAsyncCameraCallback()

virtual bool IHmdDevice::IAsyncCameraCallback::OnAsyncCameraCallback ( const HmdTrackingState & state,
AsyncCameraContext & context
)
pure virtual

Called when a source (commonly the render thread) wants to receive the most up to date camera matrix

Returns
false if it is not possible to accurately retrieve new camera matrix, otherwise true.