Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6905


Ignore:
Timestamp:
May 15, 2010, 6:12:13 PM (14 years ago)
Author:
gnadler
Message:

rockets get target but moveToPosition function does not work correctly.

Location:
code/branches/rocket/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/rocket/src/modules/weapons/RocketController.cc

    r6904 r6905  
    6363    {
    6464                haha++;
     65               
    6566
    6667        SimpleRocket *rocket = static_cast<SimpleRocket*>(this->getControllableEntity());
     68                if (haha<30)rocket->setVelocity(rocket->getVelocity()*1.03);
    6769                if (this->target_) {
    68                 rocket->rotatePitch(0.5);
    69                 rocket->rotateYaw(0.5);
     70                        this->setTargetPosition();
     71                        this->moveToTargetPosition();
     72               
    7073                }
    71                 rocket->setVelocity(rocket->getVelocity()*1.03);
     74               
     75                if (haha>500) rocket->setDestroy();;
    7276       
    7377        }
     
    8084        }
    8185
     86        void RocketController::setTargetPosition() {
     87                this->targetPosition_=this->target_->getPosition();
     88                //this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getPosition(),this->getControllableEntity()->getVelocity().length() , this->target_->getPosition(), this->target_->getVelocity());
     89        }
     90        void RocketController::moveToTargetPosition() {
     91                this->moveToPosition(this->targetPosition_);
     92        }
    8293
    83         void RocketController::setTarget(Pawn* target) {
     94
     95
     96        void RocketController::setTarget(WorldEntity* target) {
    8497                this->target_ = target;
     98                COUT(0)<<"got target\n";
    8599        }
     100
     101        void RocketController::moveToPosition(const Vector3& target)
     102    {
     103       if (!this->getControllableEntity())
     104            return;
     105
     106           COUT(0)<<"moving";
     107
     108        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     109        float distance = (target - this->getControllableEntity()->getPosition()).length();
     110
     111        if (this->target_ || distance > 10)
     112        {
     113            // Multiply with 0.8 to make them a bit slower
     114                         this->getControllableEntity()->rotateYaw(-0.2f * sgn(coord.x) * coord.x*coord.x);
     115            this->getControllableEntity()->rotatePitch(0.2f * sgn(coord.y) * coord.y*coord.y);
     116                       
     117        }
     118    }
    86119
    87120
  • code/branches/rocket/src/modules/weapons/RocketController.h

    r6903 r6905  
    5353            virtual void tick(float dt);
    5454                        SimpleRocket* getRocket(){return this->rocket;};
    55                         void setTarget(Pawn* target);
     55                        void setTarget(WorldEntity* target);
    5656        protected:
    57 
     57                        void moveToPosition(const Vector3& target);
     58                        void setTargetPosition();
     59                        void moveToTargetPosition();
    5860
    5961        private:
    6062                        SimpleRocket* rocket;
     63                        Vector3 targetPosition_;
    6164                        WeakPtr<PlayerInfo> player_;
    6265                                                int haha;
    63                         WeakPtr<Pawn> target_;
     66                        WeakPtr<WorldEntity> target_;
    6467
    6568
  • code/branches/rocket/src/modules/weapons/projectiles/SimpleRocket.cc

    r6902 r6905  
    180180        }
    181181    }
     182        void SimpleRocket::setDestroy() {
     183                this->bDestroy_=true;
     184                COUT(0)<<"trying to destroy";
     185        }
    182186
    183187    void SimpleRocket::fired(unsigned int firemode)
  • code/branches/rocket/src/modules/weapons/projectiles/SimpleRocket.h

    r6900 r6905  
    6464            virtual void rotatePitch(const Vector2& value);
    6565            virtual void rotateRoll(const Vector2& value);
     66                        void setDestroy();
    6667
    6768            /**
     
    9596            */
    9697            inline void rotatePitch(float value)
    97             { this->rotatePitch(Vector2(value, 0)); }
     98            {   COUT(0)<<"rotated rocket yaw";
     99                                this->rotatePitch(Vector2(value, 0)); }
    98100            /**
    99101            @brief Rotates the SimpleRocket around the z-axis by the specifed amount.
     
    101103            */
    102104            inline void rotateRoll(float value)
    103             { this->rotateRoll(Vector2(value, 0)); }
     105            {
     106                                COUT(0)<<"rotated rocket roll";
     107                                this->rotateRoll(Vector2(value, 0)); }
    104108
    105109            void setOwner(Pawn* owner);
  • code/branches/rocket/src/modules/weapons/weaponmodes/SimpleRocketFire.cc

    r6900 r6905  
    6969                rocket->setVelocity(this->getMuzzleDirection()*this->speed_);
    7070                rocket->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
     71                rocket->setDamage(this->damage_);
     72                WorldEntity* pawnn=(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getTarget());
     73                if (pawnn) {
     74                con->setTarget(pawnn);
     75                }
    7176    }
    7277}
  • code/branches/rocket/src/orxonox/controllers/DroneController.cc

    r6903 r6905  
    4949        assert(dynamic_cast<Drone*>(creator)!=0);
    5050        this->setControllableEntity(dynamic_cast<Drone*>(creator));
     51                this->counter=0;
    5152    }
    5253
     
    6364    void DroneController::tick(float dt)
    6465    {
     66                this->counter++;
    6567        // Place your code here:
    6668        // - steering commands
     
    7072        // - rotatePitch, rotateYaw, rotateRoll
    7173        // - apply the to myDrone (e.g. myDrone->rotateYaw(..) )
    72 
    73                 myDrone->rotateYaw(0.2);
     74                myDrone->rotatePitch(0.08);
     75                myDrone->moveFrontBack(1);
    7476
    7577    }
  • code/branches/rocket/src/orxonox/controllers/DroneController.h

    r6778 r6905  
    5454
    5555        private:
     56                        int counter;
    5657    };
    5758}
  • code/branches/rocket/src/orxonox/controllers/NewHumanController.cc

    r6903 r6905  
    574574        }
    575575    }
    576 
    577         Pawn* NewHumanController::getRocketTarget() {
    578 
    579 
    580  Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
    581 
    582         Ogre::Ray mouseRay = HumanController::localController_s->getControllableEntity()->getCamera()->getOgreCamera()->getCameraToViewportRay(static_cast<float>(this->currentYaw_)/2*-1+.5f, static_cast<float>(this->currentPitch_)/2*-1+.5f);
    583 
    584         rsq->setRay(mouseRay);
    585         rsq->setSortByDistance(true);
    586 
    587         /*
    588         Distance of objects:
    589         ignore everything under 200 maybe even take 1000 as min distance to shoot at
    590 
    591         shots are regularly traced and are entities!!!!!!!!! this is the biggest problem
    592         they vanish only after a distance of 10'000
    593         */
    594 
    595 
    596         Ogre::RaySceneQueryResult& result = rsq->execute();
    597         Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
    598 
    599         Ogre::RaySceneQueryResult::iterator itr;
    600         for (itr = result.begin(); itr != result.end(); ++itr)
    601         {
    602             if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500)
    603             {
    604                 // Try to cast the user pointer
    605                 WorldEntity* wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
    606                 if (wePtr)
    607                 {
    608                     // go through all parents of object and look whether they are sightable or not
    609                     bool isSightable = false;
    610                     WorldEntity* parent = wePtr->getParent();
    611                     while (parent)
    612                     {
    613                         if (this->targetMask_.isExcluded(parent->getIdentifier()))
    614                         {
    615                             parent = parent->getParent();
    616                             continue;
    617                         }
    618                         else
    619                         {
    620                             isSightable = true;
    621                             break;
    622                         }
    623                     }
    624                     if (!isSightable)
    625                         continue;
    626                 }
    627 
    628                                 return dynamic_cast<Pawn*> (wePtr);
    629                         }
    630                 }
    631         }
    632576               
    633577
  • code/branches/rocket/src/orxonox/controllers/NewHumanController.h

    r6903 r6905  
    6767            virtual void doResumeControl();
    6868
    69                         Pawn* getRocketTarget();
    70 
    7169
    7270        protected:
  • code/branches/rocket/src/orxonox/worldentities/Drone.cc

    r6778 r6905  
    4949        this->myController_ = 0;
    5050       
    51         this->localLinearAcceleration_.setValue(0, 0, 0);
     51        this->localLinearAcceleration_.setValue(1, 1, 1);
    5252        this->localAngularAcceleration_.setValue(0, 0, 0);
    5353        this->primaryThrust_  = 100;
Note: See TracChangeset for help on using the changeset viewer.