Win32_OculusRoomTiny.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 Filename    :   OculusRoomTiny.h
00004 Content     :   Simplest possible first-person view test application for Oculus Rift
00005 Created     :   March 10, 2012
00006 Authors     :   Michael Antonov, Andrew Reisse
00007 
00008 Copyright   :   Copyright 2012 Oculus, Inc. All Rights reserved.
00009 
00010 Licensed under the Apache License, Version 2.0 (the "License");
00011 you may not use this file except in compliance with the License.
00012 You may obtain a copy of the License at
00013 
00014 http://www.apache.org/licenses/LICENSE-2.0
00015 
00016 Unless required by applicable law or agreed to in writing, software
00017 distributed under the License is distributed on an "AS IS" BASIS,
00018 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019 See the License for the specific language governing permissions and
00020 limitations under the License.
00021 
00022 *************************************************************************************/
00023 #ifndef INC_OculusRoomTiny_h
00024 #define INC_OculusRoomTiny_h
00025 
00026 #include <Windows.h>
00027 #include <xinput.h>
00028 
00029 #include "OVR.h"
00030 #include "Util/Util_Render_Stereo.h"
00031 #include "../../LibOVR/Src/Kernel/OVR_Timer.h"
00032 #include "RenderTiny_D3D1X_Device.h"
00033 
00034 using namespace OVR;
00035 using namespace OVR::RenderTiny;
00036 
00037 
00038 //-------------------------------------------------------------------------------------
00039 // ***** OculusRoomTiny Description
00040 
00041 // This app renders a simple flat-shaded room allowing the user to move along the 
00042 // floor and look around with an HMD, mouse, keyboard and gamepad. 
00043 // By default, the application will start full-screen on Oculus Rift.
00044 // 
00045 // The following keys work:
00046 //
00047 //  'W', 'S', 'A', 'D' - Move forward, back; strafe left/right.
00048 //  F1 - No stereo, no distortion.
00049 //  F2 - Stereo, no distortion.
00050 //  F3 - Stereo and distortion.
00051 //
00052 
00053 // The world RHS coordinate system is defines as follows (as seen in perspective view):
00054 //  Y - Up
00055 //  Z - Back
00056 //  X - Right
00057 const Vector3f UpVector(0.0f, 1.0f, 0.0f);
00058 const Vector3f ForwardVector(0.0f, 0.0f, -1.0f);
00059 const Vector3f RightVector(1.0f, 0.0f, 0.0f);
00060 
00061 // We start out looking in the positive Z (180 degree rotation).
00062 const float    YawInitial  = 3.141592f;
00063 const float    Sensitivity = 1.0f;
00064 const float    MoveSpeed   = 3.0f; // m/s
00065 
00066 
00067 //-------------------------------------------------------------------------------------
00068 // ***** OculusRoomTiny Application class
00069 
00070 // An instance of this class is created on application startup (main/WinMain).
00071 // 
00072 // It then works as follows:
00073 //
00074 //  OnStartup   - Window, graphics and HMD setup is done here.
00075 //                This function will initialize OVR::DeviceManager and HMD,
00076 //                creating SensorDevice and attaching it to SensorFusion.
00077 //                This needs to be done before obtaining sensor data.
00078 //                
00079 //  OnIdle      - Does per-frame processing, processing SensorFusion and
00080 //                movement input and rendering the frame.
00081 
00082 class OculusRoomTinyApp : public MessageHandler
00083 {
00084 public:
00085     OculusRoomTinyApp(HINSTANCE hinst);
00086     ~OculusRoomTinyApp();
00087 
00088     // Initializes graphics, Rift input and creates world model.
00089     virtual int  OnStartup(const char* args);
00090     // Called per frame to sample SensorFucion and render the world.
00091     virtual void OnIdle();
00092 
00093     // Installed for Oculus device messages. Optional.
00094     virtual void OnMessage(const Message& msg);
00095 
00096     // Handle input events for movement.
00097     virtual void OnGamepad(float padLx, float padLY, float padRx, float padRy);  
00098     virtual void OnMouseMove(int x, int y, int modifiers);    
00099     virtual void OnKey(unsigned vk, bool down);
00100 
00101     // Render the view for one eye.
00102     void         Render(const StereoEyeParams& stereo);
00103 
00104     // Main application loop.
00105     int          Run();
00106 
00107     // Return amount of time passed since application started in seconds.
00108     double       GetAppTime() const
00109     {
00110         return (OVR::Timer::GetTicks() - StartupTicks) * (1.0 / (double)OVR::Timer::MksPerSecond);
00111     }
00112 
00113 
00114 protected:
00115     
00116     // Win32 window setup interface.
00117     LRESULT     windowProc(UINT msg, WPARAM wp, LPARAM lp);
00118     bool        setupWindow();
00119     void        destroyWindow();
00120     // Win32 static function that delegates to WindowProc member function.
00121     static LRESULT CALLBACK systemWindowProc(HWND window, UINT msg, WPARAM wp, LPARAM lp);
00122 
00123     void        giveUsFocus(bool setFocus);
00124 
00125     static OculusRoomTinyApp*   pApp;
00126 
00127     // *** Rendering Variables
00128     Ptr<RenderDevice>   pRender;
00129     RendererParams      RenderParams;
00130     int                 Width, Height;
00131 
00132 
00133     // *** Win32 System Variables
00134     HWND                hWnd;
00135     HINSTANCE           hInstance;    
00136     POINT               WindowCenter; // In desktop coordinates
00137     bool                Quit;
00138     bool                MouseCaptured;
00139 
00140     // Dynamically ink to XInput to simplify projects.    
00141     typedef DWORD (WINAPI *PFn_XInputGetState)(DWORD dwUserIndex, XINPUT_STATE* pState);
00142     PFn_XInputGetState  pXInputGetState;
00143     HMODULE             hXInputModule;
00144     UInt32              LastPadPacketNo;
00145    
00146 
00147     // *** Oculus HMD Variables
00148     
00149     Ptr<DeviceManager>  pManager;
00150     Ptr<SensorDevice>   pSensor;
00151     Ptr<HMDDevice>      pHMD;
00152     SensorFusion        SFusion;
00153     OVR::HMDInfo        HMDInfo;
00154 
00155     // Last update seconds, used for move speed timing.
00156     double              LastUpdate;
00157     UInt64              StartupTicks;
00158 
00159      // Position and look. The following apply:
00160     Vector3f            EyePos;
00161     float               EyeYaw;         // Rotation around Y, CCW positive when looking at RHS (X,Z) plane.
00162     float               EyePitch;       // Pitch. If sensor is plugged in, only read from sensor.
00163     float               EyeRoll;        // Roll, only accessible from Sensor.
00164     float               LastSensorYaw;  // Stores previous Yaw value from to support computing delta.
00165 
00166     // Movement state; different bits may be set based on the state of keys.
00167     UByte               MoveForward;
00168     UByte               MoveBack;
00169     UByte               MoveLeft;
00170     UByte               MoveRight;
00171     Vector3f            GamepadMove, GamepadRotate;
00172 
00173     Matrix4f            View;
00174     RenderTiny::Scene   Scene;
00175    
00176     // Stereo view parameters.
00177     StereoConfig        SConfig;
00178     PostProcessType     PostProcess;
00179 
00180     // Shift accelerates movement/adjustment velocity. 
00181     bool                ShiftDown;
00182     bool                ControlDown;
00183 };
00184 
00185 // Adds sample models and lights to the argument scene.
00186 void PopulateRoomScene(Scene* scene, RenderDevice* render);
00187 
00188 
00189 #endif


oculus_sdk
Author(s):
autogenerated on Mon Oct 6 2014 03:01:19