GlobeEngine
VRExampleEngine.h
Go to the documentation of this file.
1 
9 #ifndef GlobeEngine_VRExampleEngine_h
10 #define GlobeEngine_VRExampleEngine_h
11 
12 #include <math.h>
13 #include <ctime>
14 #include <iostream>
15 #include <stdio.h>
16 #include <vector>
17 #include "OpenGL_Includes.h"
18 #include "Engine.h"
19 #include "Shader.h"
20 #include "FlightCamera.h"
21 #include "Common.h"
22 #include "CoordinateSystem.h"
23 #include "SceneStateSet.h"
24 #include "DrawableComponent.h"
25 #include "Cube.h"
26 #include "DebugLogger.h"
27 #include "Timer.h"
28 #include "MemoryState.h"
29 #include "DebugMap.h"
30 #include "VRExampleComposition.h"
31 #include "Plane.h"
32 #include "PointCloud.h"
33 #include "Mesh.h"
34 
35 #include <openvr.h>
36 
37 namespace geVRExample {
38 
39  class VRExampleEngine : public ge::Engine
40  {
41 
42  public:
45 
46  void clear();
47  void destroy();
48  void create();
49 
50  // overrides from ge::Engine
51  void initializeScene(std::string _projectsrcPath=0);
52  void drawScene();
53  void resize(int _w, int _h);
54  void update();
55 
57  void setDebugMapsEnabled(bool _in);
58 
59  void drawFrame(std::shared_ptr<ge::Camera> _cam,
60  vr::Hmd_Eye nEye);
61 
62  std::string getTrackedDeviceString(vr::IVRSystem *pHmd, vr::TrackedDeviceIndex_t unDevice, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError *peError = NULL);
63  bool initVRCompositor();
64  void shutdown();
65  vmml::Vector2ui getStereoRenderTargets();
66  void setupRenderModelForTrackedDevice(vr::TrackedDeviceIndex_t unTrackedDeviceIndex);
67  vmml::Matrix4f getHMDMatrixProjectionEye(vr::Hmd_Eye nEye, float _nearClipPlane, float _farClipPlane);
68  vmml::Matrix4f getHMDMatrixPoseEye(vr::Hmd_Eye nEye);
69  void updateHMDMatrixPose();
70  vmml::Matrix4f VRExampleEngine::getCurrentViewProjectionMatrix(vr::Hmd_Eye nEye);
71 
72  void nextModel() { currentModel = (currentModel + 1) % pointclouds.size(); }
73 
74  void nextRenderMode() { currentRenderMode = RenderMode( (currentRenderMode + 1) % (both + 1) ); }
75 
76  private:
77  std::shared_ptr<ge::Shader> programForUtilities;
78  std::shared_ptr<ge::Shader> programForDebug;
79  std::shared_ptr<ge::Shader> programForPointClouds;
80  std::shared_ptr<ge::Shader> programForMeshes;
81  ge::SceneStateSet sceneStates[4];
82 
83  enum RenderMode { cloud, both };
84 
85  RenderMode currentRenderMode;
86  int currentModel;
87  std::vector<std::shared_ptr<geData::PointCloud>> pointclouds;
88  std::vector<std::shared_ptr<geData::Mesh>> meshes;
89  float rot;
90 
91  // Debugger functionality
92  geUtil::DebugLogger openglDebugLogger;
93  ge::Timer openglTimer;
94  geUtil::MemoryState openglMemory;
95  geUtil::DebugMap debugmaps[2];
96 
97  ge::FrameBufferObject earthBuffer;
98 
99  vr::IVRSystem* hmd;
100  vr::IVRRenderModels* renderModels;
101  std::string driverString;
102  std::string displayString;
103  std::string modelString;
104  vr::TrackedDevicePose_t trackedDevicePose[vr::k_unMaxTrackedDeviceCount];
105  vmml::Matrix4f m_rmat4DevicePose[vr::k_unMaxTrackedDeviceCount];
106  bool showTrackedDevice[vr::k_unMaxTrackedDeviceCount];
107  float freq;
108  int iValidPoseCount;
109  int iValidPoseCount_Last;
110  std::string poseClassesString; // what classes we saw poses for this frame
111  char devClassChar[vr::k_unMaxTrackedDeviceCount]; // for each device, a character representing its class
112  //vmml::Matrix4f convertSteamVRMatrixToVMMLMat4(const vr::HmdMatrix34_t &matPose);
113 
114  vmml::Matrix4f mat4HMDPose;
115  vmml::Matrix4f mat4eyePosLeft;
116  vmml::Matrix4f mat4eyePosRight;
117 
118  vmml::Matrix4f projLeft;
119  vmml::Matrix4f projRight;
120 
121  bool debugMapsEnabled;
122  bool debugWithoutVive;
123 
124  unsigned int screenWidth;
125  unsigned int screenHeight;
126  };
127 }
128 #endif
void updateHMDMatrixPose()
Definition: VRExampleEngine.cpp:581
bool initVRCompositor()
Definition: VRExampleEngine.cpp:442
void setDebugMapsEnabled(bool _in)
Definition: VRExampleEngine.cpp:420
void destroy()
Definition: VRExampleEngine.cpp:30
void nextRenderMode()
Definition: VRExampleEngine.h:74
Definition: MemoryState.h:16
void updateFramebufferStandardID()
Definition: VRExampleEngine.cpp:413
void create()
Definition: VRExampleEngine.cpp:35
void resize(int _w, int _h)
Definition: VRExampleEngine.cpp:410
Definition: DebugMap.h:18
void nextModel()
Definition: VRExampleEngine.h:72
Definition: DebugLogger.h:22
std::string getTrackedDeviceString(vr::IVRSystem *pHmd, vr::TrackedDeviceIndex_t unDevice, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError *peError=NULL)
Definition: VRExampleEngine.cpp:429
VRExampleEngine()
Definition: VRExampleEngine.cpp:9
Definition: FrameBufferObject.h:20
Definition: overlaywidget.h:10
void drawScene()
Definition: VRExampleEngine.cpp:326
void drawFrame(std::shared_ptr< ge::Camera > _cam, vr::Hmd_Eye nEye)
Definition: VRExampleEngine.cpp:366
void clear()
Definition: VRExampleEngine.cpp:17
Definition: Engine.h:20
void setupRenderModelForTrackedDevice(vr::TrackedDeviceIndex_t unTrackedDeviceIndex)
Definition: VRExampleEngine.cpp:472
void shutdown()
Definition: VRExampleEngine.cpp:452
void initializeScene(std::string _projectsrcPath=0)
Definition: VRExampleEngine.cpp:40
Definition: VRExampleEngine.h:39
~VRExampleEngine()
Definition: VRExampleEngine.cpp:13
Definition: SceneStateSet.h:41
void update()
Definition: VRExampleEngine.cpp:279
vmml::Vector2ui getStereoRenderTargets()
Definition: VRExampleEngine.cpp:462
vmml::Matrix4f getHMDMatrixPoseEye(vr::Hmd_Eye nEye)
Definition: VRExampleEngine.cpp:566
Definition: Timer.h:17
vmml::Matrix4f VRExampleEngine::getCurrentViewProjectionMatrix(vr::Hmd_Eye nEye)
vmml::Matrix4f getHMDMatrixProjectionEye(vr::Hmd_Eye nEye, float _nearClipPlane, float _farClipPlane)
Definition: VRExampleEngine.cpp:552