Beispiel #1
0
OVR_PUBLIC_FUNCTION(ovrResult) ovr_Create(ovrSession* pSession, ovrGraphicsLuid* pLuid)
{
	// Initialize the opaque pointer with our own OpenVR-specific struct
	ovrSession session = new struct ovrHmdStruct();
	memset(session->ColorTexture, 0, sizeof(ovrHmdStruct::ColorTexture));
	session->ThumbStick[ovrHand_Left] = true;

	// Get the compositor interface
	session->compositor = (vr::IVRCompositor*)VR_GetGenericInterface(vr::IVRCompositor_Version, &g_InitError);
	if (g_InitError != vr::VRInitError_None)
		return REV_InitErrorToOvrError(g_InitError);
	session->compositor->SetTrackingSpace(vr::TrackingUniverseSeated);

	// Get the settings interface
	session->settings = (vr::IVRSettings*)VR_GetGenericInterface(vr::IVRSettings_Version, &g_InitError);
	if (g_InitError != vr::VRInitError_None)
		return REV_InitErrorToOvrError(g_InitError);

	// Get the overlay interface
	session->overlay = (vr::IVROverlay*)VR_GetGenericInterface(vr::IVROverlay_Version, &g_InitError);
	if (g_InitError != vr::VRInitError_None)
		return REV_InitErrorToOvrError(g_InitError);

	// Apply settings
	session->ThumbStickRange = session->settings->GetFloat(REV_SETTINGS_SECTION, "ThumbStickRange", 0.8f);

	// Get the LUID for the adapter
	int32_t index;
	g_VRSystem->GetDXGIOutputInfo(&index);
	if (index == -1)
		index = 0;

	// Create the DXGI factory
	IDXGIFactory* pFactory;
	HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&pFactory));
	if (FAILED(hr))
		return ovrError_IncompatibleGPU;

	IDXGIAdapter* pAdapter;
	hr = pFactory->EnumAdapters(index, &pAdapter);
	if (FAILED(hr))
		return ovrError_MismatchedAdapters;

	DXGI_ADAPTER_DESC desc;
	hr = pAdapter->GetDesc(&desc);
	if (FAILED(hr))
		return ovrError_MismatchedAdapters;

	// Copy the LUID into the structure
	memcpy(pLuid, &desc.AdapterLuid, sizeof(LUID));

	// Cleanup and return
	pFactory->Release();
	pAdapter->Release();
	*pSession = session;
	return ovrSuccess;
}
Beispiel #2
0
int main(int argc, char *argv[]) {



    EVRInitError error;
    VR_InitInternal(&error, EVRApplicationType_VRApplication_Scene);
    printf("Init error: %s\n", VR_GetVRInitErrorAsEnglishDescription(error));


    char fnTableName[128];
    int result = sprintf(fnTableName, "FnTable:%s", IVRSystem_Version);

    EVRInitError initError;
    struct VR_IVRSystem_FnTable *fnTable;
    fnTable = (struct VR_IVRSystem_FnTable*)VR_GetGenericInterface(fnTableName, &initError);

    printf("%s\n", fnTable->GetEventTypeNameFromEnum(EVREventType_VREvent_TrackedDeviceActivated));
    printf("Init error: %s\n", VR_GetVRInitErrorAsEnglishDescription(initError));

    HmdMatrix44_t matrix = fnTable->GetProjectionMatrix(
        EVREye_Eye_Left, 0.1, 10000, EGraphicsAPIConvention_API_OpenGL);

    // HmdMatrix44_t matrix = VR_IVRSystem_GetProjectionMatrix(sys,
    //     Hmd_Eye_Eye_Left, 0.1, 10000, GraphicsAPIConvention_API_OpenGL);
    printf("%f\n", matrix.m[0][0]);


    return 0;
}