[Orxonox-commit 337] r2956 - in branches/map/src/orxonox: objects objects/worldentities/pawns overlays/map

Naaduun at orxonox.net Naaduun at orxonox.net
Thu May 7 16:44:13 CEST 2009


Author: Naaduun
Date: 2009-05-07 16:44:12 +0200 (Thu, 07 May 2009)
New Revision: 2956

Modified:
   branches/map/src/orxonox/objects/RadarViewable.cc
   branches/map/src/orxonox/objects/RadarViewable.h
   branches/map/src/orxonox/objects/worldentities/pawns/Pawn.cc
   branches/map/src/orxonox/objects/worldentities/pawns/Pawn.h
   branches/map/src/orxonox/overlays/map/Map.cc
   branches/map/src/orxonox/overlays/map/Map.h
Log:
added rotate and zoom to map. using static mapscenemanager now

Modified: branches/map/src/orxonox/objects/RadarViewable.cc
===================================================================
--- branches/map/src/orxonox/objects/RadarViewable.cc	2009-05-04 18:31:03 UTC (rev 2955)
+++ branches/map/src/orxonox/objects/RadarViewable.cc	2009-05-07 14:44:12 UTC (rev 2956)
@@ -51,6 +51,7 @@
         , MapNode_(NULL)
         , MapEntity_(NULL)
         , line_(NULL)
+        , isHumanShip_(false)
     {
         RegisterRootObject(RadarViewable);
 
@@ -68,7 +69,13 @@
     RadarViewable::~RadarViewable()
     {
         delete MapNode_;
+        MapNode_=0;
         delete MapEntity_;
+        MapEntity_=0;
+        delete line_;
+        line_=0;
+        delete LineNode_;
+        LineNode_=0;
     }
 
     void RadarViewable::addMapEntity()
@@ -90,7 +97,9 @@
             this->line_->addPoint( Vector3(0,0,0) );
 
             this->MapNode_->attachObject( this->MapEntity_ );
-            this->MapNode_->attachObject( this->line_ );
+
+            this->LineNode_ = this->MapNode_->createChildSceneNode();
+            this->LineNode_->attachObject( this->line_ );
         }
         else
         {
@@ -105,8 +114,11 @@
             this->MapNode_->setPosition( this->getRVWorldPosition() );
             this->MapNode_->translate( this->getRVOrientedVelocity(), (Ogre::Node::TransformSpace)3 );
             this->MapNode_->setOrientation( this->getWorldEntity()->getOrientation() );
-Vector3 v = this->getRVWorldPosition();
-            this->line_->setPoint(1, Vector3(0,v.y,0) );
+//Vector3 v = this->getRVWorldPosition();
+            //this->line_->setPoint(1, Vector3(0,v.y,0) );
+            this->line_->setPoint(1, Vector3(0, -this->getRVWorldPosition().y ,0) );
+            this->line_->update();
+            this->LineNode_->setDirection(Vector3::UNIT_Y,Ogre::Node::TS_WORLD,Vector3::UNIT_Y);
         }
     }
 

Modified: branches/map/src/orxonox/objects/RadarViewable.h
===================================================================
--- branches/map/src/orxonox/objects/RadarViewable.h	2009-05-04 18:31:03 UTC (rev 2955)
+++ branches/map/src/orxonox/objects/RadarViewable.h	2009-05-07 14:44:12 UTC (rev 2956)
@@ -100,8 +100,15 @@
         Ogre::SceneNode * MapNode_;
         Ogre::Entity * MapEntity_;
         DynamicLines* line_;
+        Ogre::SceneNode * LineNode_;
         void addMapEntity();
         void updateMapPosition();
+        bool isHumanShip_;
+        inline std::string getUniqueId()
+        {
+            return this->uniqueId_;
+        }
+
     private:
         void validate(const WorldEntity* object) const
         {
@@ -112,9 +119,11 @@
             }
         }
 
+        //Map
+        std::string uniqueId_;
         
-        std::string uniqueId_;
 
+        //Radar
         float radarObjectCamouflage_;
         Shape radarObjectShape_;
         std::string radarObjectDescription_;

