Changeset 9444 for code/branches/spaceNavigation/src/modules
- Timestamp:
- Nov 12, 2012, 11:07:01 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/spaceNavigation/src/modules/overlays/hud/HUDNavigation.cc
r9443 r9444 489 489 Vector3 targetPosition = target->getRVWorldPosition(); 490 490 Vector3 targetSpeed = target->getRVOrientedVelocity(); 491 Vector3 relativePosition = targetPosition - wePosition; //Vector from attacker to target 492 493 float p_half = relativePosition.dotProduct(targetSpeed)/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_); 494 float time1 = -p_half + sqrt(p_half * p_half - relativePosition.squaredLength()/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_)); 495 orxout()<< "TIME 1: " << time1 <<endl; 496 497 491 498 492 499 // munSpeed*time = lengthBetween(wePosition, targetPosition + targetSpeed*time) 493 500 // from this we extract: 494 float a = targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_;501 float a = pow(targetSpeed.length(),2) - pow(this->currentMunitionSpeed_,2); 495 502 float b = 2*((targetPosition.x - wePosition.x)*targetSpeed.x 496 503 +(targetPosition.y - wePosition.y)*targetSpeed.y 497 504 +(targetPosition.z - wePosition.z)*targetSpeed.z); 498 float c = (wePosition-targetPosition).squaredLength();505 float c = pow((targetPosition-wePosition).length(),2); 499 506 500 507 // calculate smallest time solution, in case it exists 501 float det = b * b - 4 * a * c; 502 if(det < 0) 508 if(pow(b,2) - 4*a*c < 0) 503 509 return NULL; 504 float time = (-b - sqrt(det))/(2*a); 510 float time = (-b - sqrt(pow(b,2) - 4*a*c))/(2*a); 511 orxout()<< "TIME 1: " << time1 <<endl; 505 512 if(time < 0) 506 time = (-b + sqrt( det))/(2*a);513 time = (-b + sqrt(pow(b,2) - 4*a*c))/(2*a); 507 514 if(time < 0) 508 515 return NULL; 509 Vector3* result = new Vector3(targetPosition + t ime * targetSpeed);516 Vector3* result = new Vector3(targetPosition + targetSpeed * time); 510 517 return result; 511 518 }
Note: See TracChangeset
for help on using the changeset viewer.