- Timestamp:
- 03/30/05 17:54:55 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp
r33 r34 20 20 #include "windows.h" 21 21 22 RaySceneQuery* raySceneQuery = 0; 23 22 24 /***********************************************/ 23 25 /* TestCullingApplication implementation */ 24 26 /***********************************************/ 25 26 27 TestCullingApplication::~TestCullingApplication() 28 { 29 delete raySceneQuery; 30 } 31 //----------------------------------------------------------------------- 32 void TestCullingApplication::createCamera( void ) 33 { 34 // Create the camera 35 mCamera = mSceneMgr->createCamera("PlayerCam"); 36 37 // Position it at 500 in Z direction 38 mCamera->setPosition(Vector3(128,25,128)); 39 40 // Look back along -Z 41 mCamera->lookAt(Vector3(0,0,-300)); 42 mCamera->setNearClipDistance( 1 ); 43 mCamera->setFarClipDistance( 1000 ); 44 } 27 45 //----------------------------------------------------------------------- 28 46 void TestCullingApplication::createScene(void) 29 47 { 48 Plane waterPlane; 49 // Set ambient light 50 mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); 51 52 // Create a light 53 Light* l = mSceneMgr->createLight("MainLight"); 54 // Accept default settings: point light, white diffuse, just set position 55 // NB I could attach the light to a SceneNode if I wanted it to move automatically with 56 // other objects, but I don't 57 l->setPosition(20,80,50); 58 59 // Fog 60 // NB it's VERY important to set this before calling setWorldGeometry 61 // because the vertex program picked will be different 62 ColourValue fadeColour(0.93, 0.86, 0.76); 63 mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000); 64 mWindow->getViewport(0)->setBackgroundColour(fadeColour); 65 66 std::string terrain_cfg("terrain.cfg"); 67 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 68 terrain_cfg = mResourcePath + terrain_cfg; 69 #endif 70 mSceneMgr -> setWorldGeometry( terrain_cfg ); 71 // Infinite far plane? 72 if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE)) 73 { 74 mCamera->setFarClipDistance(0); 75 } 76 77 // Define the required skyplane 78 Plane plane; 79 // 5000 world units from the camera 80 plane.d = 5000; 81 // Above the camera, facing down 82 plane.normal = -Vector3::UNIT_Y; 83 84 // Set a nice viewpoint 85 mCamera->setPosition(707,2500,528); 86 mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); 87 88 raySceneQuery = mSceneMgr->createRayQuery( 89 Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y)); 90 30 91 // Create a skybox 31 mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox"); 32 mShip = mSceneMgr->createEntity("razor", "razor.mesh"); 33 mShipNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); 34 mShipNode->attachObject(mShip); 35 36 mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); 92 // mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox"); 37 93 38 94 // CEGUI setup 39 mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, ST_GENERIC); 95 setupGui(); 96 } 97 //----------------------------------------------------------------------- 98 void TestCullingApplication::setupGui( void ) 99 { 100 mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, ST_EXTERIOR_CLOSE); 40 101 mGUISystem = new CEGUI::System(mGUIRenderer); 41 102 … … 57 118 void TestCullingApplication::createFrameListener(void) 58 119 { 59 mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer , mShipNode);120 mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer); 60 121 mFrameListener->showDebugOverlay(true); 61 122 mRoot->addFrameListener(mFrameListener); … … 73 134 74 135 //----------------------------------------------------------------------- 75 MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer ,76 SceneNode* shipNode) 77 : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), mShipNode(shipNode)//,mShutdownRequested(false)136 MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer) 137 : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), 138 mShutdownRequested(false) 78 139 { 79 140 80 141 // Setup default variables 81 mCurrentObject = NULL;142 // mCurrentObject = NULL; 82 143 mLMouseDown = false; 83 144 mRMouseDown = false; … … 144 205 CEGUI::MouseCursor::getSingleton().show( ); 145 206 mLMouseDown = false; 146 } // if207 } 147 208 // Right mouse button up 148 209 else if (e->getButtonID() & InputEvent::BUTTON1_MASK) … … 150 211 CEGUI::MouseCursor::getSingleton().show( ); 151 212 mRMouseDown = false; 152 } // else if153 } // mouseReleased213 } 214 } 154 215 //----------------------------------------------------------------------- 155 216 void MouseQueryListener::mouseDragged (MouseEvent *e) 156 217 { 157 // If we are dragging the left mouse button. 158 if ( mLMouseDown ) 159 { 160 mShipNode->translate(-e->getRelX() * 200, -e->getRelY() * 200, 0.0); 161 } // if 162 163 // If we are dragging the right mouse button. 164 else if ( mRMouseDown ) 165 { 166 mCamera->yaw( -e->getRelX() * mRotateSpeed ); 167 mCamera->pitch( -e->getRelY() * mRotateSpeed ); 168 } // else if 169 } // mouseDragged 218 /* 219 // If we are dragging the left mouse button. 220 if ( mLMouseDown ) 221 { 222 mShipNode->translate(-e->getRelX() * 200, -e->getRelY() * 200, 0.0); 223 } 224 */ 225 226 // If we are dragging the right mouse button. 227 if ( mRMouseDown ) 228 { 229 mCamera->yaw( -e->getRelX() * mRotateSpeed ); 230 mCamera->pitch( -e->getRelY() * mRotateSpeed ); 231 } 232 } 233 //----------------------------------------------------------------------- 234 bool MouseQueryListener::frameStarted(const FrameEvent &evt) 235 { 236 // clamp to terrain 237 static Ray updateRay; 238 updateRay.setOrigin(mCamera->getPosition()); 239 updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y); 240 raySceneQuery->setRay(updateRay); 241 RaySceneQueryResult& qryResult = raySceneQuery->execute(); 242 RaySceneQueryResult::iterator i = qryResult.begin(); 243 244 if (i != qryResult.end() && i->worldFragment) 245 { 246 SceneQuery::WorldFragment* wf = i->worldFragment; 247 mCamera->setPosition(mCamera->getPosition().x, 248 i->worldFragment->singleIntersection.y + 10, 249 mCamera->getPosition().z); 250 } 251 252 return ExampleFrameListener::frameStarted(evt); 253 } 170 254 //----------------------------------------------------------------------- 171 255 bool MouseQueryListener::frameEnded(const FrameEvent& evt) … … 252 336 TestCullingApplication app; 253 337 254 try { 338 try 339 { 255 340 app.go(); 256 } catch( Ogre::Exception& e ) { 341 } 342 catch( Ogre::Exception& e ) 343 { 257 344 MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); 258 345 }
Note: See TracChangeset
for help on using the changeset viewer.