diff options
Diffstat (limited to 'Samples/OculusRoomTiny')
8 files changed, 164 insertions, 94 deletions
diff --git a/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj b/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj index 240c632..9e3c1b1 100644 --- a/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj +++ b/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj @@ -178,9 +178,11 @@ <ClCompile Include="../../../RenderTiny_D3D11_Device.cpp" />
<ClCompile Include="../../../Win32_OculusRoomTiny.cpp" />
<ClCompile Include="../../../Win32_OculusRoomTiny_Util.cpp" />
+ <ClCompile Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="../../../RenderTiny_D3D11_Device.h" />
+ <ClInclude Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.h" />
<ClInclude Include="..\..\..\HSWDisplay_Util.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
diff --git a/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj.filters b/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj.filters index 919cd62..51fe5fe 100644 --- a/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj.filters +++ b/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj.filters @@ -11,6 +11,9 @@ <Filter>Util</Filter>
</ClCompile>
<ClCompile Include="../../../Win32_OculusRoomTiny.cpp" />
+ <ClCompile Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.cpp">
+ <Filter>CommonSrc</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="../../../RenderTiny_D3D11_Device.h">
@@ -19,10 +22,16 @@ <ClInclude Include="..\..\..\HSWDisplay_Util.h">
<Filter>Util</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.h">
+ <Filter>CommonSrc</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Util">
<UniqueIdentifier>{0750679b-ec1e-44c8-a78b-05d9e58a3588}</UniqueIdentifier>
</Filter>
+ <Filter Include="CommonSrc">
+ <UniqueIdentifier>{36ff2ee7-56d9-4606-9b8c-68dff117b124}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
</Project>
\ No newline at end of file diff --git a/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj b/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj index e176e4b..cc9dd3e 100644 --- a/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj +++ b/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj @@ -186,9 +186,11 @@ <ClCompile Include="../../../RenderTiny_D3D11_Device.cpp" />
<ClCompile Include="../../../Win32_OculusRoomTiny.cpp" />
<ClCompile Include="../../../Win32_OculusRoomTiny_Util.cpp" />
+ <ClCompile Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="../../../RenderTiny_D3D11_Device.h" />
+ <ClInclude Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.h" />
<ClInclude Include="..\..\..\HSWDisplay_Util.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
diff --git a/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj.filters b/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj.filters index 580b83a..4b0ebdd 100644 --- a/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj.filters +++ b/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj.filters @@ -11,11 +11,17 @@ <ClCompile Include="../../../Win32_OculusRoomTiny_Util.cpp">
<Filter>Util</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.cpp">
+ <Filter>CommonSrc</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="Util">
<UniqueIdentifier>{0750679b-ec1e-44c8-a78b-05d9e58a3588}</UniqueIdentifier>
</Filter>
+ <Filter Include="CommonSrc">
+ <UniqueIdentifier>{4b2897e2-d185-4e74-b7c9-b66282a1cbe7}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="../../../RenderTiny_D3D11_Device.h">
@@ -24,5 +30,8 @@ <ClInclude Include="..\..\..\HSWDisplay_Util.h">
<Filter>Util</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.h">
+ <Filter>CommonSrc</Filter>
+ </ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file diff --git a/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj b/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj index 232b7aa..a85b395 100644 --- a/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj +++ b/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj @@ -191,6 +191,7 @@ </ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="../../../OculusRoomModel.cpp" />
+ <ClCompile Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.cpp" />
<ClCompile Include="..\..\..\RenderTiny_D3D11_Device.cpp" />
<ClCompile Include="..\..\..\Win32_OculusRoomTiny.cpp" />
<ClCompile Include="..\..\..\Win32_OculusRoomTiny_Util.cpp" />
@@ -199,6 +200,7 @@ <ResourceCompile Include="../../../OculusRoomTiny2.rc" />
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.h" />
<ClInclude Include="..\..\..\HSWDisplay_Util.h" />
<ClInclude Include="..\..\..\RenderTiny_D3D11_Device.h" />
</ItemGroup>
diff --git a/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj.filters b/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj.filters index ae5e0eb..4beea60 100644 --- a/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj.filters +++ b/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj.filters @@ -11,6 +11,9 @@ <ClCompile Include="..\..\..\Win32_OculusRoomTiny_Util.cpp">
<Filter>Util</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.cpp">
+ <Filter>CommonSrc</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="../../../OculusRoomTiny2.rc" />
@@ -19,6 +22,9 @@ <Filter Include="Util">
<UniqueIdentifier>{aa2ef577-a403-4088-a39c-0a87a96151a9}</UniqueIdentifier>
</Filter>
+ <Filter Include="CommonSrc">
+ <UniqueIdentifier>{0b10aa1d-2337-4b0b-942a-843ac96a682f}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\RenderTiny_D3D11_Device.h">
@@ -27,5 +33,8 @@ <ClInclude Include="..\..\..\HSWDisplay_Util.h">
<Filter>Util</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.h">
+ <Filter>CommonSrc</Filter>
+ </ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file diff --git a/Samples/OculusRoomTiny/Win32_OculusRoomTiny.cpp b/Samples/OculusRoomTiny/Win32_OculusRoomTiny.cpp index 48373ad..74a46e5 100644 --- a/Samples/OculusRoomTiny/Win32_OculusRoomTiny.cpp +++ b/Samples/OculusRoomTiny/Win32_OculusRoomTiny.cpp @@ -215,9 +215,9 @@ int Init() ovrHmd_SetEnabledCaps(HMD, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction); // Start the sensor which informs of the Rift's pose and motion - ovrHmd_ConfigureTracking(HMD, ovrTrackingCap_Orientation | - ovrTrackingCap_MagYawCorrection | - ovrTrackingCap_Position, 0); + ovrHmd_ConfigureTracking(HMD, ovrTrackingCap_Orientation | + ovrTrackingCap_MagYawCorrection | + ovrTrackingCap_Position, 0); // This creates lights and models. pRoomScene = new Scene; @@ -304,13 +304,23 @@ void ProcessAndRender() pRender->Render(&distortionShaderFill, MeshVBs[eyeNum], MeshIBs[eyeNum],sizeof(ovrDistortionVertex)); } + unsigned char latencyColor[3]; + ovrBool drawDk2LatencyQuad = ovrHmd_GetLatencyTest2DrawColor(HMD, latencyColor); + if(drawDk2LatencyQuad) + { + const int latencyQuadSize = 20; // only needs to be 1-pixel, but larger helps visual debugging + pRender->SetViewport(HMD->Resolution.w - latencyQuadSize, 0, latencyQuadSize, latencyQuadSize); + pRender->Clear(latencyColor[0] / 255.0f, latencyColor[1] / 255.0f, latencyColor[2] / 255.0f, 0.0f); + } + pRender->SetDefaultRenderTarget(); pRender->Present( true ); // Vsync enabled // Only flush GPU for ExtendDesktop; not needed in Direct App Renering with Oculus driver. if (HMD->HmdCaps & ovrHmdCap_ExtendDesktop) - pRender->WaitUntilGpuIdle(); + pRender->WaitUntilGpuIdle(); + ovrHmd_EndFrameTiming(HMD); #endif } diff --git a/Samples/OculusRoomTiny/Win32_OculusRoomTiny_Util.cpp b/Samples/OculusRoomTiny/Win32_OculusRoomTiny_Util.cpp index 8ad3798..f371ce1 100644 --- a/Samples/OculusRoomTiny/Win32_OculusRoomTiny_Util.cpp +++ b/Samples/OculusRoomTiny/Win32_OculusRoomTiny_Util.cpp @@ -21,6 +21,7 @@ limitations under the License. #include "RenderTiny_D3D11_Device.h" #include "OVR_CAPI.h" +#include "../CommonSrc/Platform/Win32_Gamepad.h" // Win32 System Variables HWND hWnd = NULL; @@ -52,6 +53,9 @@ int Init(); void ProcessAndRender(); void Release(); +// Gamepad Variables +OvrPlatform::Win32::GamepadManager GamepadManager; +OvrPlatform::GamepadState LastGamepadState = OvrPlatform::GamepadState(); //------------------------------------------------------------------------------------- @@ -85,94 +89,117 @@ void OnKey(unsigned vk, bool down) void OnMouseMove(int x) { - const float Sensitivity = 1.0f; + const float Sensitivity = 1.0f; AdditionalYawFromMouse -= (Sensitivity * x)/ 360.0f; } bool Util_RespondToControls(float & EyeYaw, Vector3f & EyePos, Quatf PoseOrientation) { - #if 0//Optional debug output - char debugString[1000]; - sprintf_s(debugString,"Pos = (%0.2f, %0.2f, %0.2f)\n",EyePos.x,EyePos.y,EyePos.z); - OutputDebugStringA(debugString); - #endif + #if 0//Optional debug output + char debugString[1000]; + sprintf_s(debugString,"Pos = (%0.2f, %0.2f, %0.2f)\n",EyePos.x,EyePos.y,EyePos.z); + OutputDebugStringA(debugString); + #endif - //Mouse rotation - EyeYaw += AdditionalYawFromMouse; - AdditionalYawFromMouse = 0; + //Mouse rotation + EyeYaw += AdditionalYawFromMouse; + AdditionalYawFromMouse = 0; - //Get HeadYaw - float tempHeadPitch, tempHeadRoll, HeadYaw; - PoseOrientation.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(&HeadYaw,&tempHeadPitch, &tempHeadRoll); + //Get HeadYaw + float tempHeadPitch, tempHeadRoll, HeadYaw, GamepadYaw; + PoseOrientation.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(&HeadYaw,&tempHeadPitch, &tempHeadRoll); - //Move on Eye pos from controls + //Move on Eye pos from controls Vector3f localMoveVector(0,0,0); - Matrix4f yawRotate = Matrix4f::RotationY(EyeYaw + HeadYaw); - if (MoveForward) localMoveVector += Vector3f(0,0,-1); + if (MoveForward) localMoveVector += Vector3f(0,0,-1); if (MoveBack) localMoveVector += Vector3f(0,0,+1); if (MoveRight) localMoveVector += Vector3f(1,0,0); if (MoveLeft) localMoveVector += Vector3f(-1,0,0); - Vector3f orientationVector = yawRotate.Transform(localMoveVector); + //respond to gamepad + OvrPlatform::GamepadState gamepadstate; + if (GamepadManager.GetGamepadState(1, &gamepadstate)) + { + if (gamepadstate.Buttons != 0) + ovrHmd_DismissHSWDisplay(HMD); + LastGamepadState = gamepadstate; + } + + //move according to gamepad input + localMoveVector += Vector3f(LastGamepadState.LX, 0, -LastGamepadState.LY); + + //prevents double speed using gamepad and + if (localMoveVector.x > 1) localMoveVector.x = 1; + if (localMoveVector.y > 1) localMoveVector.y = 1; + + //rotate according to gamepad input + const float gamepad_sensitivity = .025; + GamepadYaw = -gamepad_sensitivity * LastGamepadState.RX; + + EyeYaw += GamepadYaw; + + Matrix4f yawRotate = Matrix4f::RotationY(EyeYaw + HeadYaw); + + Vector3f orientationVector = yawRotate.Transform(localMoveVector); - const float deltaTime = 1.0f/60.0f; + const float deltaTime = 1.0f/60.0f; orientationVector *= MoveSpeed * deltaTime * (ShiftDown ? 3.0f : 1.0f); - EyePos += orientationVector; + EyePos += orientationVector; - //Some rudimentary limitation of movement, so not to go through walls - const float minDistanceToWall = 0.30f; - EyePos.x = max(EyePos.x,-10.0f + minDistanceToWall); - EyePos.x = min(EyePos.x, 10.0f - minDistanceToWall); - EyePos.z = max(EyePos.z,-20.0f + minDistanceToWall); + //Some rudimentary limitation of movement, so not to go through walls + const float minDistanceToWall = 0.30f; + EyePos.x = max(EyePos.x,-10.0f + minDistanceToWall); + EyePos.x = min(EyePos.x, 10.0f - minDistanceToWall); + EyePos.z = max(EyePos.z,-20.0f + minDistanceToWall); - //Return if need to freeze or not - return(FreezeEyeRender); + //Return if need to freeze or not + return(FreezeEyeRender); } LRESULT CALLBACK systemWindowProc(HWND arg_hwnd, UINT msg, WPARAM wp, LPARAM lp) { - switch (msg) + switch (msg) { - case(WM_NCCREATE): hWnd = arg_hwnd; break; - - case WM_MOUSEMOVE: { - // Convert mouse motion to be relative - // (report the offset and re-center). - POINT newPos = { LOWORD(lp), HIWORD(lp) }; - ::ClientToScreen(hWnd, &newPos); - if ((newPos.x == WindowCenter.x) && (newPos.y == WindowCenter.y)) - break; - ::SetCursorPos(WindowCenter.x, WindowCenter.y); - OnMouseMove(newPos.x - WindowCenter.x); - break; - } - - case WM_MOVE: RECT r; - GetClientRect(hWnd, &r); - WindowCenter.x = r.right/2; - WindowCenter.y = r.bottom/2; - ::ClientToScreen(hWnd, &WindowCenter); - break; - - case WM_KEYDOWN: OnKey((unsigned)wp, true); break; - case WM_KEYUP: OnKey((unsigned)wp, false); break; - case WM_CREATE: SetTimer(hWnd, 0, 100, NULL); break; - case WM_TIMER: KillTimer(hWnd, 0); - - case WM_SETFOCUS: - SetCursorPos(WindowCenter.x, WindowCenter.y); - SetCapture(hWnd); - ShowCursor(FALSE); - break; - case WM_KILLFOCUS: - ReleaseCapture(); - ShowCursor(TRUE); - break; - - case WM_QUIT: - case WM_CLOSE: Quit = true; + case(WM_NCCREATE): hWnd = arg_hwnd; break; + + case WM_MOUSEMOVE: { + // Convert mouse motion to be relative + // (report the offset and re-center). + POINT newPos = { LOWORD(lp), HIWORD(lp) }; + ::ClientToScreen(hWnd, &newPos); + if ((newPos.x == WindowCenter.x) && (newPos.y == WindowCenter.y)) + break; + ::SetCursorPos(WindowCenter.x, WindowCenter.y); + OnMouseMove(newPos.x - WindowCenter.x); + break; + } + + case WM_MOVE: RECT r; + GetClientRect(hWnd, &r); + WindowCenter.x = r.right/2; + WindowCenter.y = r.bottom/2; + ::ClientToScreen(hWnd, &WindowCenter); + break; + + case WM_KEYDOWN: OnKey((unsigned)wp, true); break; + case WM_KEYUP: OnKey((unsigned)wp, false); break; + case WM_CREATE: SetTimer(hWnd, 0, 100, NULL); break; + case WM_TIMER: KillTimer(hWnd, 0); + + case WM_SETFOCUS: + SetCursorPos(WindowCenter.x, WindowCenter.y); + SetCapture(hWnd); + ShowCursor(FALSE); + break; + case WM_KILLFOCUS: + ReleaseCapture(); + ShowCursor(TRUE); + break; + + case WM_QUIT: + case WM_CLOSE: Quit = true; return 0; } @@ -184,7 +211,7 @@ HWND Util_InitWindowAndGraphics(Recti vp, int fullscreen, int multiSampleCount, { RendererParams renderParams; - // Window + // Window WNDCLASS wc; memset(&wc, 0, sizeof(wc)); wc.lpszClassName = L"OVRAppWindow"; @@ -205,11 +232,11 @@ HWND Util_InitWindowAndGraphics(Recti vp, int fullscreen, int multiSampleCount, sizeDivisor = 2; } - RECT winSize = { 0, 0, vp.w / sizeDivisor, vp.h / sizeDivisor}; + RECT winSize = { 0, 0, vp.w / sizeDivisor, vp.h / sizeDivisor}; AdjustWindowRect(&winSize, wsStyle, false); hWnd = CreateWindowA("OVRAppWindow", "OculusRoomTiny", wsStyle |WS_VISIBLE, - vp.x, vp.y, + vp.x, vp.y, winSize.right-winSize.left, winSize.bottom-winSize.top, NULL, NULL, hInstance, NULL); @@ -217,10 +244,10 @@ HWND Util_InitWindowAndGraphics(Recti vp, int fullscreen, int multiSampleCount, ::ClientToScreen(hWnd, ¢er); WindowCenter = center; - if (!hWnd) return(NULL); + if (!hWnd) return(NULL); - // Graphics - renderParams.Multisample = multiSampleCount; + // Graphics + renderParams.Multisample = multiSampleCount; renderParams.Fullscreen = fullscreen; *returnedDevice = RenderDevice::CreateDevice(renderParams, (void*)hWnd); @@ -231,8 +258,8 @@ HWND Util_InitWindowAndGraphics(Recti vp, int fullscreen, int multiSampleCount, void Util_ReleaseWindowAndGraphics(RenderDevice * prender) { - if (prender) - prender->Release(); + if (prender) + prender->Release(); if (hWnd) { @@ -248,29 +275,29 @@ void Util_ReleaseWindowAndGraphics(RenderDevice * prender) // int WINAPI WinMain(HINSTANCE hinst, HINSTANCE, LPSTR , int) { - hInstance = hinst; + hInstance = hinst; if (!Init()) { // Processes messages and calls OnIdle() to do rendering. - while (!Quit) - { - MSG msg; - if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - else - { - ProcessAndRender(); - - // Keep sleeping when we're minimized. - if (IsIconic(hWnd)) Sleep(10); - } - } + while (!Quit) + { + MSG msg; + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + else + { + ProcessAndRender(); + + // Keep sleeping when we're minimized. + if (IsIconic(hWnd)) Sleep(10); + } + } } - Release(); + Release(); OVR_ASSERT(!_CrtDumpMemoryLeaks()); return (0); } |