#include #include #include <../CEGUIRenderer/include/OgreCEGUIRenderer.h> #include <../CEGUIRenderer/include/OgreCEGUIResourceProvider.h> #include <../CEGUIRenderer/include/OgreCEGUITexture.h> #include #include //#include "OgreReferenceAppLayer.h" //#include "OgreRefAppWorld.h" #include "TestCullingIVApplication.h" #include "IVFrameListener.h" #define WIN32_LEAN_AND_MEAN #include /*********************************************************/ /* TestCullingIVApplication implementation */ /*********************************************************/ //----------------------------------------------------------------------- TestCullingIVApplication::TestCullingIVApplication() { mIVReader = new IVReader(); } //----------------------------------------------------------------------- TestCullingIVApplication::~TestCullingIVApplication() { OGRE_DELETE(mIVReader); } //----------------------------------------------------------------------- void TestCullingIVApplication::createCamera() { // create the camera mCamera = mSceneMgr->createCamera("PlayerCam"); // Look back along -Z mCamera->lookAt(Vector3(0, 0, -300)); /** set a nice viewpoint * we use a camera node here and apply all transformations on it instead * of applying all transformations directly to the camera * because then the camera is displayed correctly in the visualization */ mCamNode = mSceneMgr->getRootSceneNode()-> createChildSceneNode("CamNode1", Vector3(0, -100, -200)); mCamNode->attachObject(mCamera); //mCamNode->lookAt(Vector3(0, 0, -300), Node::TS_WORLD); //mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); //-- create visualization camera mVizCamera = mSceneMgr->createCamera("VizCam"); mVizCamera->setPosition(mCamNode->getPosition()); mVizCamera->setNearClipDistance(1); mCamera->setNearClipDistance(1); // infinite far plane? if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE)) { mVizCamera->setFarClipDistance(0); mCamera->setFarClipDistance(0); } else { mVizCamera->setFarClipDistance(20000); mCamera->setFarClipDistance(20000); } } //----------------------------------------------------------------------- bool TestCullingIVApplication::setup() { bool carryOn = ExampleApplication::setup(); if (carryOn) createRenderTargetListener(); return carryOn; } //----------------------------------------------------------------------- void TestCullingIVApplication::createRenderTargetListener() { mWindow->addListener(new VisualizationRenderTargetListener(mSceneMgr)); } //----------------------------------------------------------------------- void TestCullingIVApplication::createScene() { Real scale = 1; mSceneMgr->setOption("NodeVizScale", &scale); // HACK: change this to relative path String path = "D:/svn/gtp/trunk/VUT/Ogre/resources/"; SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node1"); SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node2"); SceneNode *node3 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node3"); SceneNode *node4 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node4"); SceneNode *node5 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node5"); SceneNode *node6 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node6"); SceneNode *node7 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node7"); SceneNode *node8 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node8"); SceneNode *node9 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node9"); node1->translate(Vector3(-500, 0, 750)); node2->translate(Vector3(-400, 0, 750)); node3->scale(Vector3(100, 100 ,100)); node3->pitch(Radian(3 * Math::HALF_PI)); node4->translate(Vector3(-100, 0, 0)); node5->translate(Vector3(0, 300, 0)); node6->scale(Vector3(100, 100 ,100)); node6->pitch(Radian(3 * Math::HALF_PI)); node6->roll(Radian(Math::HALF_PI)); node6->translate(Vector3(0, -100, 0)); node7->scale(Vector3(100, 100 ,100)); node7->pitch(Radian(3 * Math::HALF_PI)); node7->roll(Radian(Math::HALF_PI)); node7->translate(Vector3(100, 0, 0)); node8->translate(Vector3(-300, -300, 0)); Log *log = LogManager::getSingleton().createLog("IVLog.log"); mIVReader->setLog(log); /*if (mIVReader->loadFile("media\\house_test1.iv")) { mIVReader->buildTree(mSceneMgr, node1); mIVReader->buildTree(mSceneMgr, node2); } if (mIVReader->loadFile("media\\anhk.wrl")) { mIVReader->buildTree(mSceneMgr, node3); } if (mIVReader->loadFile("media\\ant.wrl")) { mIVReader->buildTree(mSceneMgr, node4); } if (mIVReader->loadFile("media\\zepplin0.wrl")) { mIVReader->buildTree(mSceneMgr, node5); } if (mIVReader->loadFile("media\\warbird.wrl")) { mIVReader->buildTree(mSceneMgr, node6); } if (mIVReader->loadFile("media\\z_wing.wrl")) { mIVReader->buildTree(mSceneMgr, node7); }*/ String fileName = path + "media\\city1500_flat_1.iv"; if (mIVReader->loadFile(fileName.c_str())) { mIVReader->buildTree(mSceneMgr, node8); } fileName = path + "media\\roofs_1500.iv"; if (mIVReader->loadFile(fileName.c_str())) { mIVReader->buildTree(mSceneMgr, node8); } fileName = path + "media\\CityRoads60.iv"; if (mIVReader->loadFile(fileName.c_str())) { mIVReader->buildTree(mSceneMgr, node8); } fileName = path + "media\\CityPlane60.iv"; if (mIVReader->loadFile(fileName.c_str())) { mIVReader->buildTree(mSceneMgr, node8); } fileName = path + "media\\test.iv"; if (mIVReader->loadFile(fileName.c_str())) { mIVReader->buildTree(mSceneMgr, node9); } mIVReader->collapse(); // Set ambient light mAmbientLight = ColourValue(0.5 , 0.5, 0.5); mSceneMgr->setAmbientLight(mAmbientLight); //-- create light mSunLight = mSceneMgr->createLight("SunLight"); mSunLight->setType(Light::LT_DIRECTIONAL); //mSunLight->setType(Light::LT_SPOTLIGHT); //mSunLight->setSpotlightRange(Degree(30), Degree(50)); mSunLight->setPosition(707, 2000, 500); mSunLight->setCastShadows(true); // set light angle not too small over the surface, otherwise shadows textures will be broken Vector3 dir(0.5, 1, 0.5); dir.normalise(); mSunLight->setDirection(dir); //mSunLight->setDirection(Vector3::NEGATIVE_UNIT_Y); mSunLight->setDiffuseColour(1, 1, 1); mSunLight->setSpecularColour(1, 1, 1); // -- Fog // NB it's VERY important to set this before calling setWorldGeometry // because the vertex program picked will be different ColourValue fadeColour(0.93, 0.86, 0.76); mWindow->getViewport(0)->setBackgroundColour(fadeColour); //mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000); // Create a skybox mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 5000, true); //-- CEGUI setup setupGui(); // Use 512x512 texture in GL since we can't go higher than the window res mSceneMgr->setShadowTextureSettings(512, 2); mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5)); } //----------------------------------------------------------------------- void TestCullingIVApplication::setupGui() { mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, ST_EXTERIOR_CLOSE); mGUISystem = new CEGUI::System(mGUIRenderer); // Mouse CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLook.scheme"); CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow"); mGUISystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow"); CEGUI::MouseCursor::getSingleton().show(); } //----------------------------------------------------------------------- void TestCullingIVApplication::createFrameListener() { mIVFrameListener = new IVFrameListener(mWindow, mCamera, mSceneMgr, mGUIRenderer, mVizCamera, mCamNode, mSunLight, this); mRoot->addFrameListener(mIVFrameListener); } //----------------------------------------------------------------------- void TestCullingIVApplication::chooseSceneManager() { mSceneMgr = mRoot->getSceneManager(ST_GENERIC); } /**************************************************************/ /* VisualizationRenderTargetListener implementation */ /**************************************************************/ //----------------------------------------------------------------------- VisualizationRenderTargetListener::VisualizationRenderTargetListener(SceneManager *sceneMgr) :RenderTargetListener(), mSceneMgr(sceneMgr) { } //----------------------------------------------------------------------- void VisualizationRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt) { // visualization viewport const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER; const bool nShowViz = !showViz; mSavedShadowTechnique = mSceneMgr->getShadowTechnique(); mSavedAmbientLight = mSceneMgr->getAmbientLight(); // -- ambient light must be full for visualization, shadows disabled if (showViz) { mSceneMgr->setAmbientLight(ColourValue(1, 1, 1)); mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); } mSceneMgr->setOption("PrepareVisualization", &showViz); mSceneMgr->setOption("SkyBoxEnabled", &nShowViz); //mSceneMgr->setOption("SkyPlaneEnabled", &showViz); RenderTargetListener::preViewportUpdate(evt); } //----------------------------------------------------------------------- void VisualizationRenderTargetListener::postRenderTargetUpdate(const RenderTargetEvent &evt) { // reset values mSceneMgr->setShadowTechnique(mSavedShadowTechnique); mSceneMgr->setAmbientLight(mSavedAmbientLight); RenderTargetListener::postRenderTargetUpdate(evt); } //----------------------------------------------------------------------- INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) { // Create application object TestCullingIVApplication app; try { app.go(); } catch( Ogre::Exception& e ) { MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); } return 0; }