[Orxonox-commit 4039] r8710 - in code/branches/presentation: data/levels src/modules/objects src/orxonox/graphics

FelixSchulthess at orxonox.net FelixSchulthess at orxonox.net
Sat Jun 18 13:11:04 CEST 2011


Author: FelixSchulthess
Date: 2011-06-18 13:11:04 +0200 (Sat, 18 Jun 2011)
New Revision: 8710

Modified:
   code/branches/presentation/data/levels/myTestLevel.oxw
   code/branches/presentation/src/modules/objects/SpaceBoundaries.cc
   code/branches/presentation/src/modules/objects/SpaceBoundaries.h
   code/branches/presentation/src/orxonox/graphics/Billboard.cc
   code/branches/presentation/src/orxonox/graphics/Billboard.h
Log:
space boundary billboard is now animated. test run with myTestLevel.oxw

Modified: code/branches/presentation/data/levels/myTestLevel.oxw
===================================================================
--- code/branches/presentation/data/levels/myTestLevel.oxw	2011-06-18 11:10:00 UTC (rev 8709)
+++ code/branches/presentation/data/levels/myTestLevel.oxw	2011-06-18 11:11:04 UTC (rev 8710)
@@ -29,12 +29,32 @@
     skybox       = "Orxonox/Starbox"
   >
 
-    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
-    <SpawnPoint team=0 position="0,0,0" direction="1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    <Light type=directional position="0,0,0" direction="0.253, 0.193, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
+    <SpawnPoint team=0 position="0.1,0.1,0" yaw="-90" roll="-90" spawnclass=SpaceShip pawndesign=spaceshipassff />
     
     <SpaceBoundaries warnDistance="1" maxDistance="200" showDistance="150" reactionMode="0" healthDecrease="0.9" position="0,0,0"/>
     
-    <Billboard position="0,0,0" colour="1.0,1.0,1.0" material="Flares/backlightflare" scale=1 />
+    <Billboard position="   0,   0, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position="   0,  0,200" colour="0.0,0.0,1.0" material="Flares/backlightflare" scale=0.2 />
+
+    <Billboard position=" 142, 142, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position=" 142,-142, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position="-142,-142, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position="-142, 142, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+
+    <Billboard position=" 200,   0, 0" colour="1.0,0.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position="-200,   0, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position="   0, 200, 0" colour="0.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position="   0,-200, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+
+    <Billboard position=" 184,  76, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position="  76, 184, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position=" -76, 184, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position="-184,  76, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position="-184, -76, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position=" -76,-184, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position="  76,-184, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
+    <Billboard position=" 184, -76, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     
   </Scene>
 </Level>

Modified: code/branches/presentation/src/modules/objects/SpaceBoundaries.cc
===================================================================
--- code/branches/presentation/src/modules/objects/SpaceBoundaries.cc	2011-06-18 11:10:00 UTC (rev 8709)
+++ code/branches/presentation/src/modules/objects/SpaceBoundaries.cc	2011-06-18 11:11:04 UTC (rev 8710)
@@ -34,11 +34,20 @@
 #include "core/ObjectListIterator.h"
 #include "core/XMLPort.h"
 
+#include "util/Math.h"
+
 #include "graphics/Billboard.h"
 #include "infos/PlayerInfo.h"
 #include "worldentities/WorldEntity.h"
 #include "worldentities/pawns/Pawn.h"
 
+#ifndef PI2
+    #define PI2    1.570796327
+#endif
+#ifndef PI
+    #define PI      3.141592654
+#endif
+
 namespace orxonox
 {
     CreateFactory(SpaceBoundaries);
@@ -116,21 +125,51 @@
         this->billboards_[current].billy->setColour(ColourValue(1, 1, 1, alpha));
         this->billboards_[current].usedYet = true;
 
-        Vector3 directionVector = (this->getPosition() - position).normalisedCopy(); // vector from the position of the billboard to the center of the sphere
-        this->billboards_[current].billy->setCommonDirection(directionVector);
+        // in order to animate the billboard, we use a        
+        // transform to spherical coordinates according to
+        // http://de.wikipedia.org/wiki/Kugelkoordinaten convention
 
-        Vector3 upVector = Vector3(directionVector.z, directionVector.z, -(directionVector.x + directionVector.y)); // vector perpendicular to the direction vector
-        upVector.normalise();
-        this->billboards_[current].billy->setCommonUpVector(upVector);
+        Vector3 dirVect = position - this->getPosition();
+
+        float phi; // this is the longitude on the sphere (-pi, pi)
+        if      (dirVect.x >  0) phi = atan(dirVect.y/dirVect.x);
+        else if (dirVect.x == 0) phi = sgn(dirVect.y) * PI2;
+        else if (dirVect.y >= 0) phi = atan(dirVect.y/dirVect.x) + PI;
+        else if (dirVect.y <  0) phi = atan(dirVect.y/dirVect.x) - PI;
+        
+        float theta; // this is the latitude measured from z axis (0, pi)
+        theta = acos(dirVect.z / dirVect.length());
+
+        Vector3 e_r = dirVect.normalisedCopy();
+        //Vector3 e_phi = Vector3(-sin(phi), cos(phi), 0);
+        Vector3 e_theta = Vector3(cos(theta)*cos(phi), cos(theta)*sin(phi), -sin(theta));
+
+        // set billboard orientation
+        this->billboards_[current].billy->setCommonDirection(e_r);
+        this->billboards_[current].billy->setCommonUpVector(e_theta);
+
+        // set billboard texture coordinates
+        float u = (phi - floor(phi)) * this->maxDistance_ / 200;
+        float v = (theta -floor(theta)) * this->maxDistance_ / 200;
+        Ogre::FloatRect textureCoords = Ogre::FloatRect(0.5-u, 0.5-v, 1.0-u, 1.0-v);
+        this->billboards_[current].billy->setTextureCoords(&textureCoords, 1);
+        
+        // debug output
+        //COUT(0) << "dirVect: " << dirVect << " len: " << dirVect.length() << std::endl;
+        //COUT(0) << "phi: " << phi << std::endl;
+        //COUT(0) << "theta: " << theta << std::endl;
+        //COUT(0) << "e_r: " << e_r  << " len: " << e_r.length() << std::endl;
+        //COUT(0) << "e_phi: " << e_phi  << " len: " << e_phi.length() << std::endl;
+        //COUT(0) << "e_theta: " << e_theta  << " len: " << e_theta.length() << std::endl;
     }
     
     void SpaceBoundaries::setBillboardOptions(Billboard *billy)
     {
-        if(billy != NULL)
+        if(billy)
         {
-            billy->setMaterial("Grid");
+            billy->setMaterial("Grid02");
             billy->setBillboardType(Ogre::BBT_PERPENDICULAR_COMMON);
-            billy->setDefaultDimensions(150, 150);
+            billy->setDefaultDimensions(100, 100);
             billy->setVisible(true);
         }
     }

