Changeset 10289 for code/trunk
- Timestamp:
- Mar 1, 2015, 2:16:34 PM (10 years ago)
- Location:
- code/trunk/src
- Files:
-
- 2 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 } -
code/trunk/src/orxonox/controllers/ArtificialController.cc
r10216 r10289 92 92 return; 93 93 94 static const float hardcoded_projectile_speed = 1250;94 static const float hardcoded_projectile_speed = 2500; 95 95 96 96 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.