Beispiel #1
0
bool OcudumpBase::ovrInitializeVersioned()
{
#if defined(OVRSDK5)
    return ovr_Initialize(NULL) ? true : false;
#elif defined(OVRSDK6)
    return (ovr_Initialize(NULL)==ovrSuccess);
#endif
}
void OVRSDK06AppSkeleton::initHMD()
{
    ovrInitParams initParams = { 0 };
    if (ovrSuccess != ovr_Initialize(NULL))
    {
        LOG_INFO("Failed to initialize the Oculus SDK");
    }

    if (ovrSuccess != ovrHmd_Create(0, &m_Hmd))
    {
        LOG_INFO("Could not create HMD");
        if (ovrSuccess != ovrHmd_CreateDebug(ovrHmd_DK2, &m_Hmd))
        {
            LOG_ERROR("Could not create Debug HMD");
        }
        m_usingDebugHmd = true;
    }

    const ovrBool ret = ovrHmd_ConfigureTracking(m_Hmd,
        ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position,
        ovrTrackingCap_Orientation);
    if (!OVR_SUCCESS(ret))
    {
        LOG_ERROR("Error calling ovrHmd_ConfigureTracking");
    }
}
//======================================================================================
//  Oculus Rift使用の初期化
//======================================================================================
int InitOculusRift()
{
	// LibOVRの初期化 
	ovr_Initialize();

	// 接続されている HMD を取得
	HMD = ovrHmd_Create(0);
	if (!HMD)
	{
		// 存在しなかった
		MessageBoxA(NULL, "Oculus Riftがみつかりませんでした。", "", MB_OK);
		return(1);
	}

	// HMDの詳細情報を取得
	ovrHmd_GetDesc(HMD, &HMDDesc);
	if (HMDDesc.DisplayDeviceName[0] == '\0')
	{
		// HMDは存在したが該当するディスプレイがなかった。
		MessageBoxA(NULL, "Oculus Riftはみつかりましたが出力先ディスプレイがみつかりませんでした。", "", MB_OK);
	}


	return 0;
}
Beispiel #4
0
/**
 * ERRORCODE 0 => OK
 * ERRORCODE 1 => No HMD found
 * ERRORCODE 2 => Sensor Start failed
 */
