OSX_OculusRoomTiny.h
Go to the documentation of this file.
00001 /************************************************************************************
00002  
00003  Filename    :   OSX_OculusRoomTiny.h
00004  Content     :   Simplest possible first-person view test application for Oculus Rift
00005  Created     :   May 7, 2013
00006  Authors     :   Michael Antonov, Andrew Reisse, Artem Bolgar
00007  
00008  Copyright   :   Copyright 2013 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_OSX_OculusRoomTiny_h
00024 #define INC_OSX_OculusRoomTiny_h
00025 
00026 #import <Cocoa/Cocoa.h>
00027 
00028 #import <CoreGraphics/CoreGraphics.h>
00029 #import <CoreGraphics/CGDirectDisplay.h>
00030 
00031 
00032 #include "OVR.h"
00033 #include "Util/Util_Render_Stereo.h"
00034 #include "../../LibOVR/Src/Kernel/OVR_Timer.h"
00035 #include "RenderTiny_GL_Device.h"
00036 
00037 using namespace OVR;
00038 using namespace OVR::RenderTiny;
00039 
00040 class OculusRoomTinyApp;
00041 
00042 @interface OVRApp : NSApplication
00043 
00044 @property (assign) IBOutlet NSWindow* win;
00045 @property (assign) OculusRoomTinyApp* App;
00046 
00047 -(void) run;
00048 
00049 @end
00050 
00051 @interface OVRView : NSOpenGLView <NSWindowDelegate>
00052 
00053 //@property (assign) OVR::Platform::OSX::PlatformCore* Platform;
00054 @property (assign) OculusRoomTinyApp* App;
00055 @property unsigned long Modifiers;
00056 
00057 -(void)ProcessMouse:(NSEvent*)event;
00058 -(void)warpMouseToCenter;
00059 
00060 +(CGDirectDisplayID) displayFromScreen:(NSScreen*)s;
00061 
00062 @end
00063 
00064 //-------------------------------------------------------------------------------------
00065 // ***** OculusRoomTiny Description
00066 
00067 // This app renders a simple flat-shaded room allowing the user to move along the
00068 // floor and look around with an HMD, mouse, keyboard and gamepad.
00069 // By default, the application will start full-screen on Oculus Rift.
00070 //
00071 // The following keys work:
00072 //
00073 //  'W', 'S', 'A', 'D' - Move forward, back; strafe left/right.
00074 //  F1 - No stereo, no distortion.
00075 //  F2 - Stereo, no distortion.
00076 //  F3 - Stereo and distortion.
00077 //
00078 
00079 // The world RHS coordinate system is defines as follows (as seen in perspective view):
00080 //  Y - Up
00081 //  Z - Back
00082 //  X - Right
00083 const Vector3f UpVector(0.0f, 1.0f, 0.0f);
00084 const Vector3f ForwardVector(0.0f, 0.0f, -1.0f);
00085 const Vector3f RightVector(1.0f, 0.0f, 0.0f);
00086 
00087 // We start out looking in the positive Z (180 degree rotation).
00088 const float    YawInitial  = 3.141592f;
00089 const float    Sensitivity = 1.0f;
00090 const float    MoveSpeed   = 3.0f; // m/s
00091 
00092 namespace OSX
00093 {
00094     class RenderDevice : public GL::RenderDevice
00095     {
00096     public:
00097         void* Context; // NSOpenGLContext
00098         
00099         // osview = NSView*
00100         RenderDevice(const RendererParams& p, void* osview, void* context);
00101         
00102         virtual void Shutdown();
00103         virtual void Present();
00104         
00105         virtual bool SetFullscreen(DisplayMode fullscreen);
00106         
00107         // osview = NSView*
00108         static RenderDevice* CreateDevice(const RendererParams& rp, void* osview);
00109     };
00110 }
00111 
00112 //-------------------------------------------------------------------------------------
00113 // ***** OculusRoomTiny Application class
00114 
00115 // An instance of this class is created on application startup (main/WinMain).
00116 //
00117 // It then works as follows:
00118 //
00119 //  OnStartup   - Window, graphics and HMD setup is done here.
00120 //                This function will initialize OVR::DeviceManager and HMD,
00121 //                creating SensorDevice and attaching it to SensorFusion.
00122 //                This needs to be done before obtaining sensor data.
00123 //
00124 //  OnIdle      - Does per-frame processing, processing SensorFusion and
00125 //                movement input and rendering the frame.
00126 
00127 class OculusRoomTinyApp : public MessageHandler
00128 {
00129     friend class OSX::RenderDevice;
00130 public:
00131     OculusRoomTinyApp(OVRApp* nsapp);
00132     ~OculusRoomTinyApp();
00133     
00134     // Initializes graphics, Rift input and creates world model.
00135     virtual int  OnStartup(const char* args);
00136     // Called per frame to sample SensorFucion and render the world.
00137     virtual void OnIdle();
00138     
00139     // Installed for Oculus device messages. Optional.
00140     virtual void OnMessage(const Message& msg);
00141     
00142     // Handle input events for movement.
00143     virtual void OnMouseMove(int x, int y, int modifiers);
00144     virtual void OnKey(unsigned vk, bool down);
00145     
00146     // Render the view for one eye.
00147     void         Render(const StereoEyeParams& stereo);
00148     
00149     // Main application loop.
00150     int          Run();
00151     void         Exit();
00152     
00153     // Return amount of time passed since application started in seconds.
00154     double       GetAppTime() const
00155     {
00156         return (OVR::Timer::GetTicks() - StartupTicks) * (1.0 / (double)OVR::Timer::MksPerSecond);
00157     }
00158     bool IsQuiting() const { return Quit; }
00159     
00160     int         GetWidth() const { return Width; }
00161     int         GetHeight() const { return Height; }
00162     
00163     bool        SetFullscreen(const RendererParams& rp, int fullscreen);
00164     
00165 protected:
00166     bool        setupWindow();
00167     void        destroyWindow();
00168 
00169     NSView*         View;
00170     NSWindow*       Win;
00171     OVRApp*         NsApp;
00172 
00173     static OculusRoomTinyApp*   pApp;
00174     
00175     // *** Rendering Variables
00176     Ptr<OSX::RenderDevice>   pRender;
00177     RendererParams      RenderParams;
00178     int                 Width, Height;
00179     
00180     bool                Quit;
00181 
00182     // *** Oculus HMD Variables
00183     
00184     Ptr<DeviceManager>  pManager;
00185     Ptr<SensorDevice>   pSensor;
00186     Ptr<HMDDevice>      pHMD;
00187     SensorFusion        SFusion;
00188     OVR::HMDInfo        HMDInfo;
00189     
00190     // Last update seconds, used for move speed timing.
00191     double              LastUpdate;
00192     OVR::UInt64         StartupTicks;
00193     
00194     // Position and look. The following apply:
00195     Vector3f            EyePos;
00196     float               EyeYaw;         // Rotation around Y, CCW positive when looking at RHS (X,Z) plane.
00197     float               EyePitch;       // Pitch. If sensor is plugged in, only read from sensor.
00198     float               EyeRoll;        // Roll, only accessible from Sensor.
00199     float               LastSensorYaw;  // Stores previous Yaw value from to support computing delta.
00200     
00201     // Movement state; different bits may be set based on the state of keys.
00202     UByte               MoveForward;
00203     UByte               MoveBack;
00204     UByte               MoveLeft;
00205     UByte               MoveRight;
00206     
00207     Matrix4f            ViewMat;
00208     RenderTiny::Scene   Scene;
00209     
00210     // Stereo view parameters.
00211     StereoConfig        SConfig;
00212     PostProcessType     PostProcess;
00213     
00214     // Shift accelerates movement/adjustment velocity.
00215     bool                ShiftDown;
00216     bool                ControlDown;
00217 };
00218 
00219 // Adds sample models and lights to the argument scene.
00220 void PopulateRoomScene(Scene* scene, RenderDevice* render);
00221 
00222 
00223 #endif


oculus_sdk
Author(s):
autogenerated on Fri Aug 28 2015 11:53:10