Modified: branches/map/src/orxonox/objects/worldentities/pawns/Pawn.cc
===================================================================
--- branches/map/src/orxonox/objects/worldentities/pawns/Pawn.cc	2009-05-04 18:31:03 UTC (rev 2955)
+++ branches/map/src/orxonox/objects/worldentities/pawns/Pawn.cc	2009-05-07 14:44:12 UTC (rev 2956)
@@ -74,6 +74,8 @@
         this->setRadarObjectShape(RadarViewable::Dot);
 
         this->registerVariables();
+
+        this->isHumanShip_ = this->hasLocalController();
     }
 
     Pawn::~Pawn()
@@ -290,7 +292,15 @@
             return 0;
     }
 
+    //Tell the Map (RadarViewable), if this is a playership
+    void Pawn::startLocalHumanControl()
+    {
+//        SUPER(ControllableEntity, changedPlayer());
+        ControllableEntity::startLocalHumanControl();
+        this->isHumanShip_ = true;
+    }
 
+
     ///////////////////
     // Pawn Listener //
     ///////////////////

Modified: branches/map/src/orxonox/objects/worldentities/pawns/Pawn.h
===================================================================
--- branches/map/src/orxonox/objects/worldentities/pawns/Pawn.h	2009-05-04 18:31:03 UTC (rev 2955)
+++ branches/map/src/orxonox/objects/worldentities/pawns/Pawn.h	2009-05-07 14:44:12 UTC (rev 2956)
@@ -107,6 +107,8 @@
                 {return this->pickUp;}
 
             virtual void dropItems();
+            
+            virtual void startLocalHumanControl();
 
         protected:
             virtual void death();

