Changeset 100 for trunk/VUT/work
- Timestamp:
- 05/16/05 20:22:32 (20 years ago)
- Location:
- trunk/VUT/work
- Files:
-
- 4 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/work/TestCulling/TestCullingApplication.cpp
r99 r100 292 292 mShowVisualization = !mShowVisualization; 293 293 294 mSceneMgr->setOption(" CullCamera", &mShowVisualization);294 mSceneMgr->setOption("ShowVisualization", &mShowVisualization); 295 295 } 296 296 //----------------------------------------------------------------------- -
trunk/VUT/work/TestCulling/TestCullingApplication.h
r99 r100 97 97 bool mShowVisualization; 98 98 99 Camera *mVi sualizationCamera;99 Camera *mVizCamera; 100 100 }; 101 101 -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj
r83 r100 72 72 <Tool 73 73 Name="VCCLCompilerTool" 74 AdditionalIncludeDirectories=""$(OGRE_PATH)\Dependencies\include";"$(OGRE_PATH)\OgreMain\include";"$(OGRE_PATH)\Samples\Common\include";"$(OGRE_PATH)\Dependencies\include\CEGUI";"$(OGRE_PATH)\ PlugIns\OctreeSceneManager\include";"$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\include";"$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include";..\..\GtpVisibility\include;..\include;..\TestCulling"74 AdditionalIncludeDirectories=""$(OGRE_PATH)\Dependencies\include";"$(OGRE_PATH)\OgreMain\include";"$(OGRE_PATH)\Samples\Common\include";"$(OGRE_PATH)\Dependencies\include\CEGUI";"$(OGRE_PATH)\ReferenceApplication\ReferenceAppLayer\include";"$(OGRE_PATH)\PlugIns\OctreeSceneManager\include";"$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\include";"$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include";..\..\GtpVisibility\include;..\include;..\TestCulling" 75 75 PreprocessorDefinitions="_WINDOWS;_STLP_USE_DYNAMIC_LIB;OGRE_LIBRARY_IMPORTS;_RELEASE;WIN32;_STLP_RELEASE;GTP_VISIBILITY_MODIFIED_OGRE" 76 76 RuntimeLibrary="2" -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
r99 r100 13 13 #include <OgreMemoryMacros.h> 14 14 15 #include "Ogre.h" 15 #include <Ogre.h> 16 #include "OgreReferenceAppLayer.h" 17 //#include "OgreRefAppWorld.h" 16 18 #include "TestCullingTerrainApplication.h" 17 19 … … 19 21 #include <windows.h> 20 22 23 #define VIZ_VIEWPORT_Z_ORDER 10 21 24 22 25 /*******************************************************/ 23 26 /* TestCullingTerrainApplication implementation */ 24 27 /*******************************************************/ 28 29 //----------------------------------------------------------------------- 25 30 TestCullingTerrainApplication::~TestCullingTerrainApplication() 26 31 { … … 33 38 { 34 39 // create the camera 35 mCamera = mSceneMgr->createCamera("PlayerCam"); 36 37 // set a nice viewpoint 38 mCamera->setPosition(707, 2500, 528); 39 mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); 40 41 //--create visualization camera 42 mVisualizationCamera = mSceneMgr->createCamera("VizCam"); 43 mVisualizationCamera->setPosition(mCamera->getPosition()); 44 mVisualizationCamera->setOrientation(mCamera->getOrientation()); 45 46 mVisualizationCamera->setNearClipDistance(1); 40 mCamera = mSceneMgr->createCamera("CullCamera"); 41 42 /** set a nice viewpoint 43 * we use a camera node here and apply all transformations on it instead 44 * of applying all transformations directly to the camera 45 * because then the camera is displayed correctly in the visualization 46 */ 47 48 mCamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( 49 "CamNode1", Vector3(707, 5000, 528)); 50 //mCamera->setPosition(707, 5000, 528); 51 mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); 52 53 mCamNode->attachObject(mCamera); 54 55 //-- create visualization camera 56 mVizCamera = mSceneMgr->createCamera("VizCam"); 57 mVizCamera->setPosition(mCamNode->getPosition()); 58 59 mVizCamera->setNearClipDistance(1); 47 60 mCamera->setNearClipDistance(1); 48 61 … … 50 63 if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE)) 51 64 { 52 mVi sualizationCamera->setFarClipDistance(0);65 mVizCamera->setFarClipDistance(0); 53 66 mCamera->setFarClipDistance(0); 54 67 } 55 68 else 56 69 { 57 mVi sualizationCamera->setFarClipDistance(1000);70 mVizCamera->setFarClipDistance(1000); 58 71 mCamera->setFarClipDistance(1000); 59 72 } … … 84 97 // Accept default settings: point light, white diffuse, just set position 85 98 // NB I could attach the light to a SceneNode if I wanted it to move automatically with 86 // 99 // other objects, but I don't 87 100 l->setPosition(20,80,50); 88 101 … … 95 108 96 109 // Create a skybox 97 mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 3500, false);110 mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 7000, false); 98 111 //mSceneMgr->setSkyDome( true, "Examples/CloudySky", 5, 8, 500, false ); 99 112 … … 104 117 mSceneMgr->setWorldGeometry(terrain_cfg); 105 118 106 // CEGUI setup119 //-- CEGUI setup 107 120 setupGui(); 121 122 //-- terrain content setup 123 108 124 // HACK: necessary to call once before the content creation for 109 125 // terrain initialisation … … 138 154 { 139 155 mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, 140 mGUIRenderer, mTerrainContentGenerator, mVi sualizationCamera);156 mGUIRenderer, mTerrainContentGenerator, mVizCamera, mCamNode); 141 157 mFrameListener->showDebugOverlay(true); 142 158 mRoot->addFrameListener(mFrameListener); … … 155 171 CEGUI::Renderer *renderer, 156 172 TerrainContentGenerator *sceneGenerator, 157 Camera *vizCamera): 173 Camera *vizCamera, 174 SceneNode *camNode): 158 175 ExampleFrameListener(win, cam, false, true), 159 176 mGUIRenderer(renderer), … … 169 186 mUseVisibilityCulling(true), 170 187 mUseOptimization(true), 171 mVisualizationCamera(vizCamera) 188 mVizCamera(vizCamera), 189 mShowVisualization(false), 190 mVizCameraHeight(Real(2500.0)), 191 mCamNode(camNode), 192 mCullCamera(true) 172 193 { 173 194 // Reduce move speed … … 213 234 mSceneMgr->setOption("UseVisibilityCulling", &mUseVisibilityCulling); 214 235 mSceneMgr->setOption("ShowOctree", &mShowOctree); 236 mSceneMgr->setOption("CullCamera", &mCullCamera); 215 237 216 238 pOver->show(); 217 239 } 218 240 //----------------------------------------------------------------------- 219 MouseQueryListener::~MouseQueryListener( 241 MouseQueryListener::~MouseQueryListener() 220 242 { 221 243 delete mRayQueryExecutor; 222 244 } 223 245 //----------------------------------------------------------------------- 224 void MouseQueryListener::mouseMoved 246 void MouseQueryListener::mouseMoved(MouseEvent *e) 225 247 { 226 248 // Update CEGUI with the mouse motion 227 CEGUI::System::getSingleton().injectMouseMove(e->getRelX() * mGUIRenderer->getWidth(),228 e->getRelY() * mGUIRenderer->getHeight());249 CEGUI::System::getSingleton().injectMouseMove(e->getRelX() * 250 mGUIRenderer->getWidth(), e->getRelY() * mGUIRenderer->getHeight()); 229 251 } 230 252 //----------------------------------------------------------------------- … … 252 274 CEGUI::MouseCursor::getSingleton().hide(); 253 275 mRMouseDown = true; 254 } // else if276 } 255 277 } // mousePressed 256 278 //----------------------------------------------------------------------- … … 279 301 Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY()); 280 302 281 if (mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay))303 if (mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay)) 282 304 { 283 if(mCurrentObject) 305 if (mCurrentObject) 306 { 284 307 mCurrentObject->setPosition(queryResult); 308 } 285 309 } 286 310 } … … 288 312 if (mRMouseDown) 289 313 { 290 mCamera->yaw( -e->getRelX() * mRotateSpeed ); 291 mCamera->pitch( -e->getRelY() * mRotateSpeed ); 314 //mCamera->yaw(-e->getRelX() * mRotateSpeed); 315 //mCamera->pitch(-e->getRelY() * mRotateSpeed); 316 mCamNode->yaw(-e->getRelX() * mRotateSpeed); 317 mCamNode->pitch(-e->getRelY() * mRotateSpeed); 292 318 } 293 319 } … … 295 321 bool MouseQueryListener::frameStarted(const FrameEvent &evt) 296 322 { 297 clamp2Terrain(mCamera); 298 clamp2Terrain(mVisualizationCamera); 323 clamp2Terrain(); 324 325 if (mShowVisualization) 326 { 327 // important for visualization => draw octree bounding boxes 328 mSceneMgr->setOption("ShowOctree", &mShowVisualization); 329 330 // -- setup visualization camera 331 mVizCamera->setPosition(0, 0, 0); 332 mVizCamera->setOrientation(Quaternion::IDENTITY); 333 334 Vector3 camPos = mCamNode->getPosition(); 335 mVizCamera->setPosition(camPos.x, mVizCameraHeight, camPos.z); 336 337 // Point down -Z axis 338 mVizCamera->pitch(Radian(Degree(270.0))); 339 340 // Rotation arounnd X axis 341 mVizCamera->yaw(Math::ATan2(-mCamera->getDerivedDirection().x, 342 -mCamera->getDerivedDirection().z)); 343 } 299 344 300 345 return ExampleFrameListener::frameStarted(evt); 301 346 } 302 void MouseQueryListener::clamp2Terrain(Camera *cam) 347 //----------------------------------------------------------------------- 348 void MouseQueryListener::clamp2Terrain() 303 349 { 304 350 // clamp to terrain 305 Vector3 camPos = cam->getPosition();351 Vector3 camPos = mCamNode->getPosition(); 306 352 Vector3 queryResult; 307 353 308 if (mRayQueryExecutor->executeRayQuery(&queryResult,354 if (mRayQueryExecutor->executeRayQuery(&queryResult, 309 355 Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y)) 310 356 { 311 cam->setPosition(cam->getPosition().x, queryResult.y + 10, 312 cam->getPosition().z); 357 mCamNode->setPosition(camPos.x, queryResult.y + 10, camPos.z); 313 358 } 314 359 } … … 324 369 KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm()); 325 370 326 KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));327 KEY_PRESSED(KC_ADD, 0, changeThreshold(10));328 371 KEY_PRESSED(KC_O, 0.3, toggleUseOptimization()); 329 KEY_PRESSED(KC_ Y, 0.3, toggleShowOctree());372 KEY_PRESSED(KC_E, 0.3, toggleShowOctree()); 330 373 KEY_PRESSED(KC_C, 0.3, toggleUseVisibilityCulling()); 331 374 KEY_PRESSED(KC_V, 0.3, toggleShowViz()); 332 KEY_PRESSED(KC_X, 0.3, FixVizCamera()); 375 376 if (!mShowVisualization) 377 { 378 KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10)); 379 KEY_PRESSED(KC_ADD, 0, changeThreshold(10)); 380 } 381 else 382 { 383 KEY_PRESSED(KC_SUBTRACT, 0, zoomVizCamera(50)); 384 KEY_PRESSED(KC_ADD, 0, zoomVizCamera(-50)); 385 } 333 386 334 387 updateStats(); 335 //if(mWindow->getViewport(1)) mWindow->getViewport(1)->update(); 336 337 return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt); 388 389 return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt); 390 } 391 void MouseQueryListener::moveCamera() 392 { 393 mCamNode->yaw(mRotX); 394 mCamNode->pitch(mRotY); 395 mCamNode->translate(mCamNode->getLocalAxes(), mTranslateVector); 338 396 } 339 397 //----------------------------------------------------------------------- … … 349 407 } 350 408 //----------------------------------------------------------------------- 409 bool MouseQueryListener::processUnbufferedKeyInput(const FrameEvent& evt) 410 { 411 if (mInputDevice->isKeyDown(KC_RIGHT)) 412 { 413 mCamNode->yaw(-mRotScale); 414 return true; 415 } 416 if (mInputDevice->isKeyDown(KC_LEFT)) 417 { 418 mCamNode->yaw(mRotScale); 419 return true; 420 } 421 422 return ExampleFrameListener::processUnbufferedKeyInput(evt); 423 } 424 //----------------------------------------------------------------------- 425 void MouseQueryListener::zoomVizCamera(int zoom) 426 { 427 mVizCameraHeight += zoom; 428 if(mVizCameraHeight < 0) mVizCameraHeight = 0; 429 } 430 //----------------------------------------------------------------------- 351 431 void MouseQueryListener::nextAlgorithm() 352 432 { … … 396 476 mSceneMgr->setOption("UseOptimization", &mUseOptimization); 397 477 398 if (mUseOptimization)478 if (mUseOptimization) 399 479 mUseOptimizationInfo->setCaption(": true"); 400 480 else … … 420 500 mShowVisualization = !mShowVisualization; 421 501 422 // create viewport with priority 10: will be rendered over standard viewport 423 if(mShowVisualization) 502 // create viewport with priority VIZ_VIEWPORT_Z_ORDER: 503 // will be rendered over standard viewport 504 if (mShowVisualization) 424 505 { 425 mWindow->addViewport(mVisualizationCamera, 10, 0.5, 0.5, 1, 1); 426 mWindow->getViewport(1)->setClearEveryFrame(true); 506 Viewport *vizvp = mWindow->addViewport(mVizCamera, 507 VIZ_VIEWPORT_Z_ORDER, 0.6, 0, 0.4, 0.4); 508 509 vizvp->setBackgroundColour(ColourValue(0.0, 0.3, 0.2, 1)); 510 511 vizvp->setOverlaysEnabled(false); 512 // Alter the camera aspect ratio to match the viewport 513 mVizCamera->setAspectRatio(Real(vizvp->getActualWidth()) / 514 Real(vizvp->getActualHeight())); 515 516 //vizvp->setClearEveryFrame(false); 517 518 // Create a skyplane (for visualization) 519 /*Plane plane; 520 plane.d = 1000; 521 plane.normal = Vector3::UNIT_Y; 522 mSceneMgr->setSkyPlane( true, plane, "Examples/MyTransparentTest", 4000, 75, true);*/ 523 427 524 } 428 525 else 429 526 { 430 mWindow->removeViewport(10); 431 } 432 } 433 //----------------------------------------------------------------------- 434 void MouseQueryListener::FixVizCamera() 435 { 436 mVisualizationCamera->setPosition(mCamera->getPosition()); 437 mVisualizationCamera->setOrientation(mCamera->getOrientation()); 438 clamp2Terrain(mVisualizationCamera); 439 } 440 527 mWindow->removeViewport(VIZ_VIEWPORT_Z_ORDER); 528 // if octree was enabled for visualization purpose 529 mSceneMgr->setOption("ShowOctree", &mShowOctree); 530 } 531 } 441 532 //----------------------------------------------------------------------- 442 533 void MouseQueryListener::keyPressed(KeyEvent* e) … … 475 566 void VisualizationRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt) 476 567 { 477 const bool b = evt.source->getZOrder() == 10; // visualization viewport 478 479 mSceneMgr->setOption("ShowVisualization", &b); 568 const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER; // visualization viewport 569 const bool nShowViz = !showViz; 570 571 mSceneMgr->setOption("ShowVisualization", &showViz); 572 mSceneMgr->setOption("SkyBoxEnabled", &nShowViz); 573 //mSceneMgr->setOption("SkyPlaneEnabled", &showViz); 480 574 481 575 RenderTargetListener::preViewportUpdate(evt); -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
r99 r100 8 8 #include "VisibilityEnvironment.h" 9 9 #include <OgreRenderTargetListener.h> 10 10 11 11 12 Real timeDelay = 0; … … 43 44 44 45 MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 45 CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera); 46 CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera, 47 SceneNode *camNode); 46 48 47 49 ~MouseQueryListener(); … … 49 51 bool frameStarted(const FrameEvent& evt); 50 52 bool frameEnded(const FrameEvent& evt); 53 bool processUnbufferedKeyInput(const FrameEvent& evt); 54 51 55 52 56 /* MouseListener callbacks. */ … … 80 84 void toggleUseVisibilityCulling(); 81 85 void toggleShowViz(); 82 void FixVizCamera(); 86 void zoomVizCamera(int zoom); 87 void moveCamera(); 83 88 84 89 protected: 85 void clamp2Terrain( Camera *cam);90 void clamp2Terrain(); 86 91 87 92 bool mLMouseDown, mRMouseDown; // True if the mouse buttons are down … … 115 120 bool mUseVisibilityCulling; 116 121 bool mShowVisualization; 122 bool mCullCamera; 117 123 118 Camera *mVisualizationCamera; 124 Real mVizCameraHeight; 125 126 Camera *mVizCamera; 127 SceneNode *mCamNode; 128 119 129 }; 120 130 … … 149 159 TerrainContentGenerator *mTerrainContentGenerator; 150 160 151 Camera *mVisualizationCamera; 161 Camera *mVizCamera; 162 SceneNode *mCamNode; 152 163 VisualizationRenderTargetListener *mRenderTargetListener; 153 164
Note: See TracChangeset
for help on using the changeset viewer.