Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 8, 2008, 5:04:18 PM (16 years ago)
Author:
landauf
Message:
  • added a prediction-crosshair to the navigation focus
  • fixed a bug in SpaceShipAI's target movement prediction - bots are more accurate now
File:
1 edited

Legend:

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

    r1564 r1566  
    106106        return orxonox::Vector2(-sin(angle) * radius, cos(angle) * radius);
    107107}
     108
     109orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity)
     110{
     111    float squaredProjectilespeed = projectilespeed * projectilespeed;
     112    orxonox::Vector3 distance = targetposition - myposition;
     113    float a = distance.squaredLength();
     114    float b = 2 * (distance.x + distance.y + distance.z) * (targetvelocity.x + targetvelocity.y + targetvelocity.z);
     115    float c = targetvelocity.squaredLength();
     116
     117    float temp = 4*squaredProjectilespeed*c + a*a - 4*b*c;
     118    if (temp < 0)
     119        return orxonox::Vector3::ZERO;
     120
     121    temp = sqrt(temp);
     122    float time = (temp + a) / (2 * (squaredProjectilespeed - b));
     123    return (targetposition + targetvelocity * time);
     124}
Note: See TracChangeset for help on using the changeset viewer.