Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 26, 2011, 2:52:04 AM (14 years ago)
Author:
rgrieder
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/kicklib2/src/orxonox/graphics/BlinkingBillboard.cc

    r7163 r8332  
    7979        if (this->isActive())
    8080        {
    81             this->time_ += dt;
     81            // Wrap around to avoid loosing floating point precision
     82            this->time_ = std::fmod(this->time_ + dt, 1.0f / this->frequency_);
     83            float value = sin((2.0f * math::pi * this->time_ + this->phase_.valueRadians()) * this->frequency_);
    8284            if (this->bQuadratic_)
    83                 this->setScale(this->amplitude_ * static_cast<float>(square(sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_))));
     85                this->setScale(this->amplitude_ * square(value));
    8486            else
    85                 this->setScale(this->amplitude_ * static_cast<float>(fabs(sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_))));
     87                this->setScale(this->amplitude_ * std::abs(value));
    8688        }
    8789    }
Note: See TracChangeset for help on using the changeset viewer.