Changeset 80
- Timestamp:
- 05/03/05 16:59:56 (20 years ago)
- Location:
- trunk/VUT/work/TestCullingTerrain
- Files:
-
- 3 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/work/TestCullingTerrain/SceneContentGenerator.cpp
r77 r80 1 1 /** 2 2 \file 3 TerrainContentGenerator.cpp3 SceneContentGenerator.cpp 4 4 \brief 5 Creates content for the terrain.5 Creates content for a scene. 6 6 */ 7 #include " TerrainContentGenerator.h"7 #include "SceneContentGenerator.h" 8 8 #include <windows.h> 9 /********************************************/ 10 /* TerrainContentGenerator implementation */ 11 /********************************************/ 9 10 namespace Ogre { 11 12 /*******************************************************/ 13 /* SceneContentGenerator implementation */ 14 /*******************************************************/ 15 12 16 //----------------------------------------------------------------------- 13 TerrainContentGenerator::TerrainContentGenerator(SceneManager *sm) 17 SceneContentGenerator::SceneContentGenerator(SceneManager *sm): 18 mSceneMgr(sm), mCount(0), 19 mMinPos(Vector3(-70.0f, -70.0f, 0.0f)), 20 mMaxPos(Vector3(70.0f, 70.0f, 600.0f)), 21 mMinAngle(Vector3(0.0f, 0.0f, 0.0f)), 22 mMaxAngle(Vector3(360, 360, 360)) 14 23 { 15 mSceneMgr = sm;16 mRayQueryExecutor = new RayQueryExecutor(sm);17 18 mMinPos = Vector3(-500.0f, 5000.0f, -500.0f);19 mMaxPos = Vector3(500.0f, 5000.0f, 500.0f);20 21 mMinAngle = 0;22 mMaxAngle = 360;23 24 mCount = 0;25 24 } 26 25 //----------------------------------------------------------------------- 27 TerrainContentGenerator::~TerrainContentGenerator()26 void SceneContentGenerator::GenerateScene(int numObjects, const String &objName) 28 27 { 29 delete mRayQueryExecutor; 30 } 31 //----------------------------------------------------------------------- 32 void TerrainContentGenerator::generateScene(int numObjects, const String &meshName) 33 { 28 // initialise random generator 34 29 srand (time(0)); 35 30 … … 37 32 Vector3 translationRatio; 38 33 39 for(int i=0; i < numObjects; ++i) 34 int currentCount = mCount; 35 int limit = 0; 36 37 //-- create random values between zero and one 38 while ((mCount - currentCount < numObjects) && (limit < 50000)) 40 39 { 41 40 rotationRatio.x = rand() / (float) RAND_MAX; … … 47 46 translationRatio.z = rand() / (float) RAND_MAX; 48 47 49 generateSceneObject(translationRatio, rotationRatio, i, meshName); 48 // Setup the ray scene query 49 Vector3 rotation = mMinAngle + rotationRatio * (mMaxAngle - mMinAngle); 50 Vector3 position = mMinPos + translationRatio * (mMaxPos - mMinPos); 51 52 (void)GenerateSceneObject(position, rotation, objName); 53 ++limit; // just in case: to avoid endless loop 50 54 } 51 55 } 52 56 //----------------------------------------------------------------------- 53 void TerrainContentGenerator::generateSceneObject(const Vector3 &translationRatio,54 const Vector3 &rotation Ratio, const int idx, const String& entName)57 SceneNode *SceneContentGenerator::GenerateSceneObject(const Vector3 &position, 58 const Vector3 &rotation, const String& objName) 55 59 { 56 // Setup the ray scene query 57 Real rotation = mMinAngle + rotationRatio.x * (mMaxAngle - mMinAngle); 58 Vector3 position = mMinPos + translationRatio * (mMaxPos - mMinPos); 60 char name[25]; 61 sprintf(name, "Entity%d", mCount++); 62 63 Entity *ent = mSceneMgr->createEntity(name, objName); 64 65 SceneNode *currentObject = mSceneMgr->getRootSceneNode()-> 66 createChildSceneNode(String(name) + "Node", position); 59 67 60 Vector3 queryResult; 68 currentObject->attachObject(ent); 69 currentObject->setScale(0.1f, 0.1f, 0.1f); 70 71 currentObject->yaw(Degree(rotation.x)); 72 currentObject->pitch(Degree(rotation.y)); 73 currentObject->roll(Degree(rotation.z)); 61 74 75 return currentObject; 76 77 /* 62 78 char msg[100]; 63 sprintf(msg, "pos: %3.3f %3.3f %3.3f\n", position.x, position.y, position.z); 79 sprintf(msg, "pos: %3.3f %3.3f %3.3f, newpos: %3.3f %3.3f %3.3f\n", 80 position.x, position.y, position.z, queryResult.x, queryResult.y, queryResult.z); 64 81 65 if (mRayQueryExecutor->executeRayQuery(&queryResult, position, Vector3::NEGATIVE_UNIT_Y)) 66 { 67 char name[16]; 68 sprintf(name, "%s%d", entName.c_str(), mCount++); 69 OutputDebugString("Creating new object "); OutputDebugString(msg); 70 71 Entity *ent = mSceneMgr->createEntity(name, entName); 72 SceneNode *currentObject = mSceneMgr->getRootSceneNode()-> 73 createChildSceneNode(String(name) + "Node", queryResult); 74 75 currentObject->attachObject(ent); 76 currentObject->setScale(0.1f, 0.1f, 0.1f); 77 currentObject->setPosition(position); 78 } 79 else 80 { 81 OutputDebugString(msg); 82 } 83 } 84 /****************************************/ 85 /* RayQueryExecutor implementation */ 86 /****************************************/ 87 //----------------------------------------------------------------------- 88 RayQueryExecutor::RayQueryExecutor(SceneManager *sm) 89 { 90 mRaySceneQuery = sm->createRayQuery(Ray()); 82 OutputDebugString(msg); 83 */ 91 84 } 92 85 //----------------------------------------------------------------------- 93 RayQueryExecutor::~RayQueryExecutor()86 void SceneContentGenerator::SetMinAngle(Vector3 minAngle) 94 87 { 95 delete mRaySceneQuery;88 mMinAngle = minAngle; 96 89 } 97 90 //----------------------------------------------------------------------- 98 bool RayQueryExecutor::executeRayQuery(Vector3 *result, const Vector3 &pos, const Vector3 &dir)91 void SceneContentGenerator::SetMaxAngle(Vector3 maxAngle) 99 92 { 100 return executeRayQuery(result, Ray(pos, dir)); 93 mMaxAngle = maxAngle; 94 } 95 //----------------------------------------------------------------------- 96 void SceneContentGenerator::SetMinPos(Vector3 minPos) 97 { 98 mMinPos = minPos; 99 } 100 //----------------------------------------------------------------------- 101 void SceneContentGenerator::SetMaxPos(Vector3 maxPos) 102 { 103 mMaxPos = maxPos; 101 104 } 102 105 103 bool RayQueryExecutor::executeRayQuery(Vector3 *result, const Ray &ray) 104 { 105 mRaySceneQuery->setRay(ray); 106 107 // Perform the scene query 108 RaySceneQueryResult &queryResult = mRaySceneQuery->execute(); 109 RaySceneQueryResult::iterator it = queryResult.begin(); 110 111 if (it != queryResult.end() && it->worldFragment) 112 { 113 SceneQuery::WorldFragment* wf = it->worldFragment; 114 115 *result = wf->singleIntersection; 116 return true; 117 } 118 119 return false; 120 } 106 } // namespace Ogre -
trunk/VUT/work/TestCullingTerrain/SceneContentGenerator.h
r75 r80 1 /** 2 \file 3 TerrainContentGenerator.h 1 #ifndef _SCENECONTENTGENERATOR_H__ 2 #define _SCENECONTENTGENERATOR_H__ 3 4 #include <OgrePrerequisites.h> 5 #include <OgreMath.h> 6 #include <Ogre.h> 7 8 namespace Ogre { 9 10 /** Class which fills a scene with content in a random fashion. 4 11 */ 5 #include "ExampleApplication.h" 6 7 /** Class which executes a simple ray query. 8 */ 9 class RayQueryExecutor 12 class SceneContentGenerator 10 13 { 11 14 public: 12 RayQueryExecutor(SceneManager *sm); 13 ~RayQueryExecutor(); 15 SceneContentGenerator(SceneManager *sm); 14 16 15 bool executeRayQuery(Vector3 *result, const Vector3 &pos, const Vector3 &dir); 16 bool RayQueryExecutor::executeRayQuery( Vector3 *result, const Ray &ray); 17 /** Generates scene object in a random fashion. 18 @param number of objects to generate 19 @param objName the name of the mesh to be generated 20 */ 21 void GenerateScene(int numObjects, const String &objName); 22 /** Generates a new object in the scene using ray scene queries 23 and inserts it into scene hierarchy. 24 @param position position where the object is created 25 @param rotation rotation angle applied locally to object 26 @objName the name of the object entity 27 @returns scene object if it was successfully created, NULL otherwise 28 */ 29 SceneNode *GenerateSceneObject(const Vector3 &position, 30 const Vector3 &rotation, const String &objName); 17 31 18 protected: 19 RaySceneQuery *mRaySceneQuery; 20 }; 21 /** Class which fills a terrain with content in a random way. 22 */ 23 class TerrainContentGenerator 24 { 25 public: 26 TerrainContentGenerator(SceneManager *sm); 27 ~TerrainContentGenerator(); 28 /** Generates a the scene hierarchy with random values . 29 @param number of objects to generate 30 @param the name of the mesh to be generated 31 */ 32 void generateScene(int numObjects, const String &meshName); 33 /** Generates a new scene object 34 @param tranlationRatio ratio between minimal and maximal possible translation 35 @param rotationRatio ratio between minimal and maximal possible rotation 36 @idx the index of the new object 37 @entName the name of the object entity 38 */ 39 void generateSceneObject(const Vector3 &translationRatio, const Vector3 &rotationRatio, 40 const int idx, const String &entName); 41 32 void SetMinAngle(Vector3 minAngle); 33 void SetMaxAngle(Vector3 maxAngle); 34 void SetMinPos(Vector3 minPos); 35 void SetMaxPos(Vector3 maxPos); 36 42 37 protected: 43 38 44 RealmMinAngle;45 RealmMaxAngle;39 Vector3 mMinAngle; 40 Vector3 mMaxAngle; 46 41 Vector3 mMaxPos; 47 42 Vector3 mMinPos; 48 49 RayQueryExecutor *mRayQueryExecutor; 43 50 44 SceneManager *mSceneMgr; 51 45 int mCount; // The number of objects on the screen 52 46 }; 53 47 48 } // namespace Ogre 49 50 #endif // SCENECONTENTGENERATOR_H_ -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj
r74 r80 122 122 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> 123 123 <File 124 RelativePath=".\SceneContentGenerator.cpp"> 125 </File> 126 <File 124 127 RelativePath=".\TerrainContentGenerator.cpp"> 125 128 </File> … … 133 136 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> 134 137 <File 138 RelativePath=".\SceneContentGenerator.h"> 139 </File> 140 <File 135 141 RelativePath=".\TerrainContentGenerator.h"> 136 142 </File> -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
r76 r80 20 20 21 21 22 /************************************************ /23 /* TestCullingTerrainApplication implementation*/24 /************************************************ /22 /*******************************************************/ 23 /* TestCullingTerrainApplication implementation */ 24 /*******************************************************/ 25 25 TestCullingTerrainApplication::~TestCullingTerrainApplication() 26 26 { 27 delete m TerrainContentGenerator;27 delete mSceneContentGenerator; 28 28 } 29 29 //----------------------------------------------------------------------- … … 91 91 // CEGUI setup 92 92 setupGui(); 93 94 mTerrainContentGenerator = new TerrainContentGenerator(mSceneMgr); 95 mTerrainContentGenerator->generateScene(300, "robot.mesh"); 96 } 97 //----------------------------------------------------------------------- 98 void TestCullingTerrainApplication::setupGui( void ) 93 // HACK: necessary to call once before the content creation for 94 // terrain initialisation 95 mSceneMgr->_renderScene(mCamera, mWindow->getViewport(0), true); 96 97 mSceneContentGenerator = new TerrainContentGenerator(mSceneMgr); 98 mSceneContentGenerator->GenerateScene(300, "robot.mesh"); 99 // no limitations now: the user can set objects also on peaks 100 mSceneContentGenerator->SetMaxHeight(5000); 101 } 102 //----------------------------------------------------------------------- 103 void TestCullingTerrainApplication::setupGui() 99 104 { 100 105 mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, … … 111 116 } 112 117 //----------------------------------------------------------------------- 113 void TestCullingTerrainApplication::createFrameListener(void) 114 { 115 mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer); 118 void TestCullingTerrainApplication::createFrameListener() 119 { 120 mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, 121 mGUIRenderer, mSceneContentGenerator); 116 122 mFrameListener->showDebugOverlay(true); 117 123 mRoot->addFrameListener(mFrameListener); 118 124 } 119 125 //----------------------------------------------------------------------- 120 void TestCullingTerrainApplication::chooseSceneManager( void)126 void TestCullingTerrainApplication::chooseSceneManager() 121 127 { 122 128 mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE); 123 129 } 124 125 130 /***********************************************/ 126 /* MouseQueryListener implementation*/131 /* MouseQueryListener implementation */ 127 132 /***********************************************/ 128 133 //----------------------------------------------------------------------- 129 134 MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam, 130 135 SceneManager *sceneManager, 131 CEGUI::Renderer *renderer): 136 CEGUI::Renderer *renderer, 137 TerrainContentGenerator *sceneGenerator): 132 138 ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), 133 139 mShutdownRequested(false) … … 138 144 mRMouseDown = false; 139 145 mSceneMgr = sceneManager; 146 mSceneContentGenerator = sceneGenerator; 140 147 141 148 // Reduce move speed … … 195 202 196 203 // Setup the ray scene query 197 Ray mouseRay = mCamera->getCameraToViewportRay( e->getX(), e->getY());204 Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY()); 198 205 199 206 Vector3 queryResult; 200 // Get results, create a node/entity on the position 201 if(mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay)) 202 { 203 char name[16]; 204 sprintf(name, "Robot%d", mCount++); 205 206 Entity *ent = mSceneMgr->createEntity(name, "robot.mesh"); 207 mCurrentObject = mSceneMgr->getRootSceneNode()-> 208 createChildSceneNode(String(name) + "Node", queryResult); 209 mCurrentObject->attachObject(ent); 210 mCurrentObject->setScale(0.1f, 0.1f, 0.1f); 211 212 } 213 207 208 // Get results, create a node/entity on the position 209 mCurrentObject = mSceneContentGenerator->GenerateSceneObject( 210 mouseRay.getOrigin(), mouseRay.getDirection(), "robot.mesh"); 211 214 212 mLMouseDown = true; 215 213 } … … 249 247 if(mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay)) 250 248 { 251 mCurrentObject->setPosition(queryResult); 249 if(mCurrentObject) 250 mCurrentObject->setPosition(queryResult); 252 251 } 253 252 } -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
r75 r80 30 30 31 31 MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 32 CEGUI::Renderer *renderer );32 CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator); 33 33 34 35 ~MouseQueryListener( ); 34 ~MouseQueryListener(); 36 35 37 36 bool frameStarted(const FrameEvent& evt); … … 87 86 88 87 RayQueryExecutor *mRayQueryExecutor; 88 TerrainContentGenerator *mSceneContentGenerator; 89 89 }; 90 90 … … 111 111 Vector3 mMaxAngle; 112 112 113 TerrainContentGenerator *m TerrainContentGenerator;113 TerrainContentGenerator *mSceneContentGenerator; 114 114 115 115 private:
Note: See TracChangeset
for help on using the changeset viewer.