Changeset 55 for trunk/VUT/OcclusionCullingSceneManager
- Timestamp:
- 04/21/05 19:33:56 (20 years ago)
- Location:
- trunk/VUT/OcclusionCullingSceneManager
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h
r52 r55 6 6 #include "ExampleApplication.h" 7 7 #include "OgreOcclusionCullingSceneTraverser.h" 8 8 9 9 10 Real timeDelay = 0; … … 28 29 public: 29 30 30 MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer); 31 MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 32 CEGUI::Renderer *renderer); 31 33 32 34 -
trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.cpp
r47 r55 5 5 Creates content for the terrain, 6 6 */ 7 8 7 #include "TerrainContentGenerator.h" 9 8 10 9 //----------------------------------------------------------------------- 11 TerrainContentGenerator::TerrainContentGenerator( void)10 TerrainContentGenerator::TerrainContentGenerator( SceneManager *sm, RayQueryExecutor *rayQueryEx ) 12 11 { 12 mSceneMgr = sm; 13 mRayQueryExecutor = rayQueryEx; 14 15 mMinTranslation = Vector3(-70.0f, -70.0f, 0.0f); 16 mMaxTranslation = Vector3(70.0f, 70.0f, 600.0f); 17 18 mMinAngle = 0; 19 mMaxAngle = 360; 20 21 mCount = 0; 13 22 } 23 //----------------------------------------------------------------------- 24 void TerrainContentGenerator::generateScene( int numObjects ) 25 { 26 srand (time (0)); 27 28 Vector3 rotationRatio; 29 Vector3 translationRatio; 14 30 31 for(int i=0; i < numObjects; i++) 32 { 33 rotationRatio.x = rand() / (float) RAND_MAX; 34 rotationRatio.y = rand() / (float) RAND_MAX; 35 rotationRatio.z = rand() / (float) RAND_MAX; 36 37 translationRatio.x = rand() / (float) RAND_MAX; 38 translationRatio.y = rand() / (float) RAND_MAX; 39 translationRatio.z = rand() / (float) RAND_MAX; 40 41 generateSceneObject(translationRatio, rotationRatio, i, "sphere.mesh"); 42 } 43 } 44 //----------------------------------------------------------------------- 45 void TerrainContentGenerator::generateSceneObject(const Vector3 &translationRatio, 46 const Vector3 &rotationRatio, const int idx, const String& entName) 47 { 48 // Setup the ray scene query 49 Real rotation = mMinAngle + rotationRatio.x * (mMaxAngle - mMinAngle); 50 Vector3 translation = mMinTranslation + translationRatio * (mMaxTranslation - mMinTranslation); 51 52 translation.y = 5000; 53 54 Vector3 queryResult; 55 56 if(mRayQueryExecutor->executeRayQuery(&queryResult, translation, Vector3::NEGATIVE_UNIT_Y)) 57 { 58 char name[16]; 59 sprintf( name, "%s%d", entName.c_str(), mCount++); 60 61 Entity *ent = mSceneMgr->createEntity(name, entName); 62 SceneNode *currentObject = mSceneMgr->getRootSceneNode( )->createChildSceneNode( String(name) + "Node", queryResult); 63 currentObject->attachObject(ent); 64 currentObject->setScale(0.1f, 0.1f, 0.1f); 65 } 66 } 67 //----------------------------------------------------------------------- 68 RayQueryExecutor::RayQueryExecutor( SceneManager *sm ) 69 { 70 mRaySceneQuery = sm->createRayQuery(Ray()); 71 } 72 //----------------------------------------------------------------------- 73 RayQueryExecutor::~RayQueryExecutor() 74 { 75 delete mRaySceneQuery; 76 } 77 //----------------------------------------------------------------------- 78 bool RayQueryExecutor::executeRayQuery( Vector3 *result, const Vector3 &pos, const Vector3 &dir ) 79 { 80 Ray ray(pos, dir); 81 mRaySceneQuery->setRay(ray); 82 83 // Perform the scene query 84 RaySceneQueryResult &queryResult = mRaySceneQuery->execute(); 85 RaySceneQueryResult::iterator it = queryResult.begin( ); 86 87 if (it != queryResult.end() && it->worldFragment) 88 { 89 SceneQuery::WorldFragment* wf = it->worldFragment; 90 91 *result = wf->singleIntersection; 92 return true; 93 } 94 95 return false; 96 } -
trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.h
r47 r55 3 3 TerrainContentGenerator.h 4 4 */ 5 #include "ExampleApplication.h" 6 7 class RayQueryExecutor 8 { 9 public: 10 RayQueryExecutor( SceneManager *sm ); 11 ~RayQueryExecutor( ); 12 bool executeRayQuery( Vector3 *result, const Vector3 &pos, const Vector3 &dir ); 13 protected: 14 RaySceneQuery *mRaySceneQuery; 15 }; 5 16 6 17 class TerrainContentGenerator 7 18 { 8 19 public: 9 TerrainContentGenerator(); 20 TerrainContentGenerator( SceneManager *sm, RayQueryExecutor *rayQueryEx ); 21 /** generates a the scene hierarchy with random values 22 @param number of objects to generate 23 */ 24 void generateScene( int numObjects ); 25 /** 26 generates a new scene object 27 @param tranlationRatio ratio between minimal and maximal possible translation 28 @param rotationRatio ratio between minimal and maximal possible rotation 29 @idx the index of the new object 30 @entName the name of the object entity 31 */ 32 void generateSceneObject( const Vector3 &translationRatio, const Vector3 &rotationRatio, 33 const int idx, const String &entName ); 10 34 11 35 protected: 12 36 37 Real mMinAngle; 38 Real mMaxAngle; 39 Vector3 mMaxTranslation; 40 Vector3 mMinTranslation; 41 42 RayQueryExecutor *mRayQueryExecutor; 43 SceneManager *mSceneMgr; 44 int mCount; // The number of objects on the screen 13 45 }; 14 46 -
trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.cpp
r52 r55 20 20 #include "windows.h" 21 21 22 //RaySceneQuery* mRaySceneQuery = 0; 23 24 /***********************************************/ 25 /* TestCullingTerrainApplication implementation */ 26 /***********************************************/ 27 /*TestCullingTerrainApplication::~TestCullingTerrainApplication() 28 { 29 delete mRaySceneQuery; 30 }*/ 22 23 /************************************************/ 24 /* TestCullingTerrainApplication implementation */ 25 /************************************************/ 26 TestCullingTerrainApplication::~TestCullingTerrainApplication() 27 { 28 delete mRayQueryExecutor; 29 delete mTerrainContentGenerator; 30 } 31 31 32 //----------------------------------------------------------------------- 32 33 void TestCullingTerrainApplication::createCamera( void ) … … 40 41 // Look back along -Z 41 42 mCamera->lookAt(Vector3(0,0,-300)); 42 mCamera->setNearClipDistance( 1 ); 43 mCamera->setFarClipDistance( 1000 ); 44 } 45 //----------------------------------------------------------------------- 46 void TestCullingTerrainApplication::createScene(void) 47 { 43 mCamera->setNearClipDistance(1); 44 mCamera->setFarClipDistance(1000); 45 } 46 //----------------------------------------------------------------------- 47 void TestCullingTerrainApplication::generateSceneObject(const Vector3 &translationRatio, 48 const Vector3 &rotationRatio, const int idx, const String& entName) 49 { 50 // Setup the ray scene query 51 /*Vector3 rotation = mMinAngle + rotationRatio * (mMaxAngle - mMinAngle); 52 Vector3 translation = mMinTranslation + translationRatio * (mMaxTranslation - mMinTranslation); 53 54 translation.y = 5000; 55 Ray ray(translation, Vector3::NEGATIVE_UNIT_Y); 56 mRaySceneQuery->setRay(ray); 57 58 // Execute query 59 RaySceneQueryResult &result = mRaySceneQuery->execute(); 60 RaySceneQueryResult::iterator itr = result.begin( ); 61 62 // Get results, create a node/entity on the position 63 if ( itr != result.end() && itr->worldFragment ) 64 { 65 char name[16]; 66 sprintf( name, "%s%d", entName.c_str(), mCount++ ); 67 68 Entity *ent = mSceneMgr->createEntity( name, entName ); 69 SceneNode currentObject = mSceneMgr->getRootSceneNode( )->createChildSceneNode( String(name) + "Node", itr->worldFragment->singleIntersection ); 70 currentObject->attachObject( ent ); 71 currentObject->setScale( 0.1f, 0.1f, 0.1f ); 72 }*/ 73 } 74 75 //----------------------------------------------------------------------- 76 void TestCullingTerrainApplication::createScene( void ) 77 { 78 mRayQueryExecutor = new RayQueryExecutor(mSceneMgr); 79 mTerrainContentGenerator = new TerrainContentGenerator(mSceneMgr, mRayQueryExecutor); 48 80 // Set ambient light 49 81 mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); … … 62 94 mWindow->getViewport(0)->setBackgroundColour(fadeColour); 63 95 //mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000); 64 //mSceneMgr->setFog( FOG_EXP, fadeColour, 0.005 );65 66 67 96 68 97 // Create a skybox … … 94 123 mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); 95 124 96 /*97 Entity *robotEnt = mSceneMgr->createEntity( "Robot", "robot.mesh" );98 SceneNode *robotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "RobotNode", Vector3( 750, 25, 600 ));99 robotNode->attachObject( robotEnt );100 robotNode->scale( .3, .3, .3 );101 robotNode->yaw( Degree( 160 ) );102 103 Entity *ogreEnt = mSceneMgr->createEntity( "Ogre", "ogrehead.mesh" );104 SceneNode *ogreNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Ogre", Vector3( 800, 50, 830 ) );105 ogreNode->attachObject( ogreEnt );106 ogreNode->scale(.2,.2,.2);107 ogreNode->yaw( Degree( 20 ) );108 109 Entity *ogreEnt2 = mSceneMgr->createEntity( "Ogre2", "ogrehead.mesh" );110 SceneNode *ogreNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Ogre2", Vector3( 700, 50, 730 ) );111 ogreNode2->attachObject( ogreEnt2 );112 ogreNode2->scale(.05,.05,.05);113 ogreNode->yaw( Degree( 40 ) );*/114 115 125 // CEGUI setup 116 126 setupGui(); … … 133 143 void TestCullingTerrainApplication::createFrameListener(void) 134 144 { 135 mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer );145 mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer, mRayQueryExecutor); 136 146 mFrameListener->showDebugOverlay(true); 137 147 mRoot->addFrameListener(mFrameListener); … … 148 158 /***********************************************/ 149 159 //----------------------------------------------------------------------- 150 MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer) 151 : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), 152 mShutdownRequested(false) 160 MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer, RayQueryExecutor *rqe) 161 : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), mShutdownRequested(false), mRayQueryExecutor(rqe) 153 162 { 154 163 … … 171 180 mEventProcessor->addKeyListener(this); 172 181 173 mRaySceneQuery = mSceneMgr->createRayQuery( Ray());182 mRaySceneQuery = mSceneMgr->createRayQuery(Ray()); 174 183 175 184 // show overlay -
trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.h
r52 r55 6 6 #include "ExampleApplication.h" 7 7 #include "OgreOcclusionCullingSceneTraverser.h" 8 #include "TerrainContentGenerator.h" 8 9 9 10 Real timeDelay = 0; … … 28 29 public: 29 30 30 MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer); 31 MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 32 CEGUI::Renderer *renderer, RayQueryExecutor *rqe); 31 33 32 34 … … 82 84 83 85 SceneNode *mCurrentObject; // The newly created object 86 RaySceneQuery *mRaySceneQuery; // The ray scene query pointer 84 87 int mCount; // The number of robots on the screen 85 RaySceneQuery *mRaySceneQuery; // The ray scene query pointer 88 89 RayQueryExecutor *mRayQueryExecutor; 86 90 }; 87 91 … … 90 94 { 91 95 public: 92 //~TestCullingTerrainApplication();96 ~TestCullingTerrainApplication(); 93 97 94 98 protected: … … 98 102 virtual void createCamera(void); 99 103 104 /** 105 generates a new scene object 106 @param tranlationRatio ratio between minimal and maximal possible translation 107 @param rotationRatio ratio between minimal and maximal possible rotation 108 @idx the index of the new object 109 @entName the name of the object entity 110 */ 111 void generateSceneObject(const Vector3 &translationRatio, const Vector3 &rotationRatio, 112 const int idx, const String &entName); 113 100 114 CEGUI::OgreCEGUIRenderer *mGUIRenderer; 101 115 CEGUI::System *mGUISystem; 116 RayQueryExecutor *mRayQueryExecutor; 117 TerrainContentGenerator *mTerrainContentGenerator; 118 119 Vector3 mMinTranslation; 120 Vector3 mMaxTranslation; 121 122 Vector3 mMinAngle; 123 Vector3 mMaxAngle; 102 124 103 125 private: -
trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneTraverser.cpp
r54 r55 114 114 else 115 115 { 116 /*117 char msg2[100];118 Vector3 min = box.getMinimum();119 Vector3 max = box.getMaximum();120 121 sprintf(msg2, "culling box: %3.3f %3.3f %3.3f %3.3f %3.3f %3.3f\n", min.x, min.y, min.z, max.x, max.y, max.z);122 OutputDebugString(msg2);123 */124 125 116 mNumQueryCulledNodes ++; 126 117 } -
trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp
r54 r55 16 16 new OcclusionCullingOctreeSceneTraverser(this, mDestRenderSystem); 17 17 18 mShowBoxes = true;18 //mShowBoxes = true; 19 19 //mDisplayNodes = true; 20 mShowBoundingBoxes = true;20 //mShowBoundingBoxes = true; 21 21 mMaxDepth = 20; 22 22 }
Note: See TracChangeset
for help on using the changeset viewer.