[Orxonox-commit 3648] r8333 - in code/branches/kicklib2/src: libraries/util modules/designtools orxonox/controllers orxonox/graphics orxonox/overlays

rgrieder at orxonox.net rgrieder at orxonox.net
Tue Apr 26 04:46:26 CEST 2011


Author: rgrieder
Date: 2011-04-26 04:46:26 +0200 (Tue, 26 Apr 2011)
New Revision: 8333

Modified:
   code/branches/kicklib2/src/libraries/util/Math.h
   code/branches/kicklib2/src/modules/designtools/CreateStars.cc
   code/branches/kicklib2/src/orxonox/controllers/ArtificialController.cc
   code/branches/kicklib2/src/orxonox/controllers/NewHumanController.cc
   code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.cc
   code/branches/kicklib2/src/orxonox/overlays/OrxonoxOverlay.cc
Log:
Removed double precision versions of the mathematical constants and added math::twoPi.

Modified: code/branches/kicklib2/src/libraries/util/Math.h
===================================================================
--- code/branches/kicklib2/src/libraries/util/Math.h	2011-04-26 00:52:04 UTC (rev 8332)
+++ code/branches/kicklib2/src/libraries/util/Math.h	2011-04-26 02:46:26 UTC (rev 8333)
@@ -65,22 +65,20 @@
 
 namespace orxonox
 {
-    // C++ doesn't define any constants for pi, e, etc.
+    /** Often used numerical constants because C++ doesn't define any.
+    @note
+        The values here are decimal representations of the approximate floating
+        point value as it is stored according to the IEEE 754 standard.
+    */
     namespace math
     {
-        const float pi      = 3.14159265f;      ///< PI
-        const float pi_2    = 1.57079633f;      ///< PI / 2
-        const float pi_4    = 7.85398163e-1f;   ///< PI / 4
-        const float e       = 2.71828183f;      ///< e
-        const float sqrt2   = 1.41421356f;      ///< sqrt(2)
-        const float sqrt2_2 = 7.07106781e-1f;   ///< sqrt(2) / 2
-
-        const double pi_d      = 3.14159265358979324;       ///< PI (double)
-        const double pi_2_d    = 1.57079632679489662;       ///< PI / 2 (double)
-        const double pi_4_d    = 7.85398163397448310e-1;    ///< PI / 4 (double)
-        const double e_d       = 2.71828182845904524;       ///< e (double)
-        const double sqrt2_d   = 1.41421356237309505;       ///< sqrt(2) (double)
-        const double sqrt2_2_d = 7.07106781186547524e-1;    ///< sqrt(2) / 2 (double)
+        const float twoPi   = 6.283185482025146484375f;     ///< PI * 2
+        const float pi      = 3.1415927410125732421875f;    ///< PI
+        const float pi_2    = 1.57079637050628662109375f;   ///< PI / 2
+        const float pi_4    = 0.785398185253143310546875f;  ///< PI / 4
+        const float e       = 2.718281269073486328125f;     ///< e
+        const float sqrt2   = 1.41421353816986083984375f;   ///< sqrt(2)
+        const float sqrt2_2 = 0.707106769084930419921875f;  ///< sqrt(2) / 2
     }
 
 #if OGRE_VERSION < 0x010603

Modified: code/branches/kicklib2/src/modules/designtools/CreateStars.cc
===================================================================
--- code/branches/kicklib2/src/modules/designtools/CreateStars.cc	2011-04-26 00:52:04 UTC (rev 8332)
+++ code/branches/kicklib2/src/modules/designtools/CreateStars.cc	2011-04-26 02:46:26 UTC (rev 8333)
@@ -87,7 +87,7 @@
 
             while(1)
             {
-                phi = rnd(2*math::pi);
+                phi = rnd(math::twoPi);
                 teta = rnd(math::pi);
                 float random = rnd(1);
                 if(sin(teta)>random) break;

Modified: code/branches/kicklib2/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/kicklib2/src/orxonox/controllers/ArtificialController.cc	2011-04-26 00:52:04 UTC (rev 8332)
+++ code/branches/kicklib2/src/orxonox/controllers/ArtificialController.cc	2011-04-26 02:46:26 UTC (rev 8333)
@@ -846,8 +846,8 @@
                 float speed = this->getControllableEntity()->getVelocity().length();
                 Vector3 distanceCurrent = this->targetPosition_ - this->getControllableEntity()->getPosition();
                 Vector3 distanceNew = it->getPosition() - this->getControllableEntity()->getPosition();
-                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))
-                        < 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))
+                if (!this->target_ || it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / math::twoPi)
+                        < this->targetPosition_.squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / math::twoPi) + rnd(-250, 250))
                 {
                     this->target_ = (*it);
                     this->targetPosition_ = it->getPosition();

Modified: code/branches/kicklib2/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/branches/kicklib2/src/orxonox/controllers/NewHumanController.cc	2011-04-26 00:52:04 UTC (rev 8332)
+++ code/branches/kicklib2/src/orxonox/controllers/NewHumanController.cc	2011-04-26 02:46:26 UTC (rev 8333)
@@ -542,22 +542,22 @@
 
             if (distance > 0.04f && distance <= 0.59f * arrowsSize_ / 2.0f )
             {
-                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));
+                this->arrowsOverlay1_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / math::twoPi * 360.0f));
                 this->arrowsOverlay1_->show();
             }
             else if (distance > 0.59f * arrowsSize_ / 2.0f && distance <= 0.77f * arrowsSize_ / 2.0f )
             {
-                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));
+                this->arrowsOverlay2_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / math::twoPi * 360.0f));
                 this->arrowsOverlay2_->show();
             }
             else if (distance > 0.77f * arrowsSize_ / 2.0f && distance <= arrowsSize_ / 2.0f)
             {
-                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));
+                this->arrowsOverlay3_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / math::twoPi * 360.0f));
                 this->arrowsOverlay3_->show();
             }
             else if (distance > arrowsSize_ / 2.0f)
             {
-                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));
+                this->arrowsOverlay4_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / math::twoPi * 360.0f));
                 this->arrowsOverlay4_->show();
             }
         }

Modified: code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.cc
===================================================================
--- code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.cc	2011-04-26 00:52:04 UTC (rev 8332)
+++ code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.cc	2011-04-26 02:46:26 UTC (rev 8333)
@@ -80,7 +80,7 @@
         {
             // Wrap around to avoid loosing floating point precision
             this->time_ = std::fmod(this->time_ + dt, 1.0f / this->frequency_);
-            float value = sin((2.0f * math::pi * this->time_ + this->phase_.valueRadians()) * this->frequency_);
+            float value = sin((math::twoPi * this->time_ + this->phase_.valueRadians()) * this->frequency_);
             if (this->bQuadratic_)
                 this->setScale(this->amplitude_ * square(value));
             else

Modified: code/branches/kicklib2/src/orxonox/overlays/OrxonoxOverlay.cc
===================================================================
--- code/branches/kicklib2/src/orxonox/overlays/OrxonoxOverlay.cc	2011-04-26 00:52:04 UTC (rev 8332)
+++ code/branches/kicklib2/src/orxonox/overlays/OrxonoxOverlay.cc	2011-04-26 02:46:26 UTC (rev 8333)
@@ -282,7 +282,7 @@
         if (angle < 0.0)
             angle = -angle;
         angle -= math::pi * static_cast<int>(angle / (math::pi));
-        if (angle > math::pi * 0.5)
+        if (angle > math::pi_2)
             angle = math::pi - angle;
 
         // do some mathematical fiddling for a bounding box




More information about the Orxonox-commit mailing list