Advertisement
aussa

Untitled

May 8th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.49 KB | None | 0 0
  1. // GMTL includes
  2. #include <gmtl/Matrix.h>
  3. #include <gmtl/MatrixOps.h>
  4. #include <gmtl/External/OpenSGConvert.h>
  5. // OpenSG includes
  6. #include <OpenSG/OSGGLUT.h>
  7. #include <OpenSG/OSGConfig.h>
  8. #include <OpenSG/OSGGLUTWindow.h>
  9. #include <OpenSG/OSGSimpleSceneManager.h>
  10. // inVRs includes
  11. #include <inVRs/OutputInterface/OutputInterface.h>
  12. #include <inVRs/OutputInterface/SceneGraphNodeInterface.h>
  13. #include <inVRs/OutputInterface/OpenSGSceneGraphInterface/OpenSGSceneGraphInterface.h>
  14. #include <inVRs/InputInterface/InputInterface.h>
  15. #include <inVRs/InputInterface/ControllerManager/ControllerManager.h>
  16. #include <inVRs/InputInterface/ControllerManager/GlutMouseDevice.h>
  17. #include <inVRs/InputInterface/ControllerManager/GlutCharKeyboardDevice.h>
  18. #include <inVRs/SystemCore/Configuration.h>
  19. #include <inVRs/SystemCore/SystemCore.h>
  20. #include <inVRs/SystemCore/Timer.h>
  21. #include <inVRs/SystemCore/TransformationManager/TransformationManager.h>
  22. #include <inVRs/SystemCore/WorldDatabase/WorldDatabase.h>
  23. #include <inVRs/Modules/Navigation/Navigation.h>
  24. #include <inVRs/Modules/Interaction/Interaction.h>
  25. #include <inVRs/tools/libraries/HeightMap/HeightMapModifier.h>
  26. #include <inVRs/tools/libraries/HeightMap/HeightMapManager.h>
  27. #include <inVRs/tools/libraries/Skybox/Skybox.h>
  28. #include <inVRs/tools/libraries/CollisionMap/CheckCollisionModifier.h>
  29.  
  30. OSG_USING_NAMESPACE // Activate the OpenSG namespace
  31.  
  32. //------------------------------------------------------------------------------
  33. // Global Variables:
  34. //------------------------------------------------------------------------------
  35. SimpleSceneManager *mgr; // the SimpleSceneManager to manage applications
  36. bool grabMouse = true; // is the mouse stuck in the window ?
  37.  
  38. float lastTimeStamp; // remember the time
  39. User* localUser = NULL; // our local user
  40. ControllerManager *controllerManager; // the unit handling input devices
  41. Controller* controller; // an abstract input device
  42. Navigation *navigation; // the inVRs navigation module
  43. Interaction* interaction; // the inVRs interaction module
  44.  
  45. CameraTransformation* camera = NULL; // the transformation of the camera
  46. gmtl::Matrix44f camMatrix; // a matrix representing the above
  47.  
  48. Skybox skybox; // scene surroundings
  49.  
  50. NetworkInterface* network; // an interface to the network module
  51. AvatarInterface* avatar = NULL; // an interface to a user representation
  52.  
  53. float windMillSpeed = 0; // the rotational speed of a windmill
  54.  
  55. //------------------------------------------------------------------------------
  56. // Forward Declarations:
  57. //------------------------------------------------------------------------------
  58. // forward declaration so we can have the interesting parts upfront
  59. int setupGLUT(int *argc, char *argv[]);
  60.  
  61. // forward declaration to cleanup the used modules and databases
  62. void cleanup();
  63.  
  64. // The following methods are called by the SystemCore to notify the application
  65. // when CoreComponents, Interfaces or Modules are initialized.
  66. void initCoreComponents(CoreComponents comp);
  67. void initInputInterface(ModuleInterface* moduleInterface);
  68. void initModules(ModuleInterface* module);
  69.  
  70. //------------------------------------------------------------------------------
  71. // The main method
  72. //------------------------------------------------------------------------------
  73. int main(int argc, char **argv) {
  74. osgInit(argc, argv); // initialize OpenSG
  75. int winid = setupGLUT(&argc, argv); // initialize GLUT
  76.  
  77. // the connection between GLUT and OpenSG is established
  78. GLUTWindowPtr gwin = GLUTWindow::create();
  79. gwin->setId(winid);
  80. gwin->init();
  81.  
  82. //----------------------------------------------------------------------------//
  83. // Snippet-1-1 //
  84. //----------------------------------------------------------------------------//
  85.  
  86. //----------------------------------------------------------------------------//
  87. // Snippet-2-4 //
  88. //----------------------------------------------------------------------------//
  89.  
  90. //----------------------------------------------------------------------------//
  91. // Snippet-3-3 //
  92. //----------------------------------------------------------------------------//
  93.  
  94. //----------------------------------------------------------------------------//
  95. // Snippet-1-2 //
  96. //----------------------------------------------------------------------------//
  97.  
  98. //----------------------------------------------------------------------------//
  99. // Snippet-2-1 //
  100. //----------------------------------------------------------------------------//
  101.  
  102. //----------------------------------------------------------------------------//
  103. // Snippet-3-1 //
  104. //----------------------------------------------------------------------------//
  105.  
  106. //----------------------------------------------------------------------------//
  107. // Snippet-2-15 //
  108. //----------------------------------------------------------------------------//
  109.  
  110. NodePtr root = Node::create();
  111. beginEditCP(root);
  112. root->setCore(Group::create());
  113.  
  114. //----------------------------------------------------------------------------//
  115. // Snippet-1-3 //
  116. //----------------------------------------------------------------------------//
  117.  
  118. //----------------------------------------------------------------------------//
  119. // Snippet-2-16 //
  120. //----------------------------------------------------------------------------//
  121.  
  122. endEditCP(root);
  123.  
  124. //----------------------------------------------------------------------------//
  125. // Snippet-2-5 //
  126. //----------------------------------------------------------------------------//
  127.  
  128. mgr = new SimpleSceneManager; // create the SimpleSceneManager
  129. mgr->setWindow(gwin); // tell the manager what to manage
  130. mgr->setRoot(root); // attach the scenegraph to the root node
  131. mgr->showAll(); // show the whole scene
  132. mgr->getCamera()->setNear(0.1);
  133.  
  134. //----------------------------------------------------------------------------//
  135. // Snippet-2-6 //
  136. //----------------------------------------------------------------------------//
  137.  
  138. //----------------------------------------------------------------------------//
  139. // Snippet-5-2 //
  140. //----------------------------------------------------------------------------//
  141.  
  142. glutMainLoop(); // GLUT main loop
  143. return 0;
  144. }
  145.  
  146. void display(void) {
  147.  
  148. //----------------------------------------------------------------------------//
  149. // Snippet-5-3 //
  150. //----------------------------------------------------------------------------//
  151.  
  152. //----------------------------------------------------------------------------//
  153. // Snippet-2-7 //
  154. //----------------------------------------------------------------------------//
  155.  
  156. //----------------------------------------------------------------------------//
  157. // Snippet-2-17 //
  158. //----------------------------------------------------------------------------//
  159.  
  160. //----------------------------------------------------------------------------//
  161. // Snippet-4-2 //
  162. //----------------------------------------------------------------------------//
  163.  
  164. //----------------------------------------------------------------------------//
  165. // Snippet-2-8 //
  166. //----------------------------------------------------------------------------//
  167.  
  168. //----------------------------------------------------------------------------//
  169. // Snippet-6-1 //
  170. //----------------------------------------------------------------------------//
  171.  
  172. mgr->redraw(); // redraw the window
  173. } // display
  174.  
  175. void reshape(int w, int h) {
  176. mgr->resize(w, h); // react to size changes
  177.  
  178. //----------------------------------------------------------------------------//
  179. // Snippet-2-9 //
  180. //----------------------------------------------------------------------------//
  181.  
  182. glutPostRedisplay();
  183. }
  184.  
  185.  
  186. void mouse(int button, int state, int x, int y) {
  187. // !!!!!! Remove in tutorial part 2, Snippet-2-10 - BEGIN
  188. // react to mouse button presses
  189. if (state) {
  190. mgr->mouseButtonRelease(button, x, y);
  191. } else {
  192. mgr->mouseButtonPress(button, x, y);
  193. }
  194. // !!!!!! Remove - END
  195.  
  196.  
  197. //----------------------------------------------------------------------------//
  198. // Snippet-2-10 //
  199. //----------------------------------------------------------------------------//
  200.  
  201. glutPostRedisplay();
  202. } // mouse
  203.  
  204. void motion(int x, int y) {
  205.  
  206. // !!!!!! Remove in tutorial part 2, Snippet 2-11 - BEGIN
  207. // react to mouse motions with pressed buttons
  208. mgr->mouseMove(x, y);
  209. // !!!!!! Remove - END
  210.  
  211.  
  212. //----------------------------------------------------------------------------//
  213. // Snippet-2-11 //
  214. //----------------------------------------------------------------------------//
  215.  
  216. glutPostRedisplay();
  217. } // motion
  218.  
  219. void keyboard(unsigned char k, int x, int y) {
  220.  
  221. //----------------------------------------------------------------------------//
  222. // Snippet-2-12 //
  223. //----------------------------------------------------------------------------//
  224.  
  225. // react to keys
  226. switch (k) {
  227. // escape-button pressed
  228. case 27: {
  229. cleanup();
  230. exit(0);
  231. } break;
  232.  
  233. //----------------------------------------------------------------------------//
  234. // Snippet-2-13 //
  235. //----------------------------------------------------------------------------//
  236.  
  237. default: {
  238. } break;
  239. } // switch
  240. } // keyboard
  241.  
  242. void keyboardUp(unsigned char k, int x, int y) {
  243.  
  244. //----------------------------------------------------------------------------//
  245. // Snippet-2-14 //
  246. //----------------------------------------------------------------------------//
  247.  
  248. } // keyboardUp
  249.  
  250.  
  251. int setupGLUT(int *argc, char *argv[]) {
  252. // setup the GLUT library which handles the windows for us
  253. glutInit(argc, argv);
  254. glutInitDisplayMode(GLUT_RGB| GLUT_DEPTH | GLUT_DOUBLE);
  255.  
  256. int winid = glutCreateWindow("inVRs Tutorial: Medieval Town");
  257.  
  258. glutReshapeFunc(reshape);
  259. glutDisplayFunc(display);
  260. glutMouseFunc(mouse);
  261. glutMotionFunc(motion);
  262. glutKeyboardFunc(keyboard);
  263. glutKeyboardUpFunc(keyboardUp);
  264. glutPassiveMotionFunc(motion);
  265. glutIdleFunc(display);
  266.  
  267. return winid;
  268. } // setupGLUT
  269.  
  270. void cleanup() {
  271.  
  272. //----------------------------------------------------------------------------//
  273. // Snippet-1-4 //
  274. //----------------------------------------------------------------------------//
  275.  
  276. osgExit();
  277. }
  278.  
  279. //----------------------------------------------------------------------------//
  280. // Snippet-3-2 //
  281. //----------------------------------------------------------------------------//
  282.  
  283. //----------------------------------------------------------------------------//
  284. // Snippet-2-2 //
  285. //----------------------------------------------------------------------------//
  286.  
  287. //----------------------------------------------------------------------------//
  288. // Snippet-2-3 //
  289. //----------------------------------------------------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement