- #include "ApplicationManager.h"
- #include "IrrlichtEngineManager.h"
- static const char GUI_XML_FILE[] = "../../media/guiTest.xml";
- static const int PARTICLE_START_COLOUR = 0xFFCC4400;
- static const int PARTICLE_END_COLOUR = 0xFF00FF44;
- static const int PARTICLE_MIN_AGE = 800;
- static const int PARTICLE_MAX_AGE = 2000;
- static const int PARTICLE_ANGLE = 0;
- static const vector3df PARTICLE_INITIAL_DIRECTION = vector3df(0.0f,0.06f,0.0f);
- static const aabbox3d<f32> PARTICLE_EMITTER_SIZE = aabbox3d<f32>(-15,0,50,15,1,60);
- static const int PARTICLE_MIN_EMITTER_RATE = 80;
- static const int PARTICLE_MAX_EMITTER_RATE = 100;
- static const dimension2df PARTICLE_MIN_SIZE = dimension2df(10.f,10.f);
- static const dimension2df PARTICLE_MAX_SIZE = dimension2df(20.f,20.f);
- static const char PARTICLE_MATERIAL[] = "../../media/fire.bmp";
- static const char TERRAIN_HEIGHTMAP[] = "../../media/heightmap.bmp";
- static const char TERRAIN_MATERIAL[] = "../../media/terrain.bmp";
- static const char TERRAIN_DETAIL[] = "../../media/detail.jpg";
- static const float TERRAIN_DETAIL_SCALE = 20.0f;
- static const vector3df TERRAIN_SCALE = vector3df(40.0f, 4.0f, 40.0f);
- static const float TERRAIN_CAMERA_FAR_DISTANCE = 50000.0f;
- static const vector3df TERRAIN_CAMERA_START_POS = vector3df(0, 10, 0);
- ApplicationManager::ApplicationManager()
- {
- InitialiseVariables();
- }
- ApplicationManager::~ApplicationManager()
- {
- }
- bool ApplicationManager::OnEvent(const SEvent& event)
- {
- if (event.EventType == EET_GUI_EVENT)
- {
- if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
- {
- ShutdownCurrentDemo();
- ENGINEMANAGER.GetGUIEnnvironment()->getRootGUIElement()->setVisible(false);
- s32 id = event.GUIEvent.Caller->getID();
- if (id == 1)
- {
- StartupModel();
- return true;
- }
- if (id == 2)
- {
- StartupLighting();
- return true;
- }
- if (id == 3)
- {
- StartupParticles();
- return true;
- }
- if (id == 4)
- {
- StartupTerrain();
- return true;
- }
- }
- }
- else if (event.EventType == EET_KEY_INPUT_EVENT)
- {
- if (event.KeyInput.Key == KEY_ESCAPE)
- ShutdownCurrentDemo();
- }
- return false;
- }
- void ApplicationManager::InitialiseVariables()
- {
- currentDemo = NONE;
- camera = NULL;
- terrain = NULL;
- particleSystem = NULL;
- model = NULL;
- light1 = NULL;
- billboard = NULL;
- }
- void ApplicationManager::Startup()
- {
- ENGINEMANAGER.GetIrrlichtDevice()->setEventReceiver(this);
- ENGINEMANAGER.GetGUIEnnvironment()->loadGUI(GUI_XML_FILE);
- }
- void ApplicationManager::ShutdownCurrentDemo()
- {
- ENGINEMANAGER.GetGUIEnnvironment()->getRootGUIElement()->setVisible(true);
- if (currentDemo == PARTICLE)
- ShutdownParticles();
- else if (currentDemo == TERRAIN)
- ShutdownTerrain();
- else if (currentDemo == LIGHTING)
- ShutdownLighting();
- else if (currentDemo == MODEL)
- ShutdownModel();
- InitialiseVariables();
- }
- void ApplicationManager::StartupModel()
- {
- currentDemo = MODEL;
- camera = ENGINEMANAGER.GetSceneManager()->addCameraSceneNodeFPS(
- NULL,
- 50.0f,
- 0.05f);
- ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(false);
- IAnimatedMesh* mesh = ENGINEMANAGER.GetSceneManager()->
- getMesh("../../media/ninja.b3d");
- if (mesh == NULL)
- {
- ENGINEMANAGER.EndRenderLoop();
- return;
- }
- model = ENGINEMANAGER.GetSceneManager()->addAnimatedMeshSceneNode(mesh);
- model->setPosition(vector3df(0, 0, 30));
- model->setMaterialFlag(EMF_LIGHTING, false);
- }
- void ApplicationManager::ShutdownModel()
- {
- ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(true);
- if (camera != NULL) camera->remove();
- if (model != NULL) model->remove();
- }
- void ApplicationManager::StartupLighting()
- {
- currentDemo = LIGHTING;
- camera = ENGINEMANAGER.GetSceneManager()->addCameraSceneNodeFPS(
- NULL,
- 50.0f,
- 0.05f);
- ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(false);
- IAnimatedMesh* mesh = ENGINEMANAGER.GetSceneManager()->
- getMesh("../../media/ninja.b3d");
- if (mesh == NULL)
- {
- ENGINEMANAGER.EndRenderLoop();
- return;
- }
- model = ENGINEMANAGER.GetSceneManager()->addAnimatedMeshSceneNode(mesh);
- model->setPosition(vector3df(0, 0, 30));
- billboard = ENGINEMANAGER.GetSceneManager()->addBillboardSceneNode(
- NULL,
- dimension2d<f32>(3, 3));
- billboard->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
- billboard->setMaterialTexture(0, ENGINEMANAGER.GetVideoDriver()->getTexture("../../media/particle.bmp"));
- billboard->setMaterialFlag(video::EMF_LIGHTING, false);
- light1 = ENGINEMANAGER.GetSceneManager()->addLightSceneNode(
- billboard,
- core::vector3df(0,0,0),
- video::SColorf(1.0f, 0.5f, 1.0f),
- 800.0f);
- ISceneNodeAnimator* anim = ENGINEMANAGER.GetSceneManager()->createFlyCircleAnimator(
- core::vector3df(0,5,30),
- 10.0f);
- billboard->addAnimator(anim);
- anim->drop();
- }
- void ApplicationManager::ShutdownLighting()
- {
- ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(true);
- if (camera != NULL) camera->remove();
- if (model != NULL) model->remove();
- if (light1 != NULL) light1->remove();
- if (billboard != NULL) billboard->remove();
- }
- void ApplicationManager::StartupParticles()
- {
- currentDemo = PARTICLE;
- camera = ENGINEMANAGER.GetSceneManager()->addCameraSceneNodeFPS(
- NULL,
- 50.0f,
- 0.05f);
- ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(false);
- particleSystem = ENGINEMANAGER.GetSceneManager()->addParticleSystemSceneNode(false);
- IParticleEmitter* em = particleSystem->createBoxEmitter(
- PARTICLE_EMITTER_SIZE,
- PARTICLE_INITIAL_DIRECTION,
- PARTICLE_MIN_EMITTER_RATE,
- PARTICLE_MAX_EMITTER_RATE,
- SColor(PARTICLE_START_COLOUR),
- SColor(PARTICLE_END_COLOUR),
- PARTICLE_MIN_AGE,
- PARTICLE_MAX_AGE,
- PARTICLE_ANGLE,
- PARTICLE_MIN_SIZE,
- PARTICLE_MAX_SIZE);
- particleSystem->setEmitter(em);
- em->drop();
- IParticleAffector* paf = particleSystem->createFadeOutParticleAffector();
- particleSystem->addAffector(paf);
- paf->drop();
- particleSystem->setMaterialFlag(EMF_LIGHTING, false);
- particleSystem->setMaterialFlag(EMF_ZWRITE_ENABLE, false);
- particleSystem->setMaterialTexture(0, ENGINEMANAGER.GetVideoDriver()->getTexture(PARTICLE_MATERIAL));
- particleSystem->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
- }
- void ApplicationManager::ShutdownParticles()
- {
- ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(true);
- if (camera != NULL) camera->remove();
- if (particleSystem != NULL) particleSystem->remove();
- }
- void ApplicationManager::StartupTerrain()
- {
- currentDemo = TERRAIN;
- camera = ENGINEMANAGER.GetSceneManager()->addCameraSceneNodeFPS();
- camera->setFarValue(TERRAIN_CAMERA_FAR_DISTANCE);
- camera->setPosition(TERRAIN_CAMERA_START_POS);
- ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(false);
- terrain = ENGINEMANAGER.GetSceneManager()->addTerrainSceneNode(TERRAIN_HEIGHTMAP);
- terrain->setScale(TERRAIN_SCALE);
- terrain->setMaterialFlag(EMF_LIGHTING, false);
- terrain->setMaterialTexture(
- 0,
- ENGINEMANAGER.GetVideoDriver()->getTexture(TERRAIN_MATERIAL));
- terrain->setMaterialTexture(
- 1,
- ENGINEMANAGER.GetVideoDriver()->getTexture(TERRAIN_DETAIL));
- terrain->setMaterialType(EMT_DETAIL_MAP);
- terrain->scaleTexture(1.0f, TERRAIN_DETAIL_SCALE);
- }
- void ApplicationManager::ShutdownTerrain()
- {
- ENGINEMANAGER.GetIrrlichtDevice()->getCursorControl()->setVisible(true);
- if (camera != NULL) camera->remove();
- if (terrain != NULL) terrain->remove();
- }
- void ApplicationManager::Shutdown()
- {
- InitialiseVariables();
- }