00001
00009 #ifndef VRAPP_H
00010 #define VRAPP_H
00011
00012
00013 #include <G3D/G3DAll.h>
00014 #include <iostream>
00015 using namespace std;
00016
00017 #include "DisplayTile.H"
00018 #include "InputDevice.H"
00019 #include "ProjectionVRCamera.H"
00020
00021 #ifdef USE_CLUSTER
00022 #include <synchit_client.H>
00023 #define VRG3D_DEFAULT_SYNCHIT_PORT 4045
00024 #else
00025 #define CLUSTER_NET_PORT 4045
00026 #endif
00027
00028
00029 namespace VRG3D {
00030
00031
00036 class VRApp
00037 {
00038 public:
00039
00041 VRApp();
00042 virtual ~VRApp();
00043
00049 virtual void init(const std::string &vrSetup, Log* appLog=NULL);
00050
00052 virtual void init(GWindow *_gwindow, RenderDevice *_renderDevice, DisplayTile _tile,
00053 Array<InputDevice*> _inputDevices, CoordinateFrame initialHeadFrame,
00054 const std::string &_clusterServerName="", Log *_log=NULL);
00055
00057 virtual void doUserInput(Array<VRG3D::EventRef> &events);
00058
00060 virtual void doGraphics(RenderDevice *rd);
00061
00063 virtual void run();
00064
00071 virtual void guiProcessGEvents(Array<GEvent> &gevents, Array<VRG3D::EventRef> &newGuiEvents);
00072
00076 virtual GuiButton* addGuiButtonAndTrapEvent(GuiPane *pane,
00077 const std::string &eventToGenerate,
00078 const GuiCaption &text,
00079 GuiButton::Style style=GuiButton::NORMAL_STYLE);
00080
00083 virtual void oneFrame();
00086 virtual void oneFrameGraphics();
00087
00088
00089 CoordinateFrame getHeadFrame() { return _camera->getHeadFrame(); }
00090 Log* getLog() { return _log; }
00091 ProjectionVRCameraRef getCamera() { return _camera; }
00092 RenderDevice* getRenderDevice() { return _renderDevice; }
00093 bool getReadyToEndProgram() { return _endProgram; }
00094 UserInput* getG3DUserInput() { return _userInput; }
00095 WidgetManagerRef getG3DWidgetManager() { return _widgetManager; }
00096
00098 void clientSetup();
00099 void clientRequestEvents();
00100 void clientReceiveEvents(Array<EventRef> &events);
00101 void clientRequestAndWaitForOkToSwap();
00102 void clientCheckConnection();
00103
00104 void setClearColor(Color4 clearColor) { _clearColor = clearColor; }
00105
00106 static void setupInputDevicesFromConfigFile(const std::string &filename, Log* log,
00107 Array<InputDevice*> &inputDevices);
00108
00109 static void pollWindowForGEvents(RenderDevice *rd, Array<GEvent> &gEvents);
00110
00111 static void appendGEventsToEvents(RenderDevice *rd, DisplayTile &tile, Array<EventRef> &events,
00112 Array<GEvent> &gEvents, Vector2 &mousePos);
00113
00114 static std::string getKeyName(GKey::Value key, GKeyMod mod);
00115
00116
00120 static std::string findVRG3DDataFile(const std::string &filename);
00121
00122 protected:
00123
00124 Log* _log;
00125 DisplayTile _tile;
00126 GWindow* _gwindow;
00127 RenderDevice* _renderDevice;
00128 Array<InputDevice*> _inputDevices;
00129
00130 ProjectionVRCameraRef _camera;
00131 bool _endProgram;
00132 Vector2 _curMousePos;
00133 int64 _frameCounter;
00134 Color4 _clearColor;
00135
00136 bool _isAClusterClient;
00137 std::string _clusterServerName;
00138 #ifdef USE_CLUSTER
00139 SynchItClient* _clusterSynchIt;
00140 char* _clusterSynchItBuf;
00141 #else
00142 NetworkDevice* _networkDevice;
00143 ReliableConduitRef _conduitToServer;
00144 #endif
00145
00146
00147
00148 WidgetManagerRef _widgetManager;
00149 UserInput *_userInput;
00150 Table<GuiButton*, std::string> _guiBtnToEventMap;
00151 };
00152
00153
00155 void vrg3dSleepMsecs(double msecs);
00157 void vrg3dSleepSecs(double secs);
00158
00159
00160 }
00161
00162
00163
00164 #endif
00165
00166