int init_ovr(){

	// Init the OVR library
	ovr_Initialize();

	// Create the software device and connect the physical device
	hmd = ovrHmd_Create(0);
	//if (!hmd) hmd = ovrHmd_CreateDebug(ovrHmd_DK1);
	if (!hmd)
		return 1;

	// Starts the sensor input with check required Capabilities
	 if ( !ovrHmd_ConfigureTracking(hmd, hmd->TrackingCaps, hmd->TrackingCaps) )
		 return 2;

	 if ( mode == MODE_DEBUG ){
		 recommendedTex0Size = OVR::Sizei ( 1280, 720 );
		 recommendedTex1Size = OVR::Sizei ( 1280, 720 );
		 renderTargetSize.w = 1280;
		 renderTargetSize.h = 720;
	 }else{
		//Configuring the Texture size (bigger than screen for barreldistortion)
		recommendedTex0Size = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left, hmd->DefaultEyeFov[0], 1.0f);
		recommendedTex1Size = ovrHmd_GetFovTextureSize(hmd, ovrEye_Right, hmd->DefaultEyeFov[1], 1.0f);

		renderTargetSize.w = recommendedTex0Size.w + recommendedTex1Size.w;
		renderTargetSize.h = std::max( recommendedTex0Size.h, recommendedTex1Size.h );
	 }
	
	 return 0;
}
bool OculusVR::InitVR()
{
    ovrResult result = ovr_Initialize(nullptr);
    ovrGraphicsLuid luid; // as of SDK 0.7.0.0 luid is not supported with OpenGL

    if (result != ovrSuccess)
    {
        LOG_MESSAGE_ASSERT(false, "Failed to initialize LibOVR");
        return false;
    }

    result = ovr_Create(&m_hmdSession, &luid);

    if (result != ovrSuccess)
    {
        LOG_MESSAGE_ASSERT(result == ovrSuccess, "Failed to create OVR device");
    }

    m_hmdDesc = ovr_GetHmdDesc(m_hmdSession);

    // debug camera tracking frustum
    m_cameraFrustum    = new OVRCameraFrustum;
    // debug Vive-style camera tracking chaperone
    m_trackerChaperone = new OVRTrackerChaperone;

    return result == ovrSuccess;
}
///@brief Can be called before GL context is initialized.
void initHMD()
{
    const ovrResult res = ovr_Initialize(nullptr);
    if (ovrSuccess != res)
    {
        LOG_ERROR("ovr_Initialize failed with code %d", res);
    }

    ovrGraphicsLuid luid;
    if (ovrSuccess != ovr_Create(&g_session, &luid))
    {
        LOG_ERROR("ovr_Create failed with code %d", res);
        // return 1;
    }

    ovrSessionStatus sessionStatus;
    ovr_GetSessionStatus(g_session, &sessionStatus);
    if (sessionStatus.HmdPresent == false)
    {
        LOG_ERROR("No HMD Present.");
        return;
    }

    m_Hmd = ovr_GetHmdDesc(g_session);
}
bool OculusBaseDisplayPlugin::isSupported() const {
    if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
        return false;
    }

    ovrSession session { nullptr };
    ovrGraphicsLuid luid;
    auto result = ovr_Create(&session, &luid);
    if (!OVR_SUCCESS(result)) {
        ovrErrorInfo error;
        ovr_GetLastErrorInfo(&error);
        ovr_Shutdown();
        return false;
    }

    auto hmdDesc = ovr_GetHmdDesc(session);
    if (hmdDesc.Type == ovrHmd_None) {
        ovr_Destroy(session);
        ovr_Shutdown();
        return false;
    }

    ovr_Shutdown();
    return true;
}
Beispiel #8
0
int main1(HINSTANCE hinst) {

	OVR::System::Init();


	// Initialize GDI+.
	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR           gdiplusToken;
	Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	//Initialize Oculus
	ovrResult result = ovr_Initialize(nullptr);
	if (!OVR_SUCCESS(result)) {
		throw "Failed to init";
	}


	// THIS IS THE BIT WHERE YOU CHOOSE THE MODE.
	// PICK ONE OF THESE!

	// Or figure out how to open a little window to let the user choose

	avr_main * main_manager = new avr_main(hinst);
	main_manager->main(MULTIWAVELENGTH_LONG_TOUR);
//	main_manager->main(MULTIWAVELENGTH_FREE);
//	main_manager->main(PLANCK_MODE);

	ovr_Shutdown();
	OVR::System::Destroy();

	return(0);
}
int OVRInitialize(int debug)
{
	unsigned int supportedTrackingCaps =
		ovrTrackingCap_Orientation|
		ovrTrackingCap_MagYawCorrection|
		ovrTrackingCap_Position;
	ovrHmdType debugHMDType = ovrHmd_None;

	if ( debug != 0 ) {
		debugHMDType = (debug == 1 ? ovrHmd_DK1 : debug == 2 ? ovrHmd_DK2 : ovrHmd_Other);
	}

	if ( ! ovr_Initialize() ) {
		return 0;
	}

	_OVRGlobals.HMD = ovrHmd_Create(0);

	// no HMD? check for vr_debug and attempt to create a debug HMD
	if ( ! _OVRGlobals.HMD && (
		 ! ( debugHMDType != ovrHmd_None ) ||
		 ! ( _OVRGlobals.HMD = ovrHmd_CreateDebug( debugHMDType ) ) ) ) {
		return 0;
	}

	if ( ! ovrHmd_ConfigureTracking( _OVRGlobals.HMD, supportedTrackingCaps, ovrTrackingCap_Orientation ) ) {
		return 0;
	}

	return 1;
}
Beispiel #10
0
int main(int argc, char *argv[])
{
    SoDB::init();

    QApplication app(argc, argv);
    qAddPostRoutine(cleanup);

    // Moved here because of https://developer.oculusvr.com/forums/viewtopic.php?f=17&t=7915&p=108503#p108503
    // Init libovr.
    if (!ovr_Initialize()) {
        qDebug() << "Could not initialize Oculus SDK.";
        exit(1);
    }

    CoinRiftWidget window;
    window.show();

    // An example scene.
    static const char * inlineSceneGraph[] = {
        "#Inventor V2.1 ascii\n",
        "\n",
        "Separator {\n",
        "  Rotation { rotation 1 0 0  0.3 }\n",
        "  Cone { }\n",
        "  BaseColor { rgb 1 0 0 }\n",
        "  Scale { scaleFactor .7 .7 .7 }\n",
        "  Cube { }\n",
        "\n",
        "  DrawStyle { style LINES }\n",
        "  ShapeHints { vertexOrdering COUNTERCLOCKWISE }\n",
        "  Coordinate3 {\n",
        "    point [\n",
        "       -2 -2 1.1,  -2 -1 1.1,  -2  1 1.1,  -2  2 1.1,\n",
        "       -1 -2 1.1,  -1 -1 1.1,  -1  1 1.1,  -1  2 1.1\n",
        "        1 -2 1.1,   1 -1 1.1,   1  1 1.1,   1  2 1.1\n",
        "        2 -2 1.1,   2 -1 1.1,   2  1 1.1,   2  2 1.1\n",
        "      ]\n",
        "  }\n",
        "\n",
        "  Complexity { value 0.7 }\n",
        "  NurbsSurface {\n",
        "     numUControlPoints 4\n",
        "     numVControlPoints 4\n",
        "     uKnotVector [ 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 ]\n",
        "     vKnotVector [ 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 ]\n",
        "  }\n",
        "}\n",
        NULL
    };

    SoInput in;
    in.setStringArray(inlineSceneGraph);

    window.setSceneGraph(SoDB::readAll(&in));

    return app.exec();
}
Beispiel #11
0
void RiftSetup()
{
    ovr_Initialize();

    s_hmd = ovrHmd_Create(0);
    if (!s_hmd)
    {
        s_hmd = ovrHmd_CreateDebug(ovrHmd_DK1);
    }

    ovrHmd_GetDesc(s_hmd, &s_hmdDesc);
    DumpHMDInfo(s_hmdDesc);

    uint32_t supportedSensorCaps = ovrSensorCap_Orientation;
    uint32_t requiredSensorCaps = ovrSensorCap_Orientation;
    ovrBool success = ovrHmd_StartSensor(s_hmd, supportedSensorCaps, requiredSensorCaps);
    if (!success) {
        fprintf(stderr, "ERROR: HMD does not have required capabilities!\n");
        exit(2);
    }

    // Figure out dimensions of render target
    ovrSizei recommenedTex0Size = ovrHmd_GetFovTextureSize(s_hmd, ovrEye_Left, s_hmdDesc.DefaultEyeFov[0], 1.0f);
    ovrSizei recommenedTex1Size = ovrHmd_GetFovTextureSize(s_hmd, ovrEye_Right, s_hmdDesc.DefaultEyeFov[1], 1.0f);
    s_renderTargetSize.w = recommenedTex0Size.w + recommenedTex1Size.w;
    s_renderTargetSize.h = std::max(recommenedTex0Size.h, recommenedTex1Size.h);

    CreateRenderTarget(s_renderTargetSize.w, s_renderTargetSize.h);

    s_eyeTexture[0].Header.API = ovrRenderAPI_OpenGL;
    s_eyeTexture[0].Header.TextureSize = s_renderTargetSize;
    s_eyeTexture[0].Header.RenderViewport.Pos = {0, 0};
    s_eyeTexture[0].Header.RenderViewport.Size = {s_renderTargetSize.w / 2, s_renderTargetSize.h};
    ((ovrGLTexture*)(&s_eyeTexture[0]))->OGL.TexId = s_fboTex;

    s_eyeTexture[1].Header.API = ovrRenderAPI_OpenGL;
    s_eyeTexture[1].Header.TextureSize = s_renderTargetSize;
    s_eyeTexture[1].Header.RenderViewport.Pos = {s_renderTargetSize.w / 2, 0};
    s_eyeTexture[1].Header.RenderViewport.Size = {s_renderTargetSize.w / 2, s_renderTargetSize.h};
    ((ovrGLTexture*)(&s_eyeTexture[1]))->OGL.TexId = s_fboTex;

    // Configure ovr SDK Rendering
    ovrGLConfig cfg;
    memset(&cfg, 0, sizeof(ovrGLConfig));
    cfg.OGL.Header.API = ovrRenderAPI_OpenGL;
    cfg.OGL.Header.RTSize = {s_config->width, s_config->height};
    cfg.OGL.Header.Multisample = 0;
    // TODO: on windows need to set HWND, on Linux need to set other parameters
    if (!ovrHmd_ConfigureRendering(s_hmd, &cfg.Config, s_hmdDesc.DistortionCaps, s_hmdDesc.DefaultEyeFov, s_eyeRenderDesc))
    {
        fprintf(stderr, "ERROR: HMD configure rendering failed!\n");
        exit(3);
    }
}
Beispiel #12
0
	bool VRImplOVR::init()
	{
		ovrResult initialized = ovr_Initialize(NULL);
		if (!OVR_SUCCESS(initialized))
		{
			BX_TRACE("Unable to initialize OVR runtime.");
			return false;
		}

		return true;
	}
