Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7184 for code/trunk


Ignore:
Timestamp:
Aug 18, 2010, 9:46:16 PM (14 years ago)
Author:
rgrieder
Message:

Replaced mathematical constants with a common definition in Math.h.
Use math::pi, math::pi_d (double), math::e, etc. from now on.

Location:
code/trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/util/ExprParser.cc

    r6417 r7184  
    3333
    3434#include "ExprParser.h"
     35
    3536#include <cmath>
    3637#include <cstring>
    3738#include <cstdlib>
     39#include "Math.h"
    3840
    3941// macros for easier if, else statements
     
    5052    {
    5153        this->failed_ = false;
    52         this->variables_["pi"] = 3.1415926535897932;
    53         this->variables_["e"] = 2.7182818284590452;
     54        this->variables_["pi"] = math::pi_d;
     55        this->variables_["e"] = math::e_d;
    5456    }
    5557
     
    328330                    value = sqrt(parse_last_argument());
    329331                CASE("degrees")
    330                     value = parse_last_argument()*180/3.1415926535897932;
     332                    value = parse_last_argument()*180/math::pi_d;
    331333                CASE("radians")
    332                     value = parse_last_argument()*3.1415926535897932/180;
     334                    value = parse_last_argument()*math::pi_d/180;
    333335                CASE("mod")
    334336                {
  • code/trunk/src/libraries/util/Math.cc

    r6417 r7184  
    185185        float distancelength = distance.length();
    186186        if (distancelength == 0) return orxonox::Vector2(0, 0);
    187         float radius = acos(clamp<float>(mydirection.dotProduct(distance) / distancelength, -1, 1)) / Ogre::Math::PI;
     187        float radius = acos(clamp<float>(mydirection.dotProduct(distance) / distancelength, -1, 1)) / math::pi;
    188188
    189189        if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
  • code/trunk/src/libraries/util/Math.h

    r6502 r7184  
    5959namespace orxonox
    6060{
     61    // C++ doesn't define any constants for pi, e, etc.
     62    namespace math
     63    {
     64        const float pi      = 3.14159265f;
     65        const float pi_2    = 1.57079633f;
     66        const float pi_4    = 7.85398163e-1f;
     67        const float e       = 2.71828183f;
     68        const float sqrt2   = 1.41421356f;
     69        const float sqrt2_2 = 7.07106781e-1f;
     70
     71        const double pi_d      = 3.14159265358979324;
     72        const double pi_2_d    = 1.57079632679489662;
     73        const double pi_4_d    = 7.85398163397448310e-1;
     74        const double e_d       = 2.71828182845904524;
     75        const double sqrt2_d   = 1.41421356237309505;
     76        const double sqrt2_2_d = 7.07106781186547524e-1;
     77    }
     78
    6179#if OGRE_VERSION < 0x010603
    6280    _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Radian& radian);
  • code/trunk/src/modules/designtools/CreateStars.cc

    r7163 r7184  
    3838{
    3939    CreateFactory(CreateStars);
    40 
    41     static const float pi = 3.14159265359f;
    4240
    4341    CreateStars::CreateStars(BaseObject* creator) : BaseObject(creator)
     
    9088            while(1)
    9189            {
    92                 phi = rnd(2*pi);
    93                 teta = rnd(pi);
     90                phi = rnd(2*math::pi);
     91                teta = rnd(math::pi);
    9492                float random = rnd(1);
    9593                if(sin(teta)>random) break;
  • code/trunk/src/modules/overlays/hud/HUDRadar.cc

    r7163 r7184  
    174174            // calc position on radar...
    175175            Vector2 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition());
    176             coord *= Ogre::Math::PI / 3.5f; // small adjustment to make it fit the texture
     176            coord *= math::pi / 3.5f; // small adjustment to make it fit the texture
    177177            it->second->setPosition((1.0f + coord.x - size) * 0.5f, (1.0f - coord.y - size) * 0.5f);
    178178            it->second->show();
  • code/trunk/src/orxonox/controllers/AIController.cc

    r7168 r7184  
    220220                    this->moveToTargetPosition();
    221221
    222                 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
     222                if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
    223223                    this->getControllableEntity()->fire(0);
    224224            }
     
    253253                this->moveToTargetPosition();
    254254
    255             if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
     255            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
    256256                this->getControllableEntity()->fire(0);
    257257        }
  • code/trunk/src/orxonox/controllers/ArtificialController.cc

    r7183 r7184  
    847847                Vector3 distanceCurrent = this->targetPosition_ - this->getControllableEntity()->getPosition();
    848848                Vector3 distanceNew = it->getPosition() - this->getControllableEntity()->getPosition();
    849                 if (!this->target_ || it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / (2 * Ogre::Math::PI))
    850                         < this->targetPosition_.squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI)) + rnd(-250, 250))
     849                if (!this->target_ || it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / (2 * math::pi))
     850                        < this->targetPosition_.squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * math::pi)) + rnd(-250, 250))
    851851                {
    852852                    this->target_ = (*it);
  • code/trunk/src/orxonox/controllers/NewHumanController.cc

    r7163 r7184  
    534534            if (distance > 0.04f && distance <= 0.59f * arrowsSize_ / 2.0f )
    535535            {
    536                 this->arrowsOverlay1_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f));
     536                this->arrowsOverlay1_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * math::pi) * 360.0f));
    537537                this->arrowsOverlay1_->show();
    538538            }
    539539            else if (distance > 0.59f * arrowsSize_ / 2.0f && distance <= 0.77f * arrowsSize_ / 2.0f )
    540540            {
    541                 this->arrowsOverlay2_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f));
     541                this->arrowsOverlay2_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * math::pi) * 360.0f));
    542542                this->arrowsOverlay2_->show();
    543543            }
    544544            else if (distance > 0.77f * arrowsSize_ / 2.0f && distance <= arrowsSize_ / 2.0f)
    545545            {
    546                 this->arrowsOverlay3_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f));
     546                this->arrowsOverlay3_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * math::pi) * 360.0f));
    547547                this->arrowsOverlay3_->show();
    548548            }
    549549            else if (distance > arrowsSize_ / 2.0f)
    550550            {
    551                 this->arrowsOverlay4_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f));
     551                this->arrowsOverlay4_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * math::pi) * 360.0f));
    552552                this->arrowsOverlay4_->show();
    553553            }
  • code/trunk/src/orxonox/controllers/WaypointPatrolController.cc

    r7163 r7184  
    6868                this->moveToTargetPosition();
    6969
    70             if (this->getControllableEntity() && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
     70            if (this->getControllableEntity() && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
    7171                this->getControllableEntity()->fire(0);
    7272        }
  • code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc

    r6799 r7184  
    282282        if (angle < 0.0)
    283283            angle = -angle;
    284         angle -= Ogre::Math::PI * static_cast<int>(angle / (Ogre::Math::PI));
    285         if (angle > Ogre::Math::PI * 0.5)
    286             angle = Ogre::Math::PI - angle;
     284        angle -= math::pi * static_cast<int>(angle / (math::pi));
     285        if (angle > math::pi * 0.5)
     286            angle = math::pi - angle;
    287287
    288288        // do some mathematical fiddling for a bounding box
  • code/trunk/src/orxonox/worldentities/pawns/FpsPlayer.cc

    r7183 r7184  
    171171
    172172                Radian pitch = this->cameraPositionRootNode_->getOrientation().getPitch();
    173                 if (pitch < Radian(1.5707f) && pitch > Radian(-1.5707f))
     173                if (pitch < Radian(math::pi_2) && pitch > Radian(-math::pi_2))
    174174                {
    175175                    this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
    176176                }
    177                 else if (pitch < Radian(-1.5707f))
     177                else if (pitch < Radian(-math::pi_2))
    178178                {
    179179                    if (this->pitch_ > 0.0f)
    180180                        this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
    181                     else if (pitch < Radian(-1.571f))
    182                         this->cameraPositionRootNode_->pitch(-pitch + Radian(-1.570796f));
     181                    else if (pitch < Radian(-math::pi_2))
     182                        this->cameraPositionRootNode_->pitch(-pitch + Radian(-math::pi_2));
    183183                }
    184                 else if (pitch > Radian(1.5707f))
     184                else if (pitch > Radian(math::pi_2))
    185185                {
    186186                    if (this->pitch_ < 0.0f)
    187187                        this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
    188                     else if (pitch > Radian(1.571f))
    189                         this->cameraPositionRootNode_->pitch(-pitch + Radian(1.570796f));
     188                    else if (pitch > Radian(math::pi_2))
     189                        this->cameraPositionRootNode_->pitch(-pitch + Radian(math::pi_2));
    190190                }
    191191                this->weaponNode_->setOrientation(this->cameraPositionRootNode_->getOrientation());
Note: See TracChangeset for help on using the changeset viewer.