[61] | 1 | #include <OgreNoMemoryMacros.h>
|
---|
| 2 | #include <CEGUI/CEGUI.h>
|
---|
| 3 | #include <../CEGUIRenderer/include/OgreCEGUIRenderer.h>
|
---|
| 4 | #include <../CEGUIRenderer/include/OgreCEGUIResourceProvider.h>
|
---|
| 5 | #include <../CEGUIRenderer/include/OgreCEGUITexture.h>
|
---|
| 6 | #include <OgreMemoryMacros.h>
|
---|
| 7 |
|
---|
[100] | 8 | #include <Ogre.h>
|
---|
[115] | 9 | //#include "OgreReferenceAppLayer.h"
|
---|
[100] | 10 | //#include "OgreRefAppWorld.h"
|
---|
[61] | 11 | #include "TestCullingTerrainApplication.h"
|
---|
| 12 |
|
---|
[115] | 13 |
|
---|
[61] | 14 | #define WIN32_LEAN_AND_MEAN
|
---|
[94] | 15 | #include <windows.h>
|
---|
[61] | 16 |
|
---|
[80] | 17 | /*******************************************************/
|
---|
| 18 | /* TestCullingTerrainApplication implementation */
|
---|
| 19 | /*******************************************************/
|
---|
[100] | 20 |
|
---|
| 21 | //-----------------------------------------------------------------------
|
---|
[61] | 22 | TestCullingTerrainApplication::~TestCullingTerrainApplication()
|
---|
| 23 | {
|
---|
[122] | 24 | if (mTerrainContentGenerator)
|
---|
| 25 | {
|
---|
[93] | 26 | delete mTerrainContentGenerator;
|
---|
[122] | 27 | mTerrainContentGenerator = NULL;
|
---|
| 28 | }
|
---|
[99] | 29 | //if(mRenderTargetListener) delete mRenderTargetListener;
|
---|
[61] | 30 | }
|
---|
| 31 | //-----------------------------------------------------------------------
|
---|
[93] | 32 | void TestCullingTerrainApplication::createCamera()
|
---|
[61] | 33 | {
|
---|
[99] | 34 | // create the camera
|
---|
[103] | 35 | mCamera = mSceneMgr->createCamera("PlayerCam");
|
---|
[93] | 36 |
|
---|
[100] | 37 | /** set a nice viewpoint
|
---|
| 38 | * we use a camera node here and apply all transformations on it instead
|
---|
| 39 | * of applying all transformations directly to the camera
|
---|
| 40 | * because then the camera is displayed correctly in the visualization
|
---|
| 41 | */
|
---|
[137] | 42 | mCamNode = mSceneMgr->getRootSceneNode()->
|
---|
| 43 | createChildSceneNode("CamNode1", Vector3(707, 5000, 528));
|
---|
[100] | 44 | //mCamera->setPosition(707, 5000, 528);
|
---|
| 45 | mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
|
---|
| 46 | mCamNode->attachObject(mCamera);
|
---|
[61] | 47 |
|
---|
[100] | 48 | //-- create visualization camera
|
---|
| 49 | mVizCamera = mSceneMgr->createCamera("VizCam");
|
---|
| 50 | mVizCamera->setPosition(mCamNode->getPosition());
|
---|
| 51 |
|
---|
| 52 | mVizCamera->setNearClipDistance(1);
|
---|
[93] | 53 | mCamera->setNearClipDistance(1);
|
---|
[61] | 54 |
|
---|
[99] | 55 | // infinite far plane?
|
---|
[93] | 56 | if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
|
---|
| 57 | {
|
---|
[100] | 58 | mVizCamera->setFarClipDistance(0);
|
---|
[93] | 59 | mCamera->setFarClipDistance(0);
|
---|
| 60 | }
|
---|
| 61 | else
|
---|
| 62 | {
|
---|
[104] | 63 | mVizCamera->setFarClipDistance(20000);
|
---|
| 64 | mCamera->setFarClipDistance(20000);
|
---|
[99] | 65 | }
|
---|
[61] | 66 | }
|
---|
[99] | 67 |
|
---|
[61] | 68 | //-----------------------------------------------------------------------
|
---|
[99] | 69 | bool TestCullingTerrainApplication::setup()
|
---|
| 70 | {
|
---|
| 71 | bool result = ExampleApplication::setup();
|
---|
| 72 |
|
---|
| 73 | createRenderTargetListener();
|
---|
| 74 |
|
---|
| 75 | return result;
|
---|
| 76 | }
|
---|
| 77 | //-----------------------------------------------------------------------
|
---|
| 78 | void TestCullingTerrainApplication::createRenderTargetListener()
|
---|
| 79 | {
|
---|
| 80 | mWindow->addListener(new VisualizationRenderTargetListener(mSceneMgr));
|
---|
| 81 | }
|
---|
| 82 | //-----------------------------------------------------------------------
|
---|
[75] | 83 | void TestCullingTerrainApplication::createScene()
|
---|
[61] | 84 | {
|
---|
| 85 | // Set ambient light
|
---|
[139] | 86 | mAmbientLight = ColourValue(0.5, 0.5, 0.5);
|
---|
| 87 | mSceneMgr->setAmbientLight(mAmbientLight);
|
---|
[113] | 88 |
|
---|
[110] | 89 | //-- create light
|
---|
[111] | 90 | mSunLight = mSceneMgr->createLight("SunLight");
|
---|
| 91 | mSunLight->setType(Light::LT_DIRECTIONAL);
|
---|
| 92 | //mSunLight->setType(Light::LT_SPOTLIGHT);
|
---|
[112] | 93 | //mSunLight->setSpotlightRange(Degree(30), Degree(50));
|
---|
| 94 |
|
---|
[111] | 95 | mSunLight->setPosition(707, 2000, 500);
|
---|
| 96 | mSunLight->setCastShadows(true);
|
---|
| 97 |
|
---|
[137] | 98 | // set light angle not too sharp, otherwise shadows textures will be broken
|
---|
[113] | 99 | Vector3 dir(0.5, 1, 0.5);
|
---|
[110] | 100 | dir.normalise();
|
---|
[112] | 101 | mSunLight->setDirection(dir);
|
---|
| 102 | //mSunLight->setDirection(Vector3::NEGATIVE_UNIT_Y);
|
---|
[111] | 103 | mSunLight->setDiffuseColour(1, 1, 1);
|
---|
| 104 | mSunLight->setSpecularColour(1, 1, 1);
|
---|
[110] | 105 |
|
---|
[137] | 106 | // -- Fog
|
---|
[61] | 107 | // NB it's VERY important to set this before calling setWorldGeometry
|
---|
| 108 | // because the vertex program picked will be different
|
---|
| 109 | ColourValue fadeColour(0.93, 0.86, 0.76);
|
---|
| 110 | mWindow->getViewport(0)->setBackgroundColour(fadeColour);
|
---|
| 111 | //mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
|
---|
[94] | 112 |
|
---|
[61] | 113 | // Create a skybox
|
---|
[103] | 114 | mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 5000, false);
|
---|
| 115 |
|
---|
[61] | 116 | std::string terrain_cfg("terrain.cfg");
|
---|
| 117 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
---|
| 118 | terrain_cfg = mResourcePath + terrain_cfg;
|
---|
| 119 | #endif
|
---|
[74] | 120 | mSceneMgr->setWorldGeometry(terrain_cfg);
|
---|
[75] | 121 |
|
---|
[100] | 122 | //-- CEGUI setup
|
---|
[61] | 123 | setupGui();
|
---|
[100] | 124 |
|
---|
[111] | 125 | // Floor plane
|
---|
[121] | 126 | /*
|
---|
| 127 | Plane plane;
|
---|
[111] | 128 | plane.normal = Vector3::UNIT_Y;
|
---|
| 129 | plane.d = -60;
|
---|
| 130 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
| 131 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
| 132 | 5000,5000,100,100,true,1,5,5,Vector3::UNIT_Z);
|
---|
| 133 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
| 134 | pPlaneEnt->setMaterialName("Examples/Rockwall");
|
---|
| 135 | pPlaneEnt->setCastShadows(true);
|
---|
[121] | 136 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
| 137 | */
|
---|
[137] | 138 | mSceneMgr->setShadowTextureSettings(1024, 2);
|
---|
[112] | 139 | mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5));
|
---|
[139] | 140 | //mSceneMgr->setShowDebugShadows(true);
|
---|
[111] | 141 |
|
---|
| 142 |
|
---|
[100] | 143 | //-- terrain content setup
|
---|
| 144 |
|
---|
[80] | 145 | // HACK: necessary to call once before the content creation for
|
---|
| 146 | // terrain initialisation
|
---|
| 147 | mSceneMgr->_renderScene(mCamera, mWindow->getViewport(0), true);
|
---|
[74] | 148 |
|
---|
[82] | 149 | mTerrainContentGenerator = new TerrainContentGenerator(mSceneMgr);
|
---|
[110] | 150 |
|
---|
[107] | 151 | // if no objects file generate yourself
|
---|
[110] | 152 | if (!mTerrainContentGenerator->LoadObjects("objects.out"))
|
---|
| 153 | {
|
---|
[135] | 154 | // to provide much occlusion,
|
---|
| 155 | // height is restricted to 50, so no objects appear on peaks
|
---|
[107] | 156 | mTerrainContentGenerator->SetMaxPos(Vector3(3000.0f, 50.0f, 3000.0f));
|
---|
[111] | 157 | mTerrainContentGenerator->SetOffset(0);
|
---|
[110] | 158 |
|
---|
| 159 | // the objects are generated on the whole terrain
|
---|
[120] | 160 | mTerrainContentGenerator->GenerateScene(1500, "robot");
|
---|
[112] | 161 | //mTerrainContentGenerator->GenerateScene(1500, "athene");
|
---|
[120] | 162 | //mTerrainContentGenerator->GenerateScene(500, "ninja");
|
---|
[110] | 163 | }
|
---|
[86] | 164 |
|
---|
[84] | 165 | // no limitations needed anymore: the user can set
|
---|
| 166 | // objects also on peaks of terrain
|
---|
[107] | 167 | mTerrainContentGenerator->SetMaxPos(Vector3(3000.0f, 5000.0f, 3000.0f));
|
---|
[61] | 168 | }
|
---|
| 169 | //-----------------------------------------------------------------------
|
---|
[80] | 170 | void TestCullingTerrainApplication::setupGui()
|
---|
[61] | 171 | {
|
---|
[75] | 172 | mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY,
|
---|
| 173 | false, 3000, ST_EXTERIOR_CLOSE);
|
---|
[61] | 174 | mGUISystem = new CEGUI::System(mGUIRenderer);
|
---|
| 175 |
|
---|
| 176 | // Mouse
|
---|
| 177 | CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLook.scheme");
|
---|
| 178 | CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
|
---|
[133] | 179 | mGUISystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook",
|
---|
| 180 | (CEGUI::utf8*)"MouseArrow");
|
---|
[61] | 181 |
|
---|
[75] | 182 | CEGUI::MouseCursor::getSingleton().show();
|
---|
[61] | 183 | }
|
---|
| 184 | //-----------------------------------------------------------------------
|
---|
[80] | 185 | void TestCullingTerrainApplication::createFrameListener()
|
---|
[61] | 186 | {
|
---|
[133] | 187 | mTerrainFrameListener = new TerrainFrameListener(mWindow, mCamera, mSceneMgr,
|
---|
[121] | 188 | mGUIRenderer, mTerrainContentGenerator, mVizCamera, mCamNode, mSunLight);
|
---|
[120] | 189 |
|
---|
[115] | 190 | mRoot->addFrameListener(mTerrainFrameListener);
|
---|
[61] | 191 | }
|
---|
| 192 | //-----------------------------------------------------------------------
|
---|
[80] | 193 | void TestCullingTerrainApplication::chooseSceneManager()
|
---|
[61] | 194 | {
|
---|
| 195 | mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE);
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 |
|
---|
[99] | 199 | /**************************************************************/
|
---|
| 200 | /* VisualizationRenderTargetListener implementation */
|
---|
| 201 | /**************************************************************/
|
---|
[107] | 202 | //-----------------------------------------------------------------------
|
---|
[99] | 203 | VisualizationRenderTargetListener::VisualizationRenderTargetListener(SceneManager *sceneMgr)
|
---|
| 204 | :RenderTargetListener(), mSceneMgr(sceneMgr)
|
---|
| 205 | {
|
---|
| 206 | }
|
---|
[61] | 207 | //-----------------------------------------------------------------------
|
---|
[99] | 208 | void VisualizationRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt)
|
---|
| 209 | {
|
---|
[133] | 210 | // visualization viewport
|
---|
| 211 | const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER;
|
---|
[100] | 212 | const bool nShowViz = !showViz;
|
---|
| 213 |
|
---|
[139] | 214 | mSavedShadowTechnique = mSceneMgr->getShadowTechnique();
|
---|
| 215 | mSavedAmbientLight = mSceneMgr->getAmbientLight();
|
---|
| 216 |
|
---|
| 217 | // -- ambient light must be full for visualization, shadows disabled
|
---|
[113] | 218 | if (showViz)
|
---|
| 219 | {
|
---|
| 220 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
[139] | 221 | mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
|
---|
[113] | 222 | }
|
---|
[139] | 223 |
|
---|
| 224 | mSceneMgr->setOption("PrepareVisualization", &showViz);
|
---|
[100] | 225 | mSceneMgr->setOption("SkyBoxEnabled", &nShowViz);
|
---|
| 226 | //mSceneMgr->setOption("SkyPlaneEnabled", &showViz);
|
---|
[99] | 227 |
|
---|
| 228 | RenderTargetListener::preViewportUpdate(evt);
|
---|
| 229 | }
|
---|
| 230 | //-----------------------------------------------------------------------
|
---|
| 231 | void VisualizationRenderTargetListener::postRenderTargetUpdate(const RenderTargetEvent &evt)
|
---|
| 232 | {
|
---|
[139] | 233 | // reset values
|
---|
| 234 | mSceneMgr->setShadowTechnique(mSavedShadowTechnique);
|
---|
| 235 | mSceneMgr->setAmbientLight(mSavedAmbientLight);
|
---|
| 236 |
|
---|
[99] | 237 | RenderTargetListener::postRenderTargetUpdate(evt);
|
---|
| 238 | }
|
---|
| 239 | //-----------------------------------------------------------------------
|
---|
[61] | 240 | INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
|
---|
| 241 | {
|
---|
| 242 | // Create application object
|
---|
| 243 | TestCullingTerrainApplication app;
|
---|
| 244 |
|
---|
| 245 | try
|
---|
| 246 | {
|
---|
| 247 | app.go();
|
---|
| 248 | }
|
---|
| 249 | catch( Ogre::Exception& e )
|
---|
| 250 | {
|
---|
[75] | 251 | MessageBox( NULL, e.getFullDescription().c_str(),
|
---|
| 252 | "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
|
---|
[61] | 253 | }
|
---|
| 254 |
|
---|
| 255 | return 0;
|
---|
| 256 | } |
---|