Beispiel #13
0
void Oculus::Initialize() {
	ovr_Initialize();

	head_mounted_display = ovrHmd_Create(0);

	bool tracking_setup = 
		ovrHmd_ConfigureTracking(head_mounted_display, 
		                         ovrTrackingCap_Orientation |
								 ovrTrackingCap_MagYawCorrection |
								 ovrTrackingCap_Position, 0);
	
	ConfigureEyeViewportInformation();
}
Beispiel #14
0
  HelloRift() {
    ovr_Initialize();
    hmd = ovrHmd_Create(0);
    if (nullptr == hmd) {
      debugDevice = true;
      hmd = ovrHmd_CreateDebug(ovrHmd_DK2);
    }

    ovrHmd_ConfigureTracking(hmd,
      ovrTrackingCap_Orientation |
      ovrTrackingCap_Position, 0);
    resetPosition();
  }
Beispiel #15
0
//-------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE, LPSTR, int)
{
    // Initializes LibOVR, and the Rift
    ovrResult result = ovr_Initialize(nullptr);
    VALIDATE(OVR_SUCCESS(result), "Failed to initialize libOVR.");

    VALIDATE(DIRECTX.InitWindow(hinst, L"Oculus Room Tiny (DX12)"), "Failed to open window.");

    DIRECTX.Run(MainLoop);

    ovr_Shutdown();
    return(0);
}
Beispiel #16
0
void VR::init()
{
#if defined(_OVR_)
	ovrInitParams initParams = { ovrInit_RequestVersion, OVR_MINOR_VERSION, NULL, 0, 0 };
	ovrResult result = ovr_Initialize(&initParams);
	if (OVR_FAILURE(result)) {
		ovrErrorInfo errorInfo;
		ovr_GetLastErrorInfo(&errorInfo);
		Log(L"ovr_Initialize failed: " << errorInfo.ErrorString << endl);
		Error(L"ovr_Initialize failed");
		return;
	}
	Log("LibOVR initialized ok!" << endl);
	result = ovr_Create(&session, &luid);
	if (OVR_FAILURE(result))
	{
		ovr_Shutdown();
		Error(L"No Oculus Rift detected. Cannot run in OVR mode without Oculus Rift device.");
		return;
	}

	desc = ovr_GetHmdDesc(session);
	resolution = desc.Resolution;
	// Start the sensor which provides the Rift’s pose and motion.
/*	result = ovr_ConfigureTracking(session, ovrTrackingCap_Orientation |
		ovrTrackingCap_MagYawCorrection |
		ovrTrackingCap_Position, 0);
	if (OVR_FAILURE(result)) Error(L"Could not enable Oculus Rift Tracking. Cannot run in OVR mode without Oculus Rift tracking.");
	*/
	// Setup VR components, filling out description
	eyeRenderDesc[0] = ovr_GetRenderDesc(session, ovrEye_Left, desc.DefaultEyeFov[0]);
	eyeRenderDesc[1] = ovr_GetRenderDesc(session, ovrEye_Right, desc.DefaultEyeFov[1]);

	nextTracking();

	// tracking setup complete, now init rendering:

	// Configure Stereo settings.
	Sizei recommenedTex0Size = ovr_GetFovTextureSize(session, ovrEye_Left, desc.DefaultEyeFov[0], 1.0f);
	Sizei recommenedTex1Size = ovr_GetFovTextureSize(session, ovrEye_Right, desc.DefaultEyeFov[1], 1.0f);
	buffersize_width = recommenedTex0Size.w + recommenedTex1Size.w;
	buffersize_height = max(recommenedTex0Size.h, recommenedTex1Size.h);
	result = ovr_RequestBoundaryVisible(session, ovrTrue);
	if (OVR_FAILURE(result)) {
		Log(L"Oculus Boundary system inactive.");
	}
	else {
		Log(L"Oculus Boundary system activated!!");
	}
#endif
}
Beispiel #17
0
FOculusInput::FOculusInput( const TSharedRef< FGenericApplicationMessageHandler >& InMessageHandler )
	: MessageHandler( InMessageHandler )
	, ControllerPairs()
	, TriggerThreshold(0.8f)
{
	// Initializes LibOVR. 
	ovrInitParams initParams;
	FMemory::Memset(initParams, 0);
	initParams.Flags = ovrInit_RequestVersion;
	initParams.RequestedMinorVersion = OVR_MINOR_VERSION;
#if !UE_BUILD_SHIPPING
//	initParams.LogCallback = OvrLogCallback;
#endif

	ovrResult initStatus = ovr_Initialize(&initParams);
	if (!OVR_SUCCESS(initStatus) && initStatus == ovrError_LibLoad)
	{
		// fatal errors: can't load library
 		UE_LOG(LogOcInput, Log, TEXT("Can't find Oculus library %s: is proper Runtime installed? Version: %s"),
 			TEXT(OVR_FILE_DESCRIPTION_STRING), TEXT(OVR_VERSION_STRING));
		return;
	}

	FOculusTouchControllerPair& ControllerPair = *new(ControllerPairs) FOculusTouchControllerPair();

	// @todo: Unreal controller index should be assigned to us by the engine to ensure we don't contest with other devices
	ControllerPair.UnrealControllerIndex = 0; //???? NextUnrealControllerIndex++;

	// Load the config, even if we failed to initialize a controller
	LoadConfig();

	IModularFeatures::Get().RegisterModularFeature( GetModularFeatureName(), this );
	GEngine->MotionControllerDevices.AddUnique(this);

	// Register the FKeys
	EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Left_Thumbstick, LOCTEXT("OculusTouch_Left_Thumbstick", "Oculus Touch (L) Thumbstick CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
	EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Left_FaceButton1, LOCTEXT("OculusTouch_Left_FaceButton1", "Oculus Touch (L) X Button CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
	EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Left_Trigger, LOCTEXT("OculusTouch_Left_Trigger", "Oculus Touch (L) Trigger CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
	EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Left_FaceButton2, LOCTEXT("OculusTouch_Left_FaceButton2", "Oculus Touch (L) Y Button CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
	EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Left_IndexPointing, LOCTEXT("OculusTouch_Left_IndexPointing", "Oculus Touch (L) Pointing CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
	EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Left_ThumbUp, LOCTEXT("OculusTouch_Left_ThumbUp", "Oculus Touch (L) Thumb Up CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));

	EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Right_Thumbstick, LOCTEXT("OculusTouch_Right_Thumbstick", "Oculus Touch (R) Thumbstick CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
	EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Right_FaceButton1, LOCTEXT("OculusTouch_Right_FaceButton1", "Oculus Touch (R) A Button CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
	EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Right_Trigger, LOCTEXT("OculusTouch_Right_Trigger", "Oculus Touch (R) Trigger CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
	EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Right_FaceButton2, LOCTEXT("OculusTouch_Right_FaceButton2", "Oculus Touch (R) B Button CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
	EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Right_IndexPointing, LOCTEXT("OculusTouch_Right_IndexPointing", "Oculus Touch (R) Pointing CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
	EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Right_ThumbUp, LOCTEXT("OculusTouch_Right_ThumbUp", "Oculus Touch (R) Thumb Up CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));

	UE_LOG(LogOcInput, Log, TEXT("OculusInput is initialized. Init status %d. Runtime version: %s"), int(initStatus), *FString(ANSI_TO_TCHAR(ovr_GetVersionString())));
}
Beispiel #18
0
OvrSdkRenderer::OvrSdkRenderer()
{
	ovr_Initialize();
	hmd = ovrHmd_Create(0);
	if (hmd) {
		ovrHmd_ConfigureTracking(hmd,
			ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, // supported
			ovrTrackingCap_Orientation); // required

		// Set low persistence mode
		int hmdCaps = ovrHmd_GetEnabledCaps(hmd);
		ovrHmd_SetEnabledCaps(hmd, hmdCaps | ovrHmdCap_LowPersistence);
	}
}
  void initGl() {
    GlfwApp::initGl();
    glClearColor(0.1f, 0.1f, 0.1f, 1.0f);

    ovr_Initialize();
    hmd = ovrHmd_Create(0);
    if (!hmd) {
      FAIL("Unable to open HMD");
    }

    if (!ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation, 0)) {
      FAIL("Unable to locate Rift sensor device");
    }

  }
Beispiel #20
0
	bool VRImplOVR::init()
	{
		if (NULL != g_platformData.session)
		{
			return true;
		}

		ovrResult initialized = ovr_Initialize(NULL);
		if (!OVR_SUCCESS(initialized))
		{
			BX_TRACE("Unable to initialize OVR runtime.");
			return false;
		}

		return true;
	}
Beispiel #21
0
void GuardianSystemDemo::Start(HINSTANCE hinst)
{
    ovrResult result;
    result = ovr_Initialize(nullptr);
    if (!OVR_SUCCESS(result)) {
        printf("ovr_Initialize failed"); exit(-1);
    }

    ovrGraphicsLuid luid;
    result = ovr_Create(&mSession, &luid);
    if (!OVR_SUCCESS(result)) {
        printf("ovr_Create failed"); exit(-1);
    }

    if (!DIRECTX.InitWindow(hinst, L"GuardianSystemDemo")) {
        printf("DIRECTX.InitWindow failed"); exit(-1);
    }

    // Use HMD desc to initialize device
    ovrHmdDesc hmdDesc = ovr_GetHmdDesc(mSession);
    if (!DIRECTX.InitDevice(hmdDesc.Resolution.w / 2, hmdDesc.Resolution.h / 2, reinterpret_cast<LUID*>(&luid))) {
        printf("DIRECTX.InitDevice failed"); exit(-1);
    }

    // Use FloorLevel tracking origin
    ovr_SetTrackingOriginType(mSession, ovrTrackingOrigin_FloorLevel);
    
    InitRenderTargets(hmdDesc);
    InitSceneGraph();
    mLastUpdateClock = std::chrono::high_resolution_clock::now();

    // Main Loop
    while (DIRECTX.HandleMessages() && !mShouldQuit)
    {
        ovrSessionStatus sessionStatus;
        ovr_GetSessionStatus(mSession, &sessionStatus);
        if (sessionStatus.ShouldQuit)
            break;

        float elapsedTimeSec = UpdateTimeWithBoundaryTest();
        UpdateBoundaryLookAndFeel();
        UpdateObjectsCollisionWithBoundary(elapsedTimeSec);
        Render();
    }

    ovr_Shutdown();
}
Beispiel #22
0
/// Start-up logic.
void Initialize()
{
	// Do nothing if already initialized.
	if (g_session != nullptr)
		return;

	// Fail now and retry later if initialization fails.
	if (!OVR_SUCCESS(ovr_Initialize(nullptr)))
		return;

	// Dummy because you can't pass nullptr.
	ovrGraphicsLuid luid;
	memset(&luid, 0, sizeof(ovrGraphicsLuid));

	// Set up the session we will need to query input each frame.
	if (!OVR_SUCCESS(ovr_Create(&g_session, &luid)))
		Shutdown();
}
Beispiel #23
0
GMO double initialize() {
	ovr_Initialize();
	HMD = ovrHmd_Create(0);
	if (!HMD) {
		#if DEBUG
			MessageBoxA(NULL, "No oculus device found", "No oculus device found", MB_ICONWARNING);
		#endif
		return 0; //No device found
	}
	if (HMD->ProductName[0] == '\0') {
		#if DEBUG
			MessageBoxA(NULL, "Rift detected, display disabled", "Rift detected, display disabled", MB_ICONWARNING);
		#endif
		return 2; //Rift deetected, display disabled
	}

	return 1;
}
Beispiel #24
0
///@brief Set this up early so we can get the HMD's display dimensions to create a window.
void RiftAppSkeleton::initHMD()
{
    ovr_Initialize();

    m_Hmd = ovrHmd_Create(0);
    if (m_Hmd == NULL)
    {
        m_Hmd = ovrHmd_CreateDebug(ovrHmd_DK1);
    }

    m_ovrScene.SetHmdPointer(m_Hmd);
    m_ovrScene.SetChassisPosPointer(&m_chassisPos);
    m_ovrScene.SetChassisYawPointer(&m_chassisYaw);

    // Both ovrVector3f and glm::vec3 are at heart a float[3], so this works fine.
    m_fm.SetChassisPosPointer(reinterpret_cast<glm::vec3*>(&m_chassisPos));
    m_fm.SetChassisYawPointer(&m_chassisYaw);
}
Beispiel #25
0
int main(int argc, char *argv[])
{
  time_offset = kpSysTimeNs();
  kp__X11Init();
#ifdef KP_OVR
  ovr_Initialize();

  ovrHmd hmd = ovrHmd_Create(0);
  if (hmd) {
    KP__L("name: %s, manf: %s", hmd->ProductName, hmd->Manufacturer);
    KP__L("%d,%d %dx%d", hmd->WindowsPos.x, hmd->WindowsPos.y, hmd->Resolution.w, hmd->Resolution.h);
  }
#endif
  kpuserAppCreate(argc, (const char**)argv);
  kp__X11Run();
  kpuserAppDestroy();
  return 0;
}
FOculusInput::FOculusInput( const TSharedRef< FGenericApplicationMessageHandler >& InMessageHandler )
	: MessageHandler( InMessageHandler )
	, ControllerPairs()
{
	PreInit(); // @TODO: call it sooner to avoid 'Warning InputKey Event specifies invalid' when loading a map using the custom keys

	// take care of backward compatibility of Remote with Gamepad 
	if (bRemoteKeysMappedToGamepad)
	{
		Remote.ReinitButtonsForGamepadCompat();
	}

	// Only initialize plug-in when not running a dedicated server, and Oculus service is running
	if(!IsRunningDedicatedServer() && ovr_Detect(0).IsOculusServiceRunning)
	{
		// Initializes LibOVR. 
		ovrInitParams initParams;
		FMemory::Memset(initParams, 0);
		initParams.Flags = ovrInit_RequestVersion;
		initParams.RequestedMinorVersion = OVR_MINOR_VERSION;
#if !UE_BUILD_SHIPPING
//		initParams.LogCallback = OvrLogCallback;
#endif

		ovrResult initStatus = ovr_Initialize(&initParams);
		if (!OVR_SUCCESS(initStatus) && initStatus == ovrError_LibLoad)
		{
			// fatal errors: can't load library
 			UE_LOG(LogOcInput, Log, TEXT("Can't find Oculus library %s: is proper Runtime installed? Version: %s"),
 				TEXT(OVR_FILE_DESCRIPTION_STRING), TEXT(OVR_VERSION_STRING));
			return;
		}

		FOculusTouchControllerPair& ControllerPair = *new(ControllerPairs) FOculusTouchControllerPair();

		// @todo: Unreal controller index should be assigned to us by the engine to ensure we don't contest with other devices
		ControllerPair.UnrealControllerIndex = 0; //???? NextUnrealControllerIndex++;

		IModularFeatures::Get().RegisterModularFeature( GetModularFeatureName(), this );
		GEngine->MotionControllerDevices.AddUnique(this);

		UE_LOG(LogOcInput, Log, TEXT("OculusInput is initialized. Init status %d. Runtime version: %s"), int(initStatus), *FString(ANSI_TO_TCHAR(ovr_GetVersionString())));
	}
}
Beispiel #27
0
qboolean VR_Enable()
{
	int i;
	if( ovr_Initialize(NULL) != ovrSuccess ) {
		Con_Printf("Failed to Initialize Oculus SDK");
		return false;
	}

	if( ovrHmd_Create(0, &hmd) != ovrSuccess ) {
		Con_Printf("Failed to get HMD");
		return false;
	}

	if( !InitOpenGLExtensions() ) {
		Con_Printf("Failed to initialize OpenGL extensions");
		return false;
	}

	ovrHmd_CreateMirrorTextureGL(hmd, GL_RGBA, glwidth, glheight, (ovrTexture**)&mirror_texture);
	glGenFramebuffersEXT(1, &mirror_fbo);
	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, mirror_fbo);
	glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, mirror_texture->OGL.TexId, 0);
	glFramebufferRenderbufferEXT(GL_READ_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);

	for( i = 0; i < 2; i++ ) {
		ovrSizei size = ovrHmd_GetFovTextureSize(hmd, (ovrEyeType)i, hmd->DefaultEyeFov[i], 1);

		eyes[i].index = i;
		eyes[i].fbo = CreateFBO(size.w, size.h);
		eyes[i].render_desc = ovrHmd_GetRenderDesc(hmd, (ovrEyeType)i, hmd->DefaultEyeFov[i]);
		eyes[i].fov_x = (atan(hmd->DefaultEyeFov[i].LeftTan) + atan(hmd->DefaultEyeFov[i].RightTan)) / M_PI_DIV_180;
		eyes[i].fov_y = (atan(hmd->DefaultEyeFov[i].UpTan) + atan(hmd->DefaultEyeFov[i].DownTan)) / M_PI_DIV_180;
	}

	ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence|ovrHmdCap_DynamicPrediction);
	ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation|ovrTrackingCap_MagYawCorrection|ovrTrackingCap_Position, 0);
	
	wglSwapIntervalEXT(0); // Disable V-Sync

	vr_initialized = true;
	return true;
}
void OculusInterface::init()
{
    try
    {
        ovr_Initialize();
        hmd = ovrHmd_Create(0);

        if(hmd)
            ovrHmd_GetDesc(hmd, &hmdDesc);
        else
            throw 0;
    }
    catch(int e)
    {
        cout << "Cannot get HMD" << endl;
        //for now.
//        initialized = false; 
//        return;

        //TODO replace content of this exeption catch by creating a virtual debug HMD to run correctly

        hmd = ovrHmd_CreateDebug(ovrHmd_DK2);
        ovrHmd_GetDesc(hmd, &hmdDesc);
    }

    customReport();
    
    try
    {
        if(!ovrHmd_StartSensor(hmd,ovrSensorCap_Orientation |ovrSensorCap_YawCorrection |ovrSensorCap_Position,ovrSensorCap_Orientation)) //minial required 
            throw string("Unable to start sensor! The detected device by OVR is not capable to get sensor state. We cannot do anything with that...");
    }
    catch (string const& e)
    {
        cerr << e << endl;
        ovrHmd_Destroy(hmd);
        ovr_Shutdown();
        abort();
    }   
    
    initialized = true;
}
  virtual GLFWwindow * createRenderingTarget(glm::uvec2 & outSize, glm::ivec2 & outPosition) {
    outSize = glm::uvec2(800, 600);
    outPosition = glm::ivec2(100, 100);
    Stacks::projection().top() = glm::perspective(
        PI / 3.0f, aspect(outSize),
        0.01f, 10000.0f);
    Stacks::modelview().top() = glm::lookAt(
        glm::vec3(0.0f, 0.0f, 3.5f),
        Vectors::ORIGIN, Vectors::UP);

    GLFWwindow * result = glfw::createWindow(outSize, outPosition);

    ovr_Initialize();
    hmd = ovrHmd_Create(0);

    if (!hmd || !ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation, 0)) {
      FAIL("Unable to locate Rift sensors");
    }
    return result;
  }
  virtual int run() {
    SAY("Initializing SDK");
    ovr_Initialize();

    int hmdCount = ovrHmd_Detect();
    SAY("Found %d connected Rift device(s)", hmdCount);
    for (int i = 0; i < hmdCount; ++i) {
      ovrHmd hmd = ovrHmd_Create(i);
      SAY(hmd->ProductName);
      ovrHmd_Destroy(hmd);
    }

    ovrHmd hmd = ovrHmd_CreateDebug(ovrHmd_DK2);
    SAY(hmd->ProductName);
    ovrHmd_Destroy(hmd);

    ovr_Shutdown();

    SAY("Exiting");
    return 0;
  }