Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1566


Ignore:
Timestamp:
Jun 8, 2008, 5:04:18 PM (16 years ago)
Author:
landauf
Message:
  • added a prediction-crosshair to the navigation focus
  • fixed a bug in SpaceShipAI's target movement prediction - bots are more accurate now
Location:
code/trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/hud/Navigation.cc

    r1564 r1566  
    3636// TODO: remove the SpaceShip and CameraHandler dependencies
    3737#include "objects/SpaceShip.h"
     38#include "objects/Projectile.h"
    3839#include "objects/CameraHandler.h"
    3940#include "RadarObject.h"
     
    8788        navMarker_->hide();
    8889        aimMarker_->hide();
     90        aimMarker_->setMaterialName("Orxonox/NavCrosshair");
     91        aimMarker_->setDimensions(20, 20);
     92        aimMarker_->setUV(0.0, 0.0, 1.0, 1.0);
    8993        container_->addChild(navMarker_);
    9094        container_->addChild(aimMarker_);
     
    106110        navText_->setCaption(Ogre::StringConverter::toString(dist));
    107111
    108         Vector3 pos = focus_->getPosition();
    109112        Ogre::Camera* navCam = SpaceShip::getLocalShip()->getCamera()->cam_;
    110113        // transform to screen coordinates
    111         pos = navCam->getProjectionMatrix() * navCam->getViewMatrix() * pos;
     114        Vector3 pos = navCam->getProjectionMatrix() * navCam->getViewMatrix() * focus_->getPosition();
     115        Vector3 aimpos = navCam->getProjectionMatrix() * navCam->getViewMatrix() * getPredictedPosition(SpaceShip::getLocalShip()->getPosition(), Projectile::getSpeed(), focus_->getPosition(), focus_->getOrientedVelocity());
    112116
    113117        float xPosRel = 0.5*pos.x+0.5;
    114118        float yPosRel = 1-(0.5*pos.y+0.5);
     119        float xAimPosRel = 0.5*aimpos.x+0.5;
     120        float yAimPosRel = 1-(0.5*aimpos.y+0.5);
    115121        int xPos = (int) (xPosRel*windowW);
    116122        int yPos = (int) (yPosRel*windowH);
     123        int xAimPos = (int) (xAimPosRel*windowW);
     124        int yAimPos = (int) (yAimPosRel*windowH);
    117125        int xFromCenter = xPos-windowW/2;
    118126        int yFromCenter = yPos-windowH/2;
     
    133141            navMarker_->setMaterialName("Orxonox/NavArrows");
    134142            navMarker_->setDimensions(16,16);
     143            aimMarker_->hide();
    135144            float phiUpperCorner = atan((float)(windowW)/(float)(windowH));
    136145            // from the angle we find out on which edge to draw the marker
     
    210219            // object is in view
    211220            navMarker_->setMaterialName("Orxonox/NavTDC");
    212             navMarker_->setDimensions(24,24);
     221            navMarker_->setDimensions(35, 35);
    213222            navMarker_->setUV(0.0, 0.0, 1.0, 1.0);
    214223            navMarker_->setPosition(xPos-navMarker_->getWidth()/2, yPos-navMarker_->getHeight()/2);
     224
     225            aimMarker_->show();
     226            aimMarker_->setPosition(xAimPos-aimMarker_->getWidth()/2, yAimPos-aimMarker_->getHeight()/2);
     227
    215228            navText_->setPosition(xPos+navMarker_->getWidth()/2, yPos+navMarker_->getHeight()/2);
    216229        }
     
    259272        if(focus_ == NULL){
    260273            navMarker_->hide();
     274            aimMarker_->hide();
    261275            navText_->hide();
    262276        }
  • code/trunk/src/orxonox/hud/RadarObject.cc

    r1564 r1566  
    120120    }
    121121
    122     const Vector3& RadarObject::getVelocity() const
     122    Vector3 RadarObject::getOrientedVelocity() const
    123123    {
    124         return this->object_->getVelocity();
     124        return this->object_->getOrientation() * this->object_->getVelocity();
    125125    }
    126126}
  • code/trunk/src/orxonox/hud/RadarObject.h

    r1564 r1566  
    5454
    5555        const Vector3& getPosition() const;
    56         const Vector3& getVelocity() const;
     56        Vector3 getOrientedVelocity() const;
    5757
    5858        inline WorldEntity* getObject() const
  • code/trunk/src/orxonox/objects/SpaceShipAI.cc

    r1564 r1566  
    238238        this->setMovePitch(0.8 * sgn(coord.y));
    239239
    240         if ((this->targetPosition_ - this->getPosition()).length() > 300)
     240        if ((this->targetPosition_ - this->getPosition()).length() > 500)
    241241            this->setMoveLongitudinal(0.8);
    242242
     
    287287            return;
    288288
    289         Vector3 enemymovement = this->target_->getVelocity();
    290         Vector3 distance_normalised = this->target_->getPosition() - this->getPosition();
    291         distance_normalised.normalise();
    292 
    293         float scalarprod = enemymovement.dotProduct(distance_normalised);
    294         float aimoffset = scalarprod*scalarprod + Projectile::getSpeed() * Projectile::getSpeed() - this->target_->getVelocity().squaredLength();
    295 
    296         if (aimoffset < 0)
    297         {
    298             this->bHasTargetPosition_ = false;
    299             return;
    300         }
    301         aimoffset = -scalarprod + sqrt(aimoffset);
    302         this->targetPosition_ = this->getPosition() + enemymovement + distance_normalised * aimoffset;
    303         this->bHasTargetPosition_ = true;
     289        this->targetPosition_ = getPredictedPosition(this->getPosition(), Projectile::getSpeed(), this->target_->getPosition(), this->target_->getOrientation() * this->target_->getVelocity());
     290        this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
    304291    }
    305292
  • code/trunk/src/util/Math.cc

    r1564 r1566  
    106106        return orxonox::Vector2(-sin(angle) * radius, cos(angle) * radius);
    107107}
     108
     109orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity)
     110{
     111    float squaredProjectilespeed = projectilespeed * projectilespeed;
     112    orxonox::Vector3 distance = targetposition - myposition;
     113    float a = distance.squaredLength();
     114    float b = 2 * (distance.x + distance.y + distance.z) * (targetvelocity.x + targetvelocity.y + targetvelocity.z);
     115    float c = targetvelocity.squaredLength();
     116
     117    float temp = 4*squaredProjectilespeed*c + a*a - 4*b*c;
     118    if (temp < 0)
     119        return orxonox::Vector3::ZERO;
     120
     121    temp = sqrt(temp);
     122    float time = (temp + a) / (2 * (squaredProjectilespeed - b));
     123    return (targetposition + targetvelocity * time);
     124}
  • code/trunk/src/util/Math.h

    r1564 r1566  
    6262_UtilExport orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
    6363_UtilExport orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
     64_UtilExport orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity);
    6465
    6566template <typename T>
Note: See TracChangeset for help on using the changeset viewer.