1. #include "ApplicationManager.h"
  2. #include "IrrlichtEngineManager.h"
  3.  
  4. static const char GUI_XML_FILE[] = "../../media/guiTest.xml";
  5.  
  6. static const int PARTICLE_START_COLOUR = 0xFFCC4400;
  7. static const int PARTICLE_END_COLOUR = 0xFF00FF44;
  8. static const int PARTICLE_MIN_AGE = 800;
  9. static const int PARTICLE_MAX_AGE = 2000;
  10. static const int PARTICLE_ANGLE = 0;
  11. static const vector3df PARTICLE_INITIAL_DIRECTION = vector3df(0.0f,0.06f,0.0f);
  12. static const aabbox3d<f32> PARTICLE_EMITTER_SIZE = aabbox3d<f32>(-15,0,50,15,1,60);
  13. static const int PARTICLE_MIN_EMITTER_RATE = 80;
  14. static const int PARTICLE_MAX_EMITTER_RATE = 100;
  15. static const dimension2df PARTICLE_MIN_SIZE = dimension2df(10.f,10.f);
  16. static const dimension2df PARTICLE_MAX_SIZE = dimension2df(20.f,20.f);
  17. static const char PARTICLE_MATERIAL[] = "../../media/fire.bmp";
  18.  
  19. static const char TERRAIN_HEIGHTMAP[] = "../../media/heightmap.bmp";
  20. static const char TERRAIN_MATERIAL[] = "../../media/terrain.bmp";
  21. static const char TERRAIN_DETAIL[] = "../../media/detail.jpg";
  22. static const float TERRAIN_DETAIL_SCALE = 20.0f;
  23. static const vector3df TERRAIN_SCALE = vector3df(40.0f, 4.0f, 40.0f);
  24. static const float TERRAIN_CAMERA_FAR_DISTANCE = 50000.0f;
  25. static const vector3df TERRAIN_CAMERA_START_POS = vector3df(0, 10, 0);
  26.  
  27.  
  28.  
  29. ApplicationManager::ApplicationManager()
  30. {
  31. InitialiseVariables();
  32. }
  33.  
  34. ApplicationManager::~ApplicationManager()
  35. {
  36.  
  37. }
  38.  
  39. bool ApplicationManager::OnEvent(const SEvent& event)
  40. {
  41. if (event.EventType == EET_GUI_EVENT)
  42. {
  43. if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
  44. {
  45. ShutdownCurrentDemo();
  46.  
  47. ENGINEMANAGER.GetGUIEnnvironment()->getRootGUIElement()->setVisible(false);
  48.  
  49. s32 id = event.GUIEvent.Caller->getID();
  50.  
  51. if (id == 1)
  52. {
  53. StartupModel();
  54. return true;
  55. }
  56.  
  57. if (id == 2)
  58. {
  59. StartupLighting();
  60. return true;
  61. }
  62.  
  63. if (id == 3)
  64. {
  65. StartupParticles();
  66. return true;
  67. }
  68.  
  69. if (id == 4)
  70. {
  71. StartupTerrain();
  72. return true;
  73. }
  74. }
  75. }
  76. else if (event.EventType == EET_KEY_INPUT_EVENT)
  77. {
  78. if (event.KeyInput.Key == KEY_ESCAPE)
  79. ShutdownCurrentDemo();
  80. }
  81.  
  82. return false;
  83. }
  84.  
  85. void ApplicationManager::InitialiseVariables()
  86. {
  87. currentDemo = NONE;
  88. camera = NULL;
  89. terrain = NULL;
  90. particleSystem = NULL;
  91. model = NULL;
  92. light1 = NULL;
  93. billboard = NULL;
  94. }
  95.  
  96. void ApplicationManager::Startup()
  97. {
  98. ENGINEMANAGER.GetIrrlichtDevice()->setEventReceiver(this);
  99. ENGINEMANAGER.GetGUIEnnvironment()->loadGUI(GUI_XML_FILE);
  100. }
  101.  
  102. void ApplicationManager::ShutdownCurrentDemo()
  103. {
  104. ENGINEMANAGER.GetGUIEnnvironment()->getRootGUIElement()->setVisible(true);
  105.  
  106. if (currentDemo == PARTICLE)
  107. ShutdownParticles();
  108. else if (currentDemo == TERRAIN)
  109. ShutdownTerrain();
  110. else if (currentDemo == LIGHTING)
  111. ShutdownLighting();
  112. else if (currentDemo == MODEL)
  113. ShutdownModel();
  114.  
  115. InitialiseVariables();
  116. }
  117.  
  118. void ApplicationManager::StartupModel()
  119. {
  120. currentDemo = MODEL;
  121.  
  122. camera = ENGINEMANAGER.GetSceneManager()->addCameraSceneNodeFPS(
  123. NULL,
  124. 50.0f,
  125. 0.05f);
  126.  
  127. ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(false);
  128.  
  129. IAnimatedMesh* mesh = ENGINEMANAGER.GetSceneManager()->
  130. getMesh("../../media/ninja.b3d");
  131.  
  132. if (mesh == NULL)
  133. {
  134. ENGINEMANAGER.EndRenderLoop();
  135. return;
  136. }
  137.  
  138. model = ENGINEMANAGER.GetSceneManager()->addAnimatedMeshSceneNode(mesh);
  139. model->setPosition(vector3df(0, 0, 30));
  140. model->setMaterialFlag(EMF_LIGHTING, false);
  141. }
  142.  
  143. void ApplicationManager::ShutdownModel()
  144. {
  145. ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(true);
  146. if (camera != NULL) camera->remove();
  147. if (model != NULL) model->remove();
  148. }
  149.  
  150. void ApplicationManager::StartupLighting()
  151. {
  152. currentDemo = LIGHTING;
  153.  
  154. camera = ENGINEMANAGER.GetSceneManager()->addCameraSceneNodeFPS(
  155. NULL,
  156. 50.0f,
  157. 0.05f);
  158.  
  159. ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(false);
  160.  
  161. IAnimatedMesh* mesh = ENGINEMANAGER.GetSceneManager()->
  162. getMesh("../../media/ninja.b3d");
  163.  
  164. if (mesh == NULL)
  165. {
  166. ENGINEMANAGER.EndRenderLoop();
  167. return;
  168. }
  169.  
  170. model = ENGINEMANAGER.GetSceneManager()->addAnimatedMeshSceneNode(mesh);
  171. model->setPosition(vector3df(0, 0, 30));
  172.  
  173. billboard = ENGINEMANAGER.GetSceneManager()->addBillboardSceneNode(
  174. NULL,
  175. dimension2d<f32>(3, 3));
  176. billboard->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
  177. billboard->setMaterialTexture(0, ENGINEMANAGER.GetVideoDriver()->getTexture("../../media/particle.bmp"));
  178. billboard->setMaterialFlag(video::EMF_LIGHTING, false);
  179.  
  180. light1 = ENGINEMANAGER.GetSceneManager()->addLightSceneNode(
  181. billboard,
  182. core::vector3df(0,0,0),
  183. video::SColorf(1.0f, 0.5f, 1.0f),
  184. 800.0f);
  185.  
  186. ISceneNodeAnimator* anim = ENGINEMANAGER.GetSceneManager()->createFlyCircleAnimator(
  187. core::vector3df(0,5,30),
  188. 10.0f);
  189.  
  190. billboard->addAnimator(anim);
  191. anim->drop();
  192. }
  193.  
  194. void ApplicationManager::ShutdownLighting()
  195. {
  196. ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(true);
  197. if (camera != NULL) camera->remove();
  198. if (model != NULL) model->remove();
  199. if (light1 != NULL) light1->remove();
  200. if (billboard != NULL) billboard->remove();
  201. }
  202.  
  203. void ApplicationManager::StartupParticles()
  204. {
  205. currentDemo = PARTICLE;
  206.  
  207. camera = ENGINEMANAGER.GetSceneManager()->addCameraSceneNodeFPS(
  208. NULL,
  209. 50.0f,
  210. 0.05f);
  211.  
  212. ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(false);
  213.  
  214. particleSystem = ENGINEMANAGER.GetSceneManager()->addParticleSystemSceneNode(false);
  215.  
  216. IParticleEmitter* em = particleSystem->createBoxEmitter(
  217. PARTICLE_EMITTER_SIZE,
  218. PARTICLE_INITIAL_DIRECTION,
  219. PARTICLE_MIN_EMITTER_RATE,
  220. PARTICLE_MAX_EMITTER_RATE,
  221. SColor(PARTICLE_START_COLOUR),
  222. SColor(PARTICLE_END_COLOUR),
  223. PARTICLE_MIN_AGE,
  224. PARTICLE_MAX_AGE,
  225. PARTICLE_ANGLE,
  226. PARTICLE_MIN_SIZE,
  227. PARTICLE_MAX_SIZE);
  228.  
  229. particleSystem->setEmitter(em);
  230. em->drop();
  231.  
  232. IParticleAffector* paf = particleSystem->createFadeOutParticleAffector();
  233. particleSystem->addAffector(paf);
  234. paf->drop();
  235.  
  236. particleSystem->setMaterialFlag(EMF_LIGHTING, false);
  237. particleSystem->setMaterialFlag(EMF_ZWRITE_ENABLE, false);
  238. particleSystem->setMaterialTexture(0, ENGINEMANAGER.GetVideoDriver()->getTexture(PARTICLE_MATERIAL));
  239. particleSystem->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
  240. }
  241.  
  242. void ApplicationManager::ShutdownParticles()
  243. {
  244. ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(true);
  245. if (camera != NULL) camera->remove();
  246. if (particleSystem != NULL) particleSystem->remove();
  247. }
  248.  
  249. void ApplicationManager::StartupTerrain()
  250. {
  251. currentDemo = TERRAIN;
  252.  
  253. camera = ENGINEMANAGER.GetSceneManager()->addCameraSceneNodeFPS();
  254. camera->setFarValue(TERRAIN_CAMERA_FAR_DISTANCE);
  255. camera->setPosition(TERRAIN_CAMERA_START_POS);
  256.  
  257. ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(false);
  258.  
  259. terrain = ENGINEMANAGER.GetSceneManager()->addTerrainSceneNode(TERRAIN_HEIGHTMAP);
  260.  
  261. terrain->setScale(TERRAIN_SCALE);
  262. terrain->setMaterialFlag(EMF_LIGHTING, false);
  263.  
  264. terrain->setMaterialTexture(
  265. 0,
  266. ENGINEMANAGER.GetVideoDriver()->getTexture(TERRAIN_MATERIAL));
  267. terrain->setMaterialTexture(
  268. 1,
  269. ENGINEMANAGER.GetVideoDriver()->getTexture(TERRAIN_DETAIL));
  270.  
  271. terrain->setMaterialType(EMT_DETAIL_MAP);
  272. terrain->scaleTexture(1.0f, TERRAIN_DETAIL_SCALE);
  273. }
  274.  
  275. void ApplicationManager::ShutdownTerrain()
  276. {
  277. ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(true);
  278. if (camera != NULL) camera->remove();
  279. if (terrain != NULL) terrain->remove();
  280. }
  281.  
  282. void ApplicationManager::Shutdown()
  283. {
  284. InitialiseVariables();
  285. }