[Orxonox-commit 5631] r10291 - in code/trunk/src: libraries/util modules/overlays/hud
landauf at orxonox.net
landauf at orxonox.net
Sun Mar 1 15:08:45 CET 2015
Author: landauf
Date: 2015-03-01 15:08:45 +0100 (Sun, 01 Mar 2015)
New Revision: 10291
Modified:
code/trunk/src/libraries/util/Math.cc
code/trunk/src/modules/overlays/hud/HUDNavigation.cc
code/trunk/src/modules/overlays/hud/HUDNavigation.h
Log:
simplified Math: temp is always positive, thus only solution1 is necessary
simplified HUDNavigation: use existing function to calculation aim-position
Modified: code/trunk/src/libraries/util/Math.cc
===================================================================
--- code/trunk/src/libraries/util/Math.cc 2015-03-01 13:17:08 UTC (rev 10290)
+++ code/trunk/src/libraries/util/Math.cc 2015-03-01 14:08:45 UTC (rev 10291)
@@ -359,10 +359,8 @@
if (discriminant < 0)
return orxonox::Vector3::ZERO;
- float temp = sqrt(discriminant);
- float solution1 = (-b + temp) / (2 * a);
- float solution2 = (-b - temp) / (2 * a);
- float time = 1.0f / std::max(solution1, solution2);
+ float solution = (-b + sqrt(discriminant)) / (2 * a);
+ float time = 1.0f / solution;
return (targetposition + targetvelocity * time);
}
Modified: code/trunk/src/modules/overlays/hud/HUDNavigation.cc
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDNavigation.cc 2015-03-01 13:17:08 UTC (rev 10290)
+++ code/trunk/src/modules/overlays/hud/HUDNavigation.cc 2015-03-01 14:08:45 UTC (rev 10291)
@@ -486,9 +486,9 @@
else // object is selected and moves
{
// get the aim position
- Vector3* targetPos = this->toAimPosition(it->first);
+ const Vector3& targetPos = this->toAimPosition(it->first);
// Transform to screen coordinates
- Vector3 screenPos = camTransform * (*targetPos);
+ Vector3 screenPos = camTransform * targetPos;
// Check if the target marker is in view too
if(screenPos.z > 1 || screenPos.x < -1.0 || screenPos.x > 1.0
|| screenPos.y < -1.0 || screenPos.y > 1.0)
@@ -501,7 +501,6 @@
it->second.target_->setTop((-screenPos.y + 1.0f - it->second.target_->getHeight()) * 0.5f);
it->second.target_->show();
}
- delete targetPos;
}
}
@@ -678,18 +677,13 @@
}
}
- Vector3* HUDNavigation::toAimPosition(RadarViewable* target) const
+ Vector3 HUDNavigation::toAimPosition(RadarViewable* target) const
{
Vector3 wePosition = HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition();
Vector3 targetPosition = target->getRVWorldPosition();
Vector3 targetSpeed = target->getRVVelocity();
- Vector3 relativePosition = targetPosition - wePosition; //Vector from attacker to target
- float p_half = relativePosition.dotProduct(targetSpeed)/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_);
- float time1 = -p_half + sqrt(p_half * p_half - relativePosition.squaredLength()/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_));
-
- Vector3* result = new Vector3(targetPosition + targetSpeed * time1);
- return result;
+ return getPredictedPosition(wePosition, this->currentMunitionSpeed_, targetPosition, targetSpeed);
}
void HUDNavigation::selectClosestTarget()
Modified: code/trunk/src/modules/overlays/hud/HUDNavigation.h
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDNavigation.h 2015-03-01 13:17:08 UTC (rev 10290)
+++ code/trunk/src/modules/overlays/hud/HUDNavigation.h 2015-03-01 14:08:45 UTC (rev 10291)
@@ -137,7 +137,7 @@
float getArrowSizeX(int dist) const;
float getArrowSizeY(int dist) const;
- Vector3* toAimPosition(RadarViewable* target) const;
+ Vector3 toAimPosition(RadarViewable* target) const;
std::map<RadarViewable*, ObjectInfo> activeObjectList_;
std::list<std::pair<RadarViewable*, unsigned int> > sortedObjectList_;
More information about the Orxonox-commit
mailing list