Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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/libraries/util
Files:
3 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);
Note: See TracChangeset for help on using the changeset viewer.