Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10630


Ignore:
Timestamp:
Oct 10, 2015, 6:36:49 PM (8 years ago)
Author:
landauf
Message:

avoid division by zero errors (happened e.g. if 'myposition' and 'targetposition' were equal)

File:
1 edited

Legend:

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

    r10291 r10630  
    358358        float discriminant = b*b - 4*a*c;
    359359        if (discriminant < 0)
    360             return orxonox::Vector3::ZERO;
    361 
     360            return orxonox::Vector3::ZERO; // solution is undefined (e.g. target faster than projectile)
     361
     362        if (a == 0.0f)
     363            return orxonox::Vector3::ZERO; // avoid division by zero
    362364        float solution = (-b + sqrt(discriminant)) / (2 * a);
     365
     366        if (solution == 0.0f)
     367            return orxonox::Vector3::ZERO; // avoid division by zero
    363368        float time = 1.0f / solution;
    364369
Note: See TracChangeset for help on using the changeset viewer.