Modified: code/branches/presentation/src/modules/objects/SpaceBoundaries.h
===================================================================
--- code/branches/presentation/src/modules/objects/SpaceBoundaries.h	2011-06-18 11:10:00 UTC (rev 8709)
+++ code/branches/presentation/src/modules/objects/SpaceBoundaries.h	2011-06-18 11:11:04 UTC (rev 8710)
@@ -45,7 +45,7 @@
 {
 
 /**
- at brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area (until now this area is a ball).
+ at brief SpaceBoundaries gives level creators the possibility to keep Pawns from leaving a defined area (until now this area is spherical).
 
        Some attributes can/should be defined in the XML-File:
        - 'position' : absolute position of the object of SpaceBoundaries in the level (usually 0,0,0) 

Modified: code/branches/presentation/src/orxonox/graphics/Billboard.cc
===================================================================
--- code/branches/presentation/src/orxonox/graphics/Billboard.cc	2011-06-18 11:10:00 UTC (rev 8709)
+++ code/branches/presentation/src/orxonox/graphics/Billboard.cc	2011-06-18 11:11:04 UTC (rev 8710)
@@ -144,31 +144,4 @@
             bSet->setBillboardType(bbt);
         }
     }
-    
-    void Billboard::setCommonDirection(Vector3 vec)
-    {
-        Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet();
-        if( bSet != NULL )
-        {
-            bSet->setCommonDirection( vec );
-        }
-    }
-            
-    void Billboard::setCommonUpVector(Vector3 vec)
-    {
-        Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet();
-        if( bSet != NULL )
-        {
-            bSet->setCommonUpVector( vec );
-        }
-    }
-    
-    void Billboard::setDefaultDimensions(float width, float height)
-    {
-        Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet();
-        if( bSet != NULL )
-        {
-            bSet->setDefaultDimensions(width, height);
-        }
-    }
 }

Modified: code/branches/presentation/src/orxonox/graphics/Billboard.h
===================================================================
--- code/branches/presentation/src/orxonox/graphics/Billboard.h	2011-06-18 11:10:00 UTC (rev 8709)
+++ code/branches/presentation/src/orxonox/graphics/Billboard.h	2011-06-18 11:11:04 UTC (rev 8710)
@@ -64,24 +64,39 @@
             inline const ColourValue& getColour() const
                 { return this->colour_; }
 
-
             inline void setRotation(const Radian& rotation)
                 { this->rotation_ = rotation; this->changedRotation(); }
             inline const Radian& getRotation() const
                 { return this->rotation_; }
 
+            /// use normalised vector as argument
+            inline void setCommonDirection(const Vector3 vec)
+                { if(this->billboard_.getBillboardSet())
+                    this->billboard_.getBillboardSet()->setCommonDirection(vec); }
+            inline const Vector3 getCommonDirection()
+                { if(this->billboard_.getBillboardSet())
+                    return this->billboard_.getBillboardSet()->getCommonDirection(); }
 
+            /// use normalised vector as argument
+            inline void setCommonUpVector(const Vector3 vec)
+                { if(this->billboard_.getBillboardSet())
+                    this->billboard_.getBillboardSet()->setCommonUpVector( vec ); }
+            inline const Vector3 getCommonUpVector()
+                { if(this->billboard_.getBillboardSet())
+                    return this->billboard_.getBillboardSet()->getCommonUpVector(); }
+
             virtual void setTeamColour(const ColourValue& colour)
                 { this->setColour(colour); }
                 
             void setBillboardType(Ogre::BillboardType bbt);
             
-            void setCommonDirection(Vector3 vec); //!< normalised Vector vec as argument
-            
-            void setCommonUpVector(Vector3 vec); //!< normalised Vector vec as argument
-            
-            void setDefaultDimensions(float width, float height);
+            inline void setDefaultDimensions(float width, float height)
+                { if(this->billboard_.getBillboardSet())
+                    this->billboard_.getBillboardSet()->setDefaultDimensions(width, height); }
 
+            inline void setTextureCoords(const Ogre::FloatRect* coords, unsigned int numCoords)
+                { if(this->billboard_.getBillboardSet())
+                    this->billboard_.getBillboardSet()->setTextureCoords(coords, numCoords); }
 
         protected:
             inline BillboardSet& getBillboardSet()




More information about the Orxonox-commit mailing list