Advertisement
aussa

MedievalTown.cpp

May 8th, 2011
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.00 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>// GMTL includes
  28. //#include <GL/glut.h>
  29. #include <gmtl/Matrix.h>
  30. #include <gmtl/MatrixOps.h>
  31. #include <gmtl/External/OpenSGConvert.h>
  32. // OpenSG includes
  33. #include <OpenSG/OSGGLUT.h>
  34. #include <OpenSG/OSGConfig.h>
  35. #include <OpenSG/OSGGLUTWindow.h>
  36. #include <OpenSG/OSGSimpleSceneManager.h>
  37. // inVRs includes
  38. #include <inVRs/OutputInterface/OutputInterface.h>
  39. #include <inVRs/OutputInterface/SceneGraphNodeInterface.h>
  40. #include <inVRs/OutputInterface/OpenSGSceneGraphInterface/OpenSGSceneGraphInterface.h>
  41. #include <inVRs/InputInterface/InputInterface.h>
  42. #include <inVRs/InputInterface/ControllerManager/ControllerManager.h>
  43. #include <inVRs/InputInterface/ControllerManager/GlutMouseDevice.h>
  44. #include <inVRs/InputInterface/ControllerManager/GlutCharKeyboardDevice.h>
  45. #include <inVRs/SystemCore/Configuration.h>
  46. #include <inVRs/SystemCore/SystemCore.h>
  47. #include <inVRs/SystemCore/Timer.h>
  48. #include <inVRs/SystemCore/TransformationManager/TransformationManager.h>
  49. #include <inVRs/SystemCore/WorldDatabase/WorldDatabase.h>
  50. #include <inVRs/Modules/Navigation/Navigation.h>
  51. #include <inVRs/Modules/Interaction/Interaction.h>
  52. #include <inVRs/tools/libraries/HeightMap/HeightMapModifier.h>
  53. #include <inVRs/tools/libraries/HeightMap/HeightMapManager.h>
  54. #include <inVRs/tools/libraries/Skybox/Skybox.h>
  55. #include <inVRs/tools/libraries/CollisionMap/CheckCollisionModifier.h>
  56. OSG_USING_NAMESPACE // Activate the OpenSG namespace
  57. //------------------------------------------------------------------------------
  58. // Global Variables:
  59. //------------------------------------------------------------------------------
  60. SimpleSceneManager *mgr; // the SimpleSceneManager to manage applications
  61. bool grabMouse = true; // is the mouse stuck in the window ?
  62.  
  63. float lastTimeStamp; // remember the time
  64. User* localUser = NULL; // our local user
  65. ControllerManager *controllerManager; // the unit handling input devices
  66. Controller* controller; // an abstract input device
  67. Navigation *navigation; // the inVRs navigation module
  68. Interaction* interaction; // the inVRs interaction module
  69.  
  70. CameraTransformation* camera = NULL; // the transformation of the camera
  71. gmtl::Matrix44f camMatrix; // a matrix representing the above
  72.  
  73. Skybox skybox; // scene surroundings
  74.  
  75. NetworkInterface* network; // an interface to the network module
  76. AvatarInterface* avatar = NULL; // an interface to a user representation
  77.  
  78. float windMillSpeed = 0; // the rotational speed of a windmill
  79.  
  80. //------------------------------------------------------------------------------
  81. // Forward Declarations:
  82. //------------------------------------------------------------------------------
  83. // forward declaration so we can have the interesting parts upfront
  84. int setupGLUT(int *argc, char *argv[]);
  85.  
  86. // forward declaration to cleanup the used modules and databases
  87. void cleanup();
  88.  
  89. // The following methods are called by the SystemCore to notify the application
  90. // when CoreComponents, Interfaces or Modules are initialized.
  91. void initCoreComponents(CoreComponents comp);
  92. void initInputInterface(ModuleInterface* moduleInterface);
  93. void initModules(ModuleInterface* module);
  94.  
  95. //------------------------------------------------------------------------------
  96. // The main method
  97. //------------------------------------------------------------------------------
  98. int main(int argc, char **argv) {
  99. osgInit(argc, argv); // initialize OpenSG
  100. int winid = setupGLUT(&argc, argv); // initialize GLUT
  101.  
  102. // the connection between GLUT and OpenSG is established
  103. GLUTWindowPtr gwin = GLUTWindow::create();
  104. gwin->setId(winid);
  105. gwin->init();
  106.  
  107. //----------------------------------------------------------------------------//
  108. // Snippet-1-1 //
  109. //----------------------------------------------------------------------------//
  110.  
  111. //----------------------------------------------------------------------------//
  112. // Snippet-2-4 //
  113. //----------------------------------------------------------------------------//
  114.  
  115. //----------------------------------------------------------------------------//
  116. // Snippet-3-3 //
  117. //----------------------------------------------------------------------------//
  118.  
  119. //----------------------------------------------------------------------------//
  120. // Snippet-1-2 //
  121. //----------------------------------------------------------------------------//
  122.  
  123. //----------------------------------------------------------------------------//
  124. // Snippet-2-1 //
  125. //----------------------------------------------------------------------------//
  126.  
  127. //----------------------------------------------------------------------------//
  128. // Snippet-3-1 //
  129. //----------------------------------------------------------------------------//
  130.  
  131. //----------------------------------------------------------------------------//
  132. // Snippet-2-15 //
  133. //----------------------------------------------------------------------------//
  134.  
  135. NodePtr root = Node::create();
  136. beginEditCP(root);
  137. root->setCore(Group::create());
  138.  
  139. //----------------------------------------------------------------------------//
  140. // Snippet-1-3 //
  141. //----------------------------------------------------------------------------//
  142.  
  143. //----------------------------------------------------------------------------//
  144. // Snippet-2-16 //
  145. //----------------------------------------------------------------------------//
  146.  
  147. endEditCP(root);
  148.  
  149. //----------------------------------------------------------------------------//
  150. // Snippet-2-5 //
  151. //----------------------------------------------------------------------------//
  152.  
  153. mgr = new SimpleSceneManager; // create the SimpleSceneManager
  154. mgr->setWindow(gwin); // tell the manager what to manage
  155. mgr->setRoot(root); // attach the scenegraph to the root node
  156. mgr->showAll(); // show the whole scene
  157. mgr->getCamera()->setNear(0.1);
  158.  
  159. //----------------------------------------------------------------------------//
  160. // Snippet-2-6 //
  161. //----------------------------------------------------------------------------//
  162.  
  163. //----------------------------------------------------------------------------//
  164. // Snippet-5-2 //
  165. //----------------------------------------------------------------------------//
  166.  
  167. glutMainLoop(); // GLUT main loop
  168. return 0;
  169. }
  170.  
  171. void display(void) {
  172.  
  173. //----------------------------------------------------------------------------//
  174. // Snippet-5-3 //
  175. //----------------------------------------------------------------------------//
  176.  
  177. //----------------------------------------------------------------------------//
  178. // Snippet-2-7 //
  179. //----------------------------------------------------------------------------//
  180.  
  181. //----------------------------------------------------------------------------//
  182. // Snippet-2-17 //
  183. //----------------------------------------------------------------------------//
  184.  
  185. //----------------------------------------------------------------------------//
  186. // Snippet-4-2 //
  187. //----------------------------------------------------------------------------//
  188.  
  189. //----------------------------------------------------------------------------//
  190. // Snippet-2-8 //
  191. //----------------------------------------------------------------------------//
  192.  
  193. //----------------------------------------------------------------------------//
  194. // Snippet-6-1 //
  195. //----------------------------------------------------------------------------//
  196.  
  197. mgr->redraw(); // redraw the window
  198. } // display
  199.  
  200. void reshape(int w, int h) {
  201. mgr->resize(w, h); // react to size changes
  202.  
  203. //----------------------------------------------------------------------------//
  204. // Snippet-2-9 //
  205. //----------------------------------------------------------------------------//
  206.  
  207. glutPostRedisplay();
  208. }
  209.  
  210.  
  211. void mouse(int button, int state, int x, int y) {
  212. // !!!!!! Remove in tutorial part 2, Snippet-2-10 - BEGIN
  213. // react to mouse button presses
  214. if (state) {
  215. mgr->mouseButtonRelease(button, x, y);
  216. } else {
  217. mgr->mouseButtonPress(button, x, y);
  218. }
  219. // !!!!!! Remove - END
  220.  
  221.  
  222. //----------------------------------------------------------------------------//
  223. // Snippet-2-10 //
  224. //----------------------------------------------------------------------------//
  225.  
  226. glutPostRedisplay();
  227. } // mouse
  228.  
  229. void motion(int x, int y) {
  230.  
  231. // !!!!!! Remove in tutorial part 2, Snippet 2-11 - BEGIN
  232. // react to mouse motions with pressed buttons
  233. mgr->mouseMove(x, y);
  234. // !!!!!! Remove - END
  235.  
  236.  
  237. //----------------------------------------------------------------------------//
  238. // Snippet-2-11 //
  239. //----------------------------------------------------------------------------//
  240.  
  241. glutPostRedisplay();
  242. } // motion
  243.  
  244. void keyboard(unsigned char k, int x, int y) {
  245.  
  246. //----------------------------------------------------------------------------//
  247. // Snippet-2-12 //
  248. //----------------------------------------------------------------------------//
  249.  
  250. // react to keys
  251. switch (k) {
  252. // escape-button pressed
  253. case 27: {
  254. cleanup();
  255. exit(0);
  256. } break;
  257.  
  258. //----------------------------------------------------------------------------//
  259. // Snippet-2-13 //
  260. //----------------------------------------------------------------------------//
  261.  
  262. default: {
  263. } break;
  264. } // switch
  265. } // keyboard
  266.  
  267. void keyboardUp(unsigned char k, int x, int y) {
  268.  
  269. //----------------------------------------------------------------------------//
  270. // Snippet-2-14 //
  271. //----------------------------------------------------------------------------//
  272.  
  273. } // keyboardUp
  274.  
  275.  
  276. int setupGLUT(int *argc, char *argv[]) {
  277. // setup the GLUT library which handles the windows for us
  278. glutInit(argc, argv);
  279. glutInitDisplayMode(GLUT_RGB| GLUT_DEPTH | GLUT_DOUBLE);
  280.  
  281. int winid = glutCreateWindow("inVRs Tutorial: Medieval Town");
  282.  
  283. glutReshapeFunc(reshape);
  284. glutDisplayFunc(display);
  285. glutMouseFunc(mouse);
  286. glutMotionFunc(motion);
  287. glutKeyboardFunc(keyboard);
  288. glutKeyboardUpFunc(keyboardUp);
  289. glutPassiveMotionFunc(motion);
  290. glutIdleFunc(display);
  291.  
  292. return winid;
  293. } // setupGLUT
  294.  
  295. void cleanup() {
  296.  
  297. //----------------------------------------------------------------------------//
  298. // Snippet-1-4 //
  299. //----------------------------------------------------------------------------//
  300.  
  301. osgExit();
  302. }
  303.  
  304. //----------------------------------------------------------------------------//
  305. // Snippet-3-2 //
  306. //----------------------------------------------------------------------------//
  307.  
  308. //----------------------------------------------------------------------------//
  309. // Snippet-2-2 //
  310. //----------------------------------------------------------------------------//
  311.  
  312. //----------------------------------------------------------------------------//
  313. // Snippet-2-3 //
  314. //----------------------------------------------------------------------------//
  315.  
  316. #include <inVRs/tools/libraries/CollisionMap/CheckCollisionModifier.h>
  317. OSG_USING_NAMESPACE // Activate the OpenSG namespace
  318. //------------------------------------------------------------------------------
  319. // Global Variables:
  320. //------------------------------------------------------------------------------
  321. SimpleSceneManager *mgr; // the SimpleSceneManager to manage applications
  322. bool grabMouse = true; // is the mouse stuck in the window ?
  323.  
  324. float lastTimeStamp; // remember the time
  325. User* localUser = NULL; // our local user
  326. ControllerManager *controllerManager; // the unit handling input devices
  327. Controller* controller; // an abstract input device
  328. Navigation *navigation; // the inVRs navigation module
  329. Interaction* interaction; // the inVRs interaction module
  330.  
  331. CameraTransformation* camera = NULL; // the transformation of the camera
  332. gmtl::Matrix44f camMatrix; // a matrix representing the above
  333.  
  334. Skybox skybox; // scene surroundings
  335.  
  336. NetworkInterface* network; // an interface to the network module
  337. AvatarInterface* avatar = NULL; // an interface to a user representation
  338.  
  339. float windMillSpeed = 0; // the rotational speed of a windmill
  340.  
  341. //------------------------------------------------------------------------------
  342. // Forward Declarations:
  343. //------------------------------------------------------------------------------
  344. // forward declaration so we can have the interesting parts upfront
  345. int setupGLUT(int *argc, char *argv[]);
  346.  
  347. // forward declaration to cleanup the used modules and databases
  348. void cleanup();
  349.  
  350. // The following methods are called by the SystemCore to notify the application
  351. // when CoreComponents, Interfaces or Modules are initialized.
  352. void initCoreComponents(CoreComponents comp);
  353. void initInputInterface(ModuleInterface* moduleInterface);
  354. void initModules(ModuleInterface* module);
  355.  
  356. //------------------------------------------------------------------------------
  357. // The main method
  358. //------------------------------------------------------------------------------
  359. int main(int argc, char **argv) {
  360. osgInit(argc, argv); // initialize OpenSG
  361. int winid = setupGLUT(&argc, argv); // initialize GLUT
  362.  
  363. // the connection between GLUT and OpenSG is established
  364. GLUTWindowPtr gwin = GLUTWindow::create();
  365. gwin->setId(winid);
  366. gwin->init();
  367.  
  368. //----------------------------------------------------------------------------//
  369. // Snippet-1-1 //
  370. //----------------------------------------------------------------------------//
  371.  
  372. //----------------------------------------------------------------------------//
  373. // Snippet-2-4 //
  374. //----------------------------------------------------------------------------//
  375.  
  376. //----------------------------------------------------------------------------//
  377. // Snippet-3-3 //
  378. //----------------------------------------------------------------------------//
  379.  
  380. //----------------------------------------------------------------------------//
  381. // Snippet-1-2 //
  382. //----------------------------------------------------------------------------//
  383.  
  384. //----------------------------------------------------------------------------//
  385. // Snippet-2-1 //
  386. //----------------------------------------------------------------------------//
  387.  
  388. //----------------------------------------------------------------------------//
  389. // Snippet-3-1 //
  390. //----------------------------------------------------------------------------//
  391.  
  392. //----------------------------------------------------------------------------//
  393. // Snippet-2-15 //
  394. //----------------------------------------------------------------------------//
  395.  
  396. NodePtr root = Node::create();
  397. beginEditCP(root);
  398. root->setCore(Group::create());
  399.  
  400. //----------------------------------------------------------------------------//
  401. // Snippet-1-3 //
  402. //----------------------------------------------------------------------------//
  403.  
  404. //----------------------------------------------------------------------------//
  405. // Snippet-2-16 //
  406. //----------------------------------------------------------------------------//
  407.  
  408. endEditCP(root);
  409.  
  410. //----------------------------------------------------------------------------//
  411. // Snippet-2-5 //
  412. //----------------------------------------------------------------------------//
  413.  
  414. mgr = new SimpleSceneManager; // create the SimpleSceneManager
  415. mgr->setWindow(gwin); // tell the manager what to manage
  416. mgr->setRoot(root); // attach the scenegraph to the root node
  417. mgr->showAll(); // show the whole scene
  418. mgr->getCamera()->setNear(0.1);
  419.  
  420. //----------------------------------------------------------------------------//
  421. // Snippet-2-6 //
  422. //----------------------------------------------------------------------------//
  423.  
  424. //----------------------------------------------------------------------------//
  425. // Snippet-5-2 //
  426. //----------------------------------------------------------------------------//
  427.  
  428. glutMainLoop(); // GLUT main loop
  429. return 0;
  430. }
  431.  
  432. void display(void) {
  433.  
  434. //----------------------------------------------------------------------------//
  435. // Snippet-5-3 //
  436. //----------------------------------------------------------------------------//
  437.  
  438. //----------------------------------------------------------------------------//
  439. // Snippet-2-7 //
  440. //----------------------------------------------------------------------------//
  441.  
  442. //----------------------------------------------------------------------------//
  443. // Snippet-2-17 //
  444. //----------------------------------------------------------------------------//
  445.  
  446. //----------------------------------------------------------------------------//
  447. // Snippet-4-2 //
  448. //----------------------------------------------------------------------------//
  449.  
  450. //----------------------------------------------------------------------------//
  451. // Snippet-2-8 //
  452. //----------------------------------------------------------------------------//
  453.  
  454. //----------------------------------------------------------------------------//
  455. // Snippet-6-1 //
  456. //----------------------------------------------------------------------------//
  457.  
  458. mgr->redraw(); // redraw the window
  459. } // display
  460.  
  461. void reshape(int w, int h) {
  462. mgr->resize(w, h); // react to size changes
  463.  
  464. //----------------------------------------------------------------------------//
  465. // Snippet-2-9 //
  466. //----------------------------------------------------------------------------//
  467.  
  468. glutPostRedisplay();
  469. }
  470.  
  471.  
  472. void mouse(int button, int state, int x, int y) {
  473. // !!!!!! Remove in tutorial part 2, Snippet-2-10 - BEGIN
  474. // react to mouse button presses
  475. if (state) {
  476. mgr->mouseButtonRelease(button, x, y);
  477. } else {
  478. mgr->mouseButtonPress(button, x, y);
  479. }
  480. // !!!!!! Remove - END
  481.  
  482.  
  483. //----------------------------------------------------------------------------//
  484. // Snippet-2-10 //
  485. //----------------------------------------------------------------------------//
  486.  
  487. glutPostRedisplay();
  488. } // mouse
  489.  
  490. void motion(int x, int y) {
  491.  
  492. // !!!!!! Remove in tutorial part 2, Snippet 2-11 - BEGIN
  493. // react to mouse motions with pressed buttons
  494. mgr->mouseMove(x, y);
  495. // !!!!!! Remove - END
  496.  
  497.  
  498. //----------------------------------------------------------------------------//
  499. // Snippet-2-11 //
  500. //----------------------------------------------------------------------------//
  501.  
  502. glutPostRedisplay();
  503. } // motion
  504.  
  505. void keyboard(unsigned char k, int x, int y) {
  506.  
  507. //----------------------------------------------------------------------------//
  508. // Snippet-2-12 //
  509. //----------------------------------------------------------------------------//
  510.  
  511. // react to keys
  512. switch (k) {
  513. // escape-button pressed
  514. case 27: {
  515. cleanup();
  516. exit(0);
  517. } break;
  518.  
  519. //----------------------------------------------------------------------------//
  520. // Snippet-2-13 //
  521. //----------------------------------------------------------------------------//
  522.  
  523. default: {
  524. } break;
  525. } // switch
  526. } // keyboard
  527.  
  528. void keyboardUp(unsigned char k, int x, int y) {
  529.  
  530. //----------------------------------------------------------------------------//
  531. // Snippet-2-14 //
  532. //----------------------------------------------------------------------------//
  533.  
  534. } // keyboardUp
  535.  
  536.  
  537. int setupGLUT(int *argc, char *argv[]) {
  538. // setup the GLUT library which handles the windows for us
  539. glutInit(argc, argv);
  540. glutInitDisplayMode(GLUT_RGB| GLUT_DEPTH | GLUT_DOUBLE);
  541.  
  542. int winid = glutCreateWindow("inVRs Tutorial: Medieval Town");
  543.  
  544. glutReshapeFunc(reshape);
  545. glutDisplayFunc(display);
  546. glutMouseFunc(mouse);
  547. glutMotionFunc(motion);
  548. glutKeyboardFunc(keyboard);
  549. glutKeyboardUpFunc(keyboardUp);
  550. glutPassiveMotionFunc(motion);
  551. glutIdleFunc(display);
  552.  
  553. return winid;
  554. } // setupGLUT
  555.  
  556. void cleanup() {
  557.  
  558. //----------------------------------------------------------------------------//
  559. // Snippet-1-4 //
  560. //----------------------------------------------------------------------------//
  561.  
  562. osgExit();
  563. }
  564.  
  565. //----------------------------------------------------------------------------//
  566. // Snippet-3-2 //
  567. //----------------------------------------------------------------------------//
  568.  
  569. //----------------------------------------------------------------------------//
  570. // Snippet-2-2 //
  571. //----------------------------------------------------------------------------//
  572.  
  573. //----------------------------------------------------------------------------//
  574. // Snippet-2-3 //
  575. //----------------------------------------------------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement