Ignore:
Timestamp:
04/19/05 09:12:55 (19 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/OcclusionCullingSceneManager/TestCulling
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp

    r44 r51  
    2020#include "windows.h" 
    2121 
    22 //RaySceneQuery* mRaySceneQuery = 0; 
    2322 
    2423/***********************************************/ 
    2524/* TestCullingApplication implementation       */ 
    2625/***********************************************/ 
    27 /*TestCullingApplication::~TestCullingApplication() 
    28 { 
    29         delete mRaySceneQuery; 
    30 }*/ 
    31 //----------------------------------------------------------------------- 
    32 void TestCullingApplication::createCamera( void ) 
     26TestCullingApplication::~TestCullingApplication() 
     27{ 
     28} 
     29//----------------------------------------------------------------------- 
     30/*void TestCullingApplication::createCamera( void ) 
    3331{ 
    3432        // Create the camera 
     
    4240    mCamera->setNearClipDistance( 1 ); 
    4341    mCamera->setFarClipDistance( 1000 ); 
    44 } 
     42}*/ 
    4543//----------------------------------------------------------------------- 
    4644void TestCullingApplication::createScene(void) 
    4745{ 
    48         Plane waterPlane; 
    4946        // Set ambient light 
    5047        mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); 
     
    5249        // Create a light 
    5350        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     //mSceneMgr->setFog( FOG_EXP, fadeColour, 0.005 ); 
    65  
     51        //l->setPosition(20,80,50); 
     52 
     53        mMinTranslation = Vector3(-70.0f, -70.0f, 0.0f); 
     54        mMaxTranslation = Vector3(70.0f, 70.0f, 600.0f); 
     55 
     56        mMinAngle = Vector3(0, 0, 0); 
     57        mMaxAngle = Vector3(360, 360, 360); 
     58 
     59        /* 
    6660        mWindow->getViewport(0)->setBackgroundColour(fadeColour); 
    6761 
     62        Entity *ogreHeadEnt = mSceneMgr->createEntity("head", "ogrehead.mesh"); 
     63        mOgreHead = mSceneMgr->getRootSceneNode()->createChildSceneNode( "OgreHeadNode" ); 
     64        mOgreHead->attachObject(ogreHeadEnt); 
     65        */ 
     66        generateScene(4); 
    6867        // Create a skybox 
    69     //mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 500, false); 
    70         //mSceneMgr->setSkyDome( true, "Examples/CloudySky", 5, 8, 500, false ); 
    71  
    72         std::string terrain_cfg("terrain.cfg"); 
    73 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 
    74         terrain_cfg = mResourcePath + terrain_cfg; 
    75 #endif 
    76         mSceneMgr -> setWorldGeometry( terrain_cfg ); 
    77         // Infinite far plane? 
    78         if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE)) 
    79         { 
    80                 mCamera->setFarClipDistance(0); 
    81         } 
    82  
    83 /*      // Define the required skyplane 
    84         Plane plane; 
    85         // 5000 world units from the camera 
    86         plane.d = 5000; 
    87         // Above the camera, facing down 
    88         plane.normal = -Vector3::UNIT_Y; 
    89         // Create the plane 10000 units wide, tile the texture 3 times 
    90     mSceneMgr->setSkyPlane(true, plane, "Examples/SpaceSkyPlane",10000,3);*/ 
    91  
    92         // Set a nice viewpoint 
    93         mCamera->setPosition(707,2500,528); 
    94         mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); 
    95  
    96         //mRaySceneQuery = mSceneMgr->createRayQuery( 
    97         //      Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y)); 
    98  
    99         /*Entity *robotEnt = mSceneMgr->createEntity( "Robot", "robot.mesh" ); 
    100         SceneNode *robotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "RobotNode", Vector3( 750, 25, 600 )); 
    101         robotNode->attachObject( robotEnt ); 
    102         robotNode->scale( .3, .3, .3 ); 
    103         robotNode->yaw( Degree( 160 ) ); 
    104  
    105         Entity *ogreEnt = mSceneMgr->createEntity( "Ogre", "ogrehead.mesh" ); 
    106     SceneNode *ogreNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Ogre", Vector3( 800, 50, 830 ) ); 
    107     ogreNode->attachObject( ogreEnt ); 
    108         ogreNode->scale(.2,.2,.2); 
    109         ogreNode->yaw( Degree( 20 ) ); 
    110  
    111         Entity *ogreEnt2 = mSceneMgr->createEntity( "Ogre2", "ogrehead.mesh" ); 
    112     SceneNode *ogreNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Ogre2", Vector3( 700, 50, 730 ) ); 
    113     ogreNode2->attachObject( ogreEnt2 ); 
    114         ogreNode2->scale(.05,.05,.05); 
    115         ogreNode->yaw( Degree( 40 ) );*/ 
     68    //mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 1000, false); 
     69    ColourValue fadeColour(0.3, 0.9, 0.5); 
     70        mWindow->getViewport(0)->setBackgroundColour(fadeColour); 
    11671 
    11772        // CEGUI setup 
     
    14297void TestCullingApplication::chooseSceneManager(void) 
    14398{ 
    144     //mSceneMgr = mRoot->getSceneManager(ST_GENERIC); 
    145         mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE); 
    146 } 
    147  
     99    mSceneMgr = mRoot->getSceneManager(ST_GENERIC); 
     100} 
     101//----------------------------------------------------------------------- 
     102void TestCullingApplication::generateSceneObject(const Vector3 &translationRatio,  
     103                                                                                                 const Vector3 &rotationRatio, const int idx, const String& entName) 
     104{ 
     105        Vector3 rotation = mMinAngle + rotationRatio * (mMaxAngle - mMinAngle); 
     106        Vector3 translation = mMinTranslation + translationRatio * (mMaxTranslation - mMinTranslation); 
     107 
     108        char name[16]; 
     109    sprintf( name, "object%d", idx ); 
     110 
     111    Entity *ent = mSceneMgr->createEntity( name, entName ); 
     112        SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode( String(name) + "Node", translation); 
     113        node->attachObject(ent); 
     114        node->scale(0.1,0.1,0.1); 
     115 
     116        node->yaw(Degree(rotation.x)); 
     117    node->pitch(Degree(rotation.y)); 
     118        node->roll(Degree(rotation.z)); 
     119} 
     120//----------------------------------------------------------------------- 
     121void TestCullingApplication::generateScene( int numObjects ) 
     122{ 
     123        srand (time (0)); 
     124         
     125        Vector3 rotationRatio; 
     126        Vector3 translationRatio; 
     127 
     128        for(int i=0; i < numObjects; i++) 
     129        { 
     130                rotationRatio.x = rand() / (float) RAND_MAX; 
     131                rotationRatio.y = rand() / (float) RAND_MAX; 
     132                rotationRatio.z = rand() / (float) RAND_MAX; 
     133 
     134                translationRatio.x = rand() / (float) RAND_MAX; 
     135                translationRatio.y = rand() / (float) RAND_MAX; 
     136                translationRatio.z = rand() / (float) RAND_MAX; 
     137 
     138                generateSceneObject(translationRatio, rotationRatio, i, "sphere.mesh"); 
     139        } 
     140} 
    148141/***********************************************/ 
    149142/* MouseQueryListener implementation           */ 
     
    156149 
    157150        // Setup default variables 
    158         mCurrentObject = NULL; 
     151        //mOgreHead = NULL; 
    159152        mLMouseDown = false; 
    160153        mRMouseDown = false; 
     
    173166        mEventProcessor->addKeyListener(this); 
    174167 
    175         mRaySceneQuery = mSceneMgr->createRayQuery( Ray() ); 
    176  
    177168        // show overlay 
    178169        Overlay* pOver = OverlayManager::getSingleton().getByName("Example/OcclusionCullingDemoOverlay");  
     
    199190MouseQueryListener::~MouseQueryListener( ) 
    200191{ 
    201         delete mRaySceneQuery; 
    202192} 
    203193//----------------------------------------------------------------------- 
     
    213203     if (e->getButtonID() & InputEvent::BUTTON0_MASK) 
    214204     { 
    215                  CEGUI::MouseCursor::getSingleton().hide( ); 
    216  
    217                  // Setup the ray scene query 
    218          Ray mouseRay = mCamera->getCameraToViewportRay( e->getX(), e->getY() ); 
    219          mRaySceneQuery->setRay( mouseRay ); 
    220  
    221          // Execute query 
    222          RaySceneQueryResult &result = mRaySceneQuery->execute(); 
    223          RaySceneQueryResult::iterator itr = result.begin( ); 
    224  
    225          // Get results, create a node/entity on the position 
    226          if ( itr != result.end() && itr->worldFragment ) 
    227          { 
    228                          char name[16]; 
    229              sprintf( name, "Robot%d", mCount++ ); 
    230  
    231              Entity *ent = mSceneMgr->createEntity( name, "robot.mesh" ); 
    232              mCurrentObject = mSceneMgr->getRootSceneNode( )->createChildSceneNode( String(name) + "Node", itr->worldFragment->singleIntersection ); 
    233              mCurrentObject->attachObject( ent ); 
    234              mCurrentObject->setScale( 0.1f, 0.1f, 0.1f ); 
    235          } 
    236  
    237          mLMouseDown = true;  
     205                mLMouseDown = true;  
    238206     } 
    239207     // Right mouse button down 
     
    267235         if ( mLMouseDown ) 
    268236     { 
    269                  Ray mouseRay = mCamera->getCameraToViewportRay( e->getX(), e->getY() ); 
    270                  mRaySceneQuery->setRay( mouseRay ); 
    271  
    272                  RaySceneQueryResult &result = mRaySceneQuery->execute(); 
    273                  RaySceneQueryResult::iterator itr = result.begin( ); 
    274  
    275                  if ( itr != result.end() && itr->worldFragment ) 
    276                  { 
    277                          mCurrentObject->setPosition( itr->worldFragment->singleIntersection ); 
    278                  }  
     237                 
    279238     } 
    280239         // If we are dragging the right mouse button. 
     
    287246//----------------------------------------------------------------------- 
    288247bool MouseQueryListener::frameStarted(const FrameEvent &evt) 
    289 { 
    290         // clamp to terrain 
    291         Vector3 camPos = mCamera->getPosition( ); 
    292     Ray cameraRay( Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y ); 
    293     mRaySceneQuery->setRay( cameraRay ); 
    294  
    295     // Perform the scene query 
    296     RaySceneQueryResult &queryResult = mRaySceneQuery->execute(); 
    297     RaySceneQueryResult::iterator it = queryResult.begin( ); 
    298  
    299         if (it != queryResult.end() && it->worldFragment) 
    300         { 
    301                 SceneQuery::WorldFragment* wf = it->worldFragment; 
    302  
    303                 mCamera->setPosition(mCamera->getPosition().x, wf->singleIntersection.y + 10,  
    304                         mCamera->getPosition().z); 
    305         } 
    306           
     248{         
    307249        return ExampleFrameListener::frameStarted(evt); 
    308250} 
  • trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h

    r44 r51  
    7979        OverlayElement *mHierarchyNodesInfo; 
    8080        OverlayElement *mSceneNodesInfo; 
    81  
    82         SceneNode *mCurrentObject;         // The newly created object 
    83         int mCount;                        // The number of robots on the screen 
    84         RaySceneQuery *mRaySceneQuery;     // The ray scene query pointer 
    8581}; 
    8682 
     
    9591        void createFrameListener(void); 
    9692        void setupGui(void); 
    97         virtual void createCamera(void); 
     93        /** generates a the scene hierarchy with random values  
     94        @param number of objects to generate 
     95        */ 
     96        void generateScene(int numObjects); 
     97 
     98        /** generates a new scene object  
     99        @param tranlationRatio ratio between minimal and maximal possible translation 
     100        @param rotationRatio ratio between minimal and maximal possible rotation 
     101        @idx the index of the new object 
     102        @entName the name of the object entity 
     103        */ 
     104        void generateSceneObject(const Vector3 &translationRatio, const Vector3 &rotationRatio,  
     105                                                         const int idx, const String &entName); 
     106 
     107        //virtual void createCamera(void); 
    98108 
    99109        CEGUI::OgreCEGUIRenderer *mGUIRenderer; 
    100110        CEGUI::System *mGUISystem; 
     111 
     112        Vector3 mMinTranslation; 
     113        Vector3 mMaxTranslation; 
     114 
     115        Vector3 mMinAngle; 
     116        Vector3 mMaxAngle; 
    101117 
    102118private: 
Note: See TracChangeset for help on using the changeset viewer.