Changeset 10289 for code/trunk/src/libraries/util
- Timestamp:
- Mar 1, 2015, 2:16:34 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/util/Math.cc
r9960 r10289 351 351 orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity) 352 352 { 353 float squaredProjectilespeed = projectilespeed * projectilespeed;354 353 orxonox::Vector3 distance = targetposition - myposition; 355 354 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) 361 360 return orxonox::Vector3::ZERO; 362 361 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 365 367 return (targetposition + targetvelocity * time); 366 368 }
Note: See TracChangeset
for help on using the changeset viewer.