Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 18, 2011, 1:11:04 PM (13 years ago)
Author:
FelixSchulthess
Message:

space boundary billboard is now animated. test run with myTestLevel.oxw

Location:
code/branches/presentation
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/data/levels/myTestLevel.oxw

    r8660 r8710  
    3030  >
    3131
    32     <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"/>
    33     <SpawnPoint team=0 position="0,0,0" direction="1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
     32    <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"/>
     33    <SpawnPoint team=0 position="0.1,0.1,0" yaw="-90" roll="-90" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3434   
    3535    <SpaceBoundaries warnDistance="1" maxDistance="200" showDistance="150" reactionMode="0" healthDecrease="0.9" position="0,0,0"/>
    3636   
    37     <Billboard position="0,0,0" colour="1.0,1.0,1.0" material="Flares/backlightflare" scale=1 />
     37    <Billboard position="   0,   0, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     38    <Billboard position="   0,  0,200" colour="0.0,0.0,1.0" material="Flares/backlightflare" scale=0.2 />
     39
     40    <Billboard position=" 142, 142, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     41    <Billboard position=" 142,-142, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     42    <Billboard position="-142,-142, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     43    <Billboard position="-142, 142, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     44
     45    <Billboard position=" 200,   0, 0" colour="1.0,0.0,0.0" material="Flares/backlightflare" scale=0.2 />
     46    <Billboard position="-200,   0, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     47    <Billboard position="   0, 200, 0" colour="0.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     48    <Billboard position="   0,-200, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     49
     50    <Billboard position=" 184,  76, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     51    <Billboard position="  76, 184, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     52    <Billboard position=" -76, 184, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     53    <Billboard position="-184,  76, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     54    <Billboard position="-184, -76, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     55    <Billboard position=" -76,-184, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     56    <Billboard position="  76,-184, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
     57    <Billboard position=" 184, -76, 0" colour="1.0,1.0,0.0" material="Flares/backlightflare" scale=0.2 />
    3858   
    3959  </Scene>
  • code/branches/presentation/src/modules/objects/SpaceBoundaries.cc

    r8694 r8710  
    3535#include "core/XMLPort.h"
    3636
     37#include "util/Math.h"
     38
    3739#include "graphics/Billboard.h"
    3840#include "infos/PlayerInfo.h"
    3941#include "worldentities/WorldEntity.h"
    4042#include "worldentities/pawns/Pawn.h"
     43
     44#ifndef PI2
     45    #define PI2    1.570796327
     46#endif
     47#ifndef PI
     48    #define PI      3.141592654
     49#endif
    4150
    4251namespace orxonox
     
    117126        this->billboards_[current].usedYet = true;
    118127
    119         Vector3 directionVector = (this->getPosition() - position).normalisedCopy(); // vector from the position of the billboard to the center of the sphere
    120         this->billboards_[current].billy->setCommonDirection(directionVector);
    121 
    122         Vector3 upVector = Vector3(directionVector.z, directionVector.z, -(directionVector.x + directionVector.y)); // vector perpendicular to the direction vector
    123         upVector.normalise();
    124         this->billboards_[current].billy->setCommonUpVector(upVector);
     128        // in order to animate the billboard, we use a       
     129        // transform to spherical coordinates according to
     130        // http://de.wikipedia.org/wiki/Kugelkoordinaten convention
     131
     132        Vector3 dirVect = position - this->getPosition();
     133
     134        float phi; // this is the longitude on the sphere (-pi, pi)
     135        if      (dirVect.x >  0) phi = atan(dirVect.y/dirVect.x);
     136        else if (dirVect.x == 0) phi = sgn(dirVect.y) * PI2;
     137        else if (dirVect.y >= 0) phi = atan(dirVect.y/dirVect.x) + PI;
     138        else if (dirVect.y <  0) phi = atan(dirVect.y/dirVect.x) - PI;
     139       
     140        float theta; // this is the latitude measured from z axis (0, pi)
     141        theta = acos(dirVect.z / dirVect.length());
     142
     143        Vector3 e_r = dirVect.normalisedCopy();
     144        //Vector3 e_phi = Vector3(-sin(phi), cos(phi), 0);
     145        Vector3 e_theta = Vector3(cos(theta)*cos(phi), cos(theta)*sin(phi), -sin(theta));
     146
     147        // set billboard orientation
     148        this->billboards_[current].billy->setCommonDirection(e_r);
     149        this->billboards_[current].billy->setCommonUpVector(e_theta);
     150
     151        // set billboard texture coordinates
     152        float u = (phi - floor(phi)) * this->maxDistance_ / 200;
     153        float v = (theta -floor(theta)) * this->maxDistance_ / 200;
     154        Ogre::FloatRect textureCoords = Ogre::FloatRect(0.5-u, 0.5-v, 1.0-u, 1.0-v);
     155        this->billboards_[current].billy->setTextureCoords(&textureCoords, 1);
     156       
     157        // debug output
     158        //COUT(0) << "dirVect: " << dirVect << " len: " << dirVect.length() << std::endl;
     159        //COUT(0) << "phi: " << phi << std::endl;
     160        //COUT(0) << "theta: " << theta << std::endl;
     161        //COUT(0) << "e_r: " << e_r  << " len: " << e_r.length() << std::endl;
     162        //COUT(0) << "e_phi: " << e_phi  << " len: " << e_phi.length() << std::endl;
     163        //COUT(0) << "e_theta: " << e_theta  << " len: " << e_theta.length() << std::endl;
    125164    }
    126165   
    127166    void SpaceBoundaries::setBillboardOptions(Billboard *billy)
    128167    {
    129         if(billy != NULL)
    130         {
    131             billy->setMaterial("Grid");
     168        if(billy)
     169        {
     170            billy->setMaterial("Grid02");
    132171            billy->setBillboardType(Ogre::BBT_PERPENDICULAR_COMMON);
    133             billy->setDefaultDimensions(150, 150);
     172            billy->setDefaultDimensions(100, 100);
    134173            billy->setVisible(true);
    135174        }
  • code/branches/presentation/src/modules/objects/SpaceBoundaries.h

    r8660 r8710  
    4646
    4747/**
    48 @brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area (until now this area is a ball).
     48@brief SpaceBoundaries gives level creators the possibility to keep Pawns from leaving a defined area (until now this area is spherical).
    4949
    5050       Some attributes can/should be defined in the XML-File:
  • code/branches/presentation/src/orxonox/graphics/Billboard.cc

    r8614 r8710  
    145145        }
    146146    }
    147    
    148     void Billboard::setCommonDirection(Vector3 vec)
    149     {
    150         Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet();
    151         if( bSet != NULL )
    152         {
    153             bSet->setCommonDirection( vec );
    154         }
    155     }
    156            
    157     void Billboard::setCommonUpVector(Vector3 vec)
    158     {
    159         Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet();
    160         if( bSet != NULL )
    161         {
    162             bSet->setCommonUpVector( vec );
    163         }
    164     }
    165    
    166     void Billboard::setDefaultDimensions(float width, float height)
    167     {
    168         Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet();
    169         if( bSet != NULL )
    170         {
    171             bSet->setDefaultDimensions(width, height);
    172         }
    173     }
    174147}
  • code/branches/presentation/src/orxonox/graphics/Billboard.h

    r8614 r8710  
    6565                { return this->colour_; }
    6666
    67 
    6867            inline void setRotation(const Radian& rotation)
    6968                { this->rotation_ = rotation; this->changedRotation(); }
     
    7170                { return this->rotation_; }
    7271
     72            /// use normalised vector as argument
     73            inline void setCommonDirection(const Vector3 vec)
     74                { if(this->billboard_.getBillboardSet())
     75                    this->billboard_.getBillboardSet()->setCommonDirection(vec); }
     76            inline const Vector3 getCommonDirection()
     77                { if(this->billboard_.getBillboardSet())
     78                    return this->billboard_.getBillboardSet()->getCommonDirection(); }
     79
     80            /// use normalised vector as argument
     81            inline void setCommonUpVector(const Vector3 vec)
     82                { if(this->billboard_.getBillboardSet())
     83                    this->billboard_.getBillboardSet()->setCommonUpVector( vec ); }
     84            inline const Vector3 getCommonUpVector()
     85                { if(this->billboard_.getBillboardSet())
     86                    return this->billboard_.getBillboardSet()->getCommonUpVector(); }
    7387
    7488            virtual void setTeamColour(const ColourValue& colour)
     
    7791            void setBillboardType(Ogre::BillboardType bbt);
    7892           
    79             void setCommonDirection(Vector3 vec); //!< normalised Vector vec as argument
    80            
    81             void setCommonUpVector(Vector3 vec); //!< normalised Vector vec as argument
    82            
    83             void setDefaultDimensions(float width, float height);
     93            inline void setDefaultDimensions(float width, float height)
     94                { if(this->billboard_.getBillboardSet())
     95                    this->billboard_.getBillboardSet()->setDefaultDimensions(width, height); }
    8496
     97            inline void setTextureCoords(const Ogre::FloatRect* coords, unsigned int numCoords)
     98                { if(this->billboard_.getBillboardSet())
     99                    this->billboard_.getBillboardSet()->setTextureCoords(coords, numCoords); }
    85100
    86101        protected:
Note: See TracChangeset for help on using the changeset viewer.