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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        }
Note: See TracChangeset for help on using the changeset viewer.