Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10289 for code/trunk


Ignore:
Timestamp:
Mar 1, 2015, 2:16:34 PM (10 years ago)
Author:
landauf
Message:

fixed target position calculation:

a) the math was wrong (not sure why)
b) the assumed projectile speed now matches the actual speed of the HsW01 weapon which is used most of the time

Location:
code/trunk/src
Files:
2 edited

Legend:

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

    r9960 r10289  
    351351    orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity)
    352352    {
    353         float squaredProjectilespeed = projectilespeed * projectilespeed;
    354353        orxonox::Vector3 distance = targetposition - myposition;
    355354        float a = distance.squaredLength();
    356         float b = 2 * (distance.x + distance.y + distance.z) * (targetvelocity.x + targetvelocity.y + targetvelocity.z);
    357         float c = targetvelocity.squaredLength();
    358 
    359         float temp = 4*squaredProjectilespeed*c + a*a - 4*b*c;
    360         if (temp < 0)
     355        float b = 2 * (distance.x * targetvelocity.x + distance.y * targetvelocity.y + distance.z * targetvelocity.z);
     356        float c = targetvelocity.squaredLength() - projectilespeed * projectilespeed;
     357
     358        float discriminant = b*b - 4*a*c;
     359        if (discriminant < 0)
    361360            return orxonox::Vector3::ZERO;
    362361
    363         temp = sqrt(temp);
    364         float time = (temp + a) / (2 * (squaredProjectilespeed - b));
     362        float temp = sqrt(discriminant);
     363        float solution1 = (-b + temp) / (2 * a);
     364        float solution2 = (-b - temp) / (2 * a);
     365        float time = 1.0f / std::max(solution1, solution2);
     366
    365367        return (targetposition + targetvelocity * time);
    366368    }
  • code/trunk/src/orxonox/controllers/ArtificialController.cc

    r10216 r10289  
    9292            return;
    9393
    94         static const float hardcoded_projectile_speed = 1250;
     94        static const float hardcoded_projectile_speed = 2500;
    9595
    9696        this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
Note: See TracChangeset for help on using the changeset viewer.