[Orxonox-commit 3647] r8332 - code/branches/kicklib2/src/orxonox/graphics

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


Author: rgrieder
Date: 2011-04-26 02:52:04 +0200 (Tue, 26 Apr 2011)
New Revision: 8332

Modified:
   code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.cc
   code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.h
Log:
BlinkingBillboard should not use long double for storing the time because of a precision loss on certain configurations.
Instead, wrap around before computing the sine.

Modified: code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.cc
===================================================================
--- code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.cc	2011-04-26 00:50:03 UTC (rev 8331)
+++ code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.cc	2011-04-26 00:52:04 UTC (rev 8332)
@@ -78,11 +78,13 @@
 
         if (this->isActive())
         {
-            this->time_ += dt;
+            // 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_);
             if (this->bQuadratic_)
-                this->setScale(this->amplitude_ * static_cast<float>(square(sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_))));
+                this->setScale(this->amplitude_ * square(value));
             else
-                this->setScale(this->amplitude_ * static_cast<float>(fabs(sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_))));
+                this->setScale(this->amplitude_ * std::abs(value));
         }
     }
 }

Modified: code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.h
===================================================================
--- code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.h	2011-04-26 00:50:03 UTC (rev 8331)
+++ code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.h	2011-04-26 00:52:04 UTC (rev 8332)
@@ -74,7 +74,7 @@
             float frequency_;
             Degree phase_;
             bool bQuadratic_;
-            long double time_;
+            float time_;
     };
 }
 




More information about the Orxonox-commit mailing list