[Orxonox-commit 5629] r10289 - in code/trunk/src: libraries/util orxonox/controllers

landauf at orxonox.net landauf at orxonox.net
Sun Mar 1 14:16:34 CET 2015


Author: landauf
Date: 2015-03-01 14:16:34 +0100 (Sun, 01 Mar 2015)
New Revision: 10289

Modified:
   code/trunk/src/libraries/util/Math.cc
   code/trunk/src/orxonox/controllers/ArtificialController.cc
Log:
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

Modified: code/trunk/src/libraries/util/Math.cc
===================================================================
--- code/trunk/src/libraries/util/Math.cc	2015-02-28 22:55:18 UTC (rev 10288)
+++ code/trunk/src/libraries/util/Math.cc	2015-03-01 13:16:34 UTC (rev 10289)
@@ -350,18 +350,20 @@
     */
     orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity)
     {
-        float squaredProjectilespeed = projectilespeed * projectilespeed;
         orxonox::Vector3 distance = targetposition - myposition;
         float a = distance.squaredLength();
-        float b = 2 * (distance.x + distance.y + distance.z) * (targetvelocity.x + targetvelocity.y + targetvelocity.z);
-        float c = targetvelocity.squaredLength();
+        float b = 2 * (distance.x * targetvelocity.x + distance.y * targetvelocity.y + distance.z * targetvelocity.z);
+        float c = targetvelocity.squaredLength() - projectilespeed * projectilespeed;
 
-        float temp = 4*squaredProjectilespeed*c + a*a - 4*b*c;
-        if (temp < 0)
+        float discriminant = b*b - 4*a*c;
+        if (discriminant < 0)
             return orxonox::Vector3::ZERO;
 
-        temp = sqrt(temp);
-        float time = (temp + a) / (2 * (squaredProjectilespeed - b));
+        float temp = sqrt(discriminant);
+        float solution1 = (-b + temp) / (2 * a);
+        float solution2 = (-b - temp) / (2 * a);
+        float time = 1.0f / std::max(solution1, solution2);
+
         return (targetposition + targetvelocity * time);
     }
 

Modified: code/trunk/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/ArtificialController.cc	2015-02-28 22:55:18 UTC (rev 10288)
+++ code/trunk/src/orxonox/controllers/ArtificialController.cc	2015-03-01 13:16:34 UTC (rev 10289)
@@ -91,7 +91,7 @@
         if (!this->target_ || !this->getControllableEntity())
             return;
 
-        static const float hardcoded_projectile_speed = 1250;
+        static const float hardcoded_projectile_speed = 2500;
 
         this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
         this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);




More information about the Orxonox-commit mailing list