Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 12, 2012, 11:07:01 PM (12 years ago)
Author:
jo
Message:

The time seems correct. The marker positioning also seems to be ok. So from where comes the displacement?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/spaceNavigation/src/modules/overlays/hud/HUDNavigation.cc

    r9443 r9444  
    489489        Vector3 targetPosition = target->getRVWorldPosition();
    490490        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
    491498
    492499        // munSpeed*time = lengthBetween(wePosition, targetPosition + targetSpeed*time)
    493500        // from this we extract:
    494         float a = targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_;
     501        float a = pow(targetSpeed.length(),2) - pow(this->currentMunitionSpeed_,2);
    495502        float b = 2*((targetPosition.x - wePosition.x)*targetSpeed.x
    496503                    +(targetPosition.y - wePosition.y)*targetSpeed.y
    497504                    +(targetPosition.z - wePosition.z)*targetSpeed.z);
    498         float c = (wePosition-targetPosition).squaredLength();
     505        float c = pow((targetPosition-wePosition).length(),2);
    499506
    500507        // 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)
    503509            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;
    505512        if(time < 0)
    506             time = (-b + sqrt(det))/(2*a);
     513            time = (-b + sqrt(pow(b,2) - 4*a*c))/(2*a);
    507514        if(time < 0)
    508515            return NULL;
    509         Vector3* result = new Vector3(targetPosition + time * targetSpeed);
     516        Vector3* result = new Vector3(targetPosition + targetSpeed * time);
    510517        return result;
    511518    }
Note: See TracChangeset for help on using the changeset viewer.