Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10291 for code/trunk/src


Ignore:
Timestamp:
Mar 1, 2015, 3:08:45 PM (10 years ago)
Author:
landauf
Message:

simplified Math: temp is always positive, thus only solution1 is necessary
simplified HUDNavigation: use existing function to calculation aim-position

Location:
code/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/util/Math.cc

    r10289 r10291  
    360360            return orxonox::Vector3::ZERO;
    361361
    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);
     362        float solution = (-b + sqrt(discriminant)) / (2 * a);
     363        float time = 1.0f / solution;
    366364
    367365        return (targetposition + targetvelocity * time);
  • code/trunk/src/modules/overlays/hud/HUDNavigation.cc

    r10258 r10291  
    487487                    {
    488488                        // get the aim position
    489                         Vector3* targetPos = this->toAimPosition(it->first);
     489                        const Vector3& targetPos = this->toAimPosition(it->first);
    490490                        // Transform to screen coordinates
    491                         Vector3 screenPos = camTransform * (*targetPos);
     491                        Vector3 screenPos = camTransform * targetPos;
    492492                        // Check if the target marker is in view too
    493493                        if(screenPos.z > 1 || screenPos.x < -1.0 || screenPos.x > 1.0
     
    502502                            it->second.target_->show();
    503503                        }
    504                         delete targetPos;
    505504                    }
    506505
     
    679678    }
    680679
    681     Vector3* HUDNavigation::toAimPosition(RadarViewable* target) const
     680    Vector3 HUDNavigation::toAimPosition(RadarViewable* target) const
    682681    {
    683682        Vector3 wePosition = HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition();
    684683        Vector3 targetPosition = target->getRVWorldPosition();
    685684        Vector3 targetSpeed = target->getRVVelocity();
    686         Vector3 relativePosition = targetPosition - wePosition; //Vector from attacker to target
    687 
    688         float p_half = relativePosition.dotProduct(targetSpeed)/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_);
    689         float time1 = -p_half + sqrt(p_half * p_half - relativePosition.squaredLength()/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_));
    690 
    691         Vector3* result = new Vector3(targetPosition + targetSpeed * time1);
    692         return result;
     685
     686        return getPredictedPosition(wePosition, this->currentMunitionSpeed_, targetPosition, targetSpeed);
    693687    }
    694688
  • code/trunk/src/modules/overlays/hud/HUDNavigation.h

    r10258 r10291  
    138138            float getArrowSizeY(int dist) const;
    139139
    140             Vector3* toAimPosition(RadarViewable* target) const;
     140            Vector3 toAimPosition(RadarViewable* target) const;
    141141
    142142            std::map<RadarViewable*, ObjectInfo> activeObjectList_;
Note: See TracChangeset for help on using the changeset viewer.