Modified: branches/map/src/orxonox/overlays/map/Map.cc
===================================================================
--- branches/map/src/orxonox/overlays/map/Map.cc	2009-05-04 18:31:03 UTC (rev 2955)
+++ branches/map/src/orxonox/overlays/map/Map.cc	2009-05-07 14:44:12 UTC (rev 2956)
@@ -60,22 +60,35 @@
  {
     CreateFactory(Map);
     SetConsoleCommand(Map, openMap, true);
-    SetConsoleCommand(Map, rotateYaw, true).setAsInputCommand();
-    SetConsoleCommand(Map, rotatePitch, true).setAsInputCommand();
+    //SetConsoleCommand(Map, rotateYaw, true).setAsInputCommand();
+    //SetConsoleCommand(Map, rotatePitch, true).setAsInputCommand();
+    SetConsoleCommand(Map, Zoom, true).setAsInputCommand();
 
     Map* Map::singletonMap_s = 0;
-    
+    Ogre::SceneManager* Map::mapSceneM_s = 0;
+    //int Map::mouseLookSpeed_ = 200;
+    //Ogre::SceneNode* Map::playerShipNode_ = 0;
+
+    const int PITCH=-30;
+    const int DISTANCE=200;
+
     Map::Map(BaseObject* creator) : OrxonoxOverlay(creator)
     {
         RegisterObject(Map);
         Map::singletonMap_s=this;
+        
         //Getting Scene Manager (Hack)
-        ObjectList<Scene>::iterator it = ObjectList<Scene>::begin();
-        this->sManager_ = it->getSceneManager();
-
-        this->mapSceneM_ = Ogre::Root::getSingletonPtr()->createSceneManager( Ogre::ST_GENERIC,"MapScene" );
-        rootNode_ = mapSceneM_->getRootSceneNode();
+        if( !sManager_ )
+        {
+            ObjectList<Scene>::iterator it = ObjectList<Scene>::begin();
+            this->sManager_ = it->getSceneManager();
+        }
+        if( !Map::getMapSceneManager() )
+        {
+            Map::setMapSceneManager( Ogre::Root::getSingletonPtr()->createSceneManager( Ogre::ST_GENERIC,"MapScene" ) );
+        }
         
+        this->playerShipNode_ = 0;
         //this->sNode_ = new Ogre::SceneNode(sManager_);
         //oManager_ = Ogre::OverlayManager::getSingletonPtr();
         //overlay_ = oManager_->create("Map");
@@ -84,36 +97,39 @@
         //Not Showing the map as default
         //this->isVisible_=false;
         //overlay_->hide();
-        
+        this->mouseLookSpeed_ = 200;
 
         //TestEntity
-        //Ogre::Entity * ent = mapSceneM_->createEntity("ent", "drone.mesh");
+        //Ogre::Entity * ent = mapSceneM_s->createEntity("ent", "drone.mesh");
         
-        //rootNode_->attachObject( ent );
+        //Map::getMapSceneManager()->getRootSceneNode()->attachObject( ent );
         /*sNode_->setPosition(0,0,-50);
         overlay_->add3D(sNode_);
         */
 	
-        this->mouseLookSpeed_ = 200;
         
+        
 
         
         // Alter the camera aspect ratio to match the viewport
         //mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
-        mReflectCam_ = mapSceneM_->createCamera("ReflectCam");
-        mReflectCam_->setPosition(200,170, -160);
-        mReflectCam_->lookAt(0,0,0);
-        mReflectCam_->setAspectRatio(1);
+        Cam_ = Map::getMapSceneManager()->createCamera("ReflectCam");
+        //Cam_->setPosition(200,170, -160);
+        //Cam_->lookAt(0,0,0);
+        Cam_->setAspectRatio(1);
+        //Cam_->setRenderingDistance(0);
+        CamNode_ = Map::getMapSceneManager()->getRootSceneNode()->createChildSceneNode();
+        
 
         //Create overlay material
         std::string camMat_id = "RttMat";
-        Ogre::MaterialPtr material = this->createRenderCamera(mReflectCam_, camMat_id);
+        Ogre::MaterialPtr material = this->createRenderCamera(Cam_, camMat_id);
 /*
         Ogre::TexturePtr rttTex = Ogre::TextureManager::getSingleton().createManual("RttTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);
 
         Ogre::RenderTexture *renderTexture = rttTex->getBuffer()->getRenderTarget();
 
-        renderTexture->addViewport(mReflectCam_);
+        renderTexture->addViewport(Cam_);
         renderTexture->getViewport(0)->setClearEveryFrame(true);
         renderTexture->getViewport(0)->setBackgroundColour(ColourValue::Black);
         renderTexture->getViewport(0)->setOverlaysEnabled(false);
@@ -153,15 +169,15 @@
         overlay_->hide();
 
         //Create plane in map
-        Ogre::Entity* plane_ent = this->mapSceneM_->createEntity( "MapPlane", "plane.mesh");
-        Ogre::SceneNode* plane_node = this->mapSceneM_->getRootSceneNode()->createChildSceneNode();
+        Ogre::Entity* plane_ent = Map::getMapSceneManager()->createEntity( "MapPlane", "plane.mesh");
+        planeNode_ = Map::getMapSceneManager()->getRootSceneNode()->createChildSceneNode();
         
         //Ogre::MaterialPtr plane_mat = Ogre::MaterialManager::getSingleton().create("mapgrid", "General");
         //plane_mat->getTechnique(0)->getPass(0)->createTextureUnitState("mapgrid.tga");
         //plane_ent->setMaterialName("mapgrid");
         plane_ent->setMaterialName("Map/Grid");
-        plane_node->attachObject(plane_ent);
-        plane_node->scale(10,1,10);
+        planeNode_->attachObject(plane_ent);
+        planeNode_->scale(10,1,10);
         //Ogre::Material plane_mat = Ogre::MaterialManager::getSingletonPtr()->getByName("rock");
         
 
@@ -177,12 +193,19 @@
 
     Map::~Map()
     {
-        singletonMap_s = 0;
+        this->singletonMap_s = 0;
+        /*if (this->isInitialized())
+        {
         //delete sManager_;
-        //delete rootNode_;
+        //delete Map::getMapSceneManager()->getRootSceneNode();
         //delete oManager_;
-        //delete mReflectCam_;
-        //delete mapSceneM_;
+        //delete CamNode_;
+        //delete Cam_;
+        //delete mapSceneM_s;
+        //Map::getMapSceneManager()->destroyAllEntities();
+        //Map::getMapSceneManager()->destroyAllCameras();
+        delete Map::getMapSceneManager();
+        }*/
     }
 
     Ogre::MaterialPtr Map::createRenderCamera(Ogre::Camera * cam, std::string matName)
@@ -207,7 +230,7 @@
     void Map::updatePositions()
     {
 
-//Ogre::Entity * ent;// = mapSceneM_->createEntity("ent1", "drone.mesh");
+//Ogre::Entity * ent;// = mapSceneM_s->createEntity("ent1", "drone.mesh");
        for(ObjectList<orxonox::RadarViewable>::iterator it = ObjectList<orxonox::RadarViewable>::begin();
             it!=ObjectList<orxonox::RadarViewable>::end();
             it++)
@@ -217,13 +240,13 @@
             //Ogre::Entity ent = it->getMapEntity();
             if( !(it->MapNode_) )
             {
-                it->MapNode_ = rootNode_->createChildSceneNode( it->getRVWorldPosition() );
+                it->MapNode_ = Map::getMapSceneManager()->getRootSceneNode()->createChildSceneNode( it->getRVWorldPosition() );
                 //it->MapNode_->translate( it->getRVOrientedVelocity(), Ogre::TS_WORLD );
                 /*if(it->getRadarObjectShape() == RadarViewable::Dot)
                 {
                     //if( !(it->MapEntity_) )//check wether the entity is already attached
                     //{
-                        //it->MapEntity_ = this->mapSceneM_->createEntity( getUniqueNumberString(), "drone.mesh");
+                        //it->MapEntity_ = Map::getMapSceneManager()->createEntity( getUniqueNumberString(), "drone.mesh");
                         //it->addEntity();
                         //it->MapNode_->attachObject( it->MapEntity_ );
                         //it->MapNode_->attachObject( it->line_ );
@@ -233,15 +256,31 @@
             }
 
             it->updateMapPosition();
+            
 
 
-
+            if(it->isHumanShip_ && it->MapNode_ != this->playerShipNode_)
+            {
+                this->playerShipNode_ = it->MapNode_;
+                this->planeNode_->getParent()->removeChild(this->planeNode_);
+                this->playerShipNode_->addChild(this->planeNode_);
+                this->CamNode_->getParent()->removeChild(this->CamNode_);
+                this->playerShipNode_->addChild(this->CamNode_);
+                this->CamNode_->attachObject(this->Cam_);
+                //this->CamNodeHelper_ = this->CamNode_->createChildSceneNode();
+                //this->CamNodeHelper_->attachObject(this->Cam_);
+                this->Cam_->setPosition(0, 0, DISTANCE);
+                this->Cam_->pitch( (Degree)PITCH );
+                //this->CamNodeHelper_->lookAt(Vector3(0,0,0), Ogre::Node::TS_PARENT);
+                this->Cam_->setAutoTracking(true, this->playerShipNode_);
+            }
             
-        
             
         }
     }
+    
 
+    
     void Map::XMLPort(Element& xmlElement, XMLPort::Mode mode)
     {
         SUPER(Map, XMLPort, xmlElement, mode);
@@ -253,7 +292,7 @@
         if(this->getOwner()->getReverseCamera())
         {
             //COUT(0) << "foo";
-            this->getOwner()->getReverseCamera()->attachCamera(this->mReflectCam_);
+            this->getOwner()->getReverseCamera()->attachCamera(this->Cam_);
         }
     }
 
@@ -296,24 +335,43 @@
         //sNode_->lookAt(Vector3::NEGATIVE_UNIT_Z, Ogre::Node::TS_WORLD, Vector3::NEGATIVE_UNIT_Z);
         if( this->isVisible_ )
             updatePositions();
-        //mReflectCam_->roll(Degree(1));
+        //Cam_->roll(Degree(1));
         
     }
 
     void Map::rotateYaw(const Vector2& value)
     {
-        //if (this->bMouseLook_)
-            //this->mReflectCam_->yaw(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL);
-        if(Map::singletonMap_s)
-            singletonMap_s->mReflectCam_->setOrientation(singletonMap_s->mReflectCam_->getOrientation() * Quaternion( (Degree)(value.y * singletonMap_s->mouseLookSpeed_) , Vector3::UNIT_Y));
+        if(!( Map::singletonMap_s && Map::singletonMap_s->CamNode_ ))
+            return;
+
+/*
+        singletonMap_s->CamNode_->setOrientation(singletonMap_s->CamNode_->getOrientation() * Quaternion( (Degree)(-value.y * singletonMap_s->mouseLookSpeed_) , singletonMap_s->playerShipNode_->getLocalAxes().GetColumn(1) ));
+
+        Map::singletonMap_s->CamNodeHelper_->setDirection(Vector3::UNIT_Y, Ogre::Node::TS_PARENT, Vector3::UNIT_Y);
+        Map::singletonMap_s->CamNodeHelper_->lookAt(Vector3(0,0,0), Ogre::Node::TS_PARENT);
+*/
+        singletonMap_s->CamNode_->yaw( (Degree)(-value.y * singletonMap_s->mouseLookSpeed_), Ogre::Node::TS_PARENT);
     }
 
     void Map::rotatePitch(const Vector2& value)
     {
-        //if (this->bMouseLook_)
-            //this->mReflectCam_->pitch(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL);
-        if(Map::singletonMap_s)
-            singletonMap_s->mReflectCam_->setOrientation(singletonMap_s->mReflectCam_->getOrientation() * Quaternion( (Degree)(-value.y * singletonMap_s->mouseLookSpeed_) , Vector3::UNIT_X));
+        if(!( Map::singletonMap_s && Map::singletonMap_s->CamNode_ ))
+            return;
+            //singletonMap_s->Cam_->setOrientation(singletonMap_s->Cam_->getOrientation() * Quaternion( (Degree)(-value.y * singletonMap_s->mouseLookSpeed_) , Vector3::UNIT_X));
+/*        singletonMap_s->CamNode_->setOrientation(singletonMap_s->CamNode_->getOrientation() * Quaternion( (Degree)(-value.y * singletonMap_s->mouseLookSpeed_) , singletonMap_s->playerShipNode_->getLocalAxes().GetColumn(0) ));
+
+        Map::singletonMap_s->CamNodeHelper_->setDirection(Vector3::UNIT_Y, Ogre::Node::TS_PARENT, Vector3::UNIT_Y);
+        Map::singletonMap_s->CamNodeHelper_->lookAt(Vector3(0,0,0), Ogre::Node::TS_PARENT);
+*/
+        singletonMap_s->CamNode_->pitch( (Degree)(value.y * singletonMap_s->mouseLookSpeed_), Ogre::Node::TS_PARENT);
+        
     }
     
+    void Map::Zoom(const Vector2& value)
+    {
+        if(!( Map::singletonMap_s && Map::singletonMap_s->CamNode_ ))
+            return;
+        //COUT(0) << value.y << std::endl;
+        Map::singletonMap_s->Cam_->setPosition(0,0, Map::singletonMap_s->Cam_->getPosition().z + value.y * Map::singletonMap_s->mouseLookSpeed_ );
+    }
  }

Modified: branches/map/src/orxonox/overlays/map/Map.h
===================================================================
--- branches/map/src/orxonox/overlays/map/Map.h	2009-05-04 18:31:03 UTC (rev 2955)
+++ branches/map/src/orxonox/overlays/map/Map.h	2009-05-07 14:44:12 UTC (rev 2956)
@@ -63,11 +63,12 @@
         
         static void openMap();
 
+//Not yet implemented
         static const int maxRange_s=1000;
 
         static void rotateYaw(const Vector2& value);
         static void rotatePitch(const Vector2& value);
-
+        static void Zoom(const Vector2& value);
         // variables
 
 
@@ -76,13 +77,17 @@
 
         static inline Ogre::SceneManager* getMapSceneManagerPtr()
         {
-            return Map::singletonMap_s->mapSceneM_;
+            return Map::singletonMap_s->mapSceneM_s;
         }
         static inline Map* getSingletonPtr()
         {
             return Map::singletonMap_s;
         }
 
+        static inline Ogre::SceneManager* getMapSceneManager()
+        {
+            return Map::mapSceneM_s;
+        }
 
 
         
@@ -90,17 +95,25 @@
 
         void toggleVisibility();
         void updatePositions();
-        
+//        void changedPlayerNode();
+        static inline void setMapSceneManager( Ogre::SceneManager * sm)
+        {
+            Map::mapSceneM_s = sm;
+        }
 
     private: // variables
         static Map* singletonMap_s;
 
         Ogre::SceneManager* sManager_;
-        Ogre::SceneManager* mapSceneM_;
-        Ogre::SceneNode* rootNode_;
         Ogre::OverlayManager * oManager_;
-        Ogre::Camera* mReflectCam_;
-        //Ogre::SceneNode* playerShipNode_;
+
+        static Ogre::SceneManager* mapSceneM_s;
+        Ogre::SceneNode* CamNode_;
+        Ogre::Camera* Cam_;
+        //Ogre::SceneNode* CamNodeHelper_;
+        Ogre::SceneNode* playerShipNode_;
+        Ogre::SceneNode* planeNode_;
+        
         int mouseLookSpeed_;
         bool isVisible_;
     };




More information about the Orxonox-commit mailing list