Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation3/src/modules/weapons/RocketController.cc @ 7019

Last change on this file since 7019 was 7018, checked in by scheusso, 14 years ago

merged rocket2 branch back into presentation3 branch

File size: 3.8 KB
RevLine 
[6803]1/*
[7018]2*   ORXONOX - the hottest 3D action shooter ever to exist
3*                    > www.orxonox.net <
4*
5*
6*   License notice:
7*
8*   This program is free software; you can redistribute it and/or
9*   modify it under the terms of the GNU General Public License
10*   as published by the Free Software Foundation; either version 2
11*   of the License, or (at your option) any later version.
12*
13*   This program is distributed in the hope that it will be useful,
14*   but WITHOUT ANY WARRANTY; without even the implied warranty of
15*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*   GNU General Public License for more details.
17*
18*   You should have received a copy of the GNU General Public License
19*   along with this program; if not, write to the Free Software
20*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21*
22*   Author:
23*     Gabriel Nadler, Originalfile: Oli Scheuss
24*   Co-authors:
25*      ...
26*
27*/
[6803]28
29#include "RocketController.h"
30#include "projectiles/SimpleRocket.h"
31#include "util/Math.h"
[6810]32#include "weapons/projectiles/SimpleRocket.h"
[6815]33#include "util/Debug.h"
[6834]34#include "weapons/weaponmodes/SimpleRocketFire.h"
[6904]35#include "worldentities/pawns/Pawn.h"
[6803]36
37namespace orxonox
38{
39    /**
40    @brief
[7018]41    Constructor.
[6803]42    */
43    RocketController::RocketController(BaseObject* creator) : Controller(creator)
44    {
[6951]45        RegisterObject(RocketController);
46        COUT(5)<< "RocketController constructed\n";
[6811]47
[7018]48
49        this->rocket_ = new SimpleRocket(this);
50        this->rocket_->setController(this);
51        this->setControllableEntity(dynamic_cast<ControllableEntity*> (this->rocket_));
52        this->counter_=0;
[6803]53    }
54
55
56    /**
57    @brief
[7018]58    The controlling happens here. This method defines what the controller has to do each tick.
[6803]59    @param dt
[7018]60    The duration of the tick.
[6803]61    */
62    void RocketController::tick(float dt)
63    {
[7018]64        counter_++;
[6811]65
[7018]66        if (this->target_ && this->rocket_->hasFuel()) {
[6951]67            this->setTargetPosition();
68            this->moveToTargetPosition();
69        }
[7018]70       
71       
[6951]72    }
[6803]73
74
[6951]75    RocketController::~RocketController()
76    {
77        COUT(5)<< "RocketController destroyed\n";
78    }
[6814]79
[6951]80    void RocketController::setTargetPosition()
81    {
[7018]82        this->targetPosition_=this->target_->getWorldPosition(); //don't really note a difference in the rocket behaviour xD
83        //this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(),this->getControllableEntity()->getVelocity().length() , this->target_->getWorldPosition(), this->target_->getVelocity());
[6951]84    }
85    void RocketController::moveToTargetPosition()
86    {
87        this->moveToPosition(this->targetPosition_);
88    }
[6814]89
[6905]90
91
[6951]92    void RocketController::setTarget(WorldEntity* target)
93    {
94        this->target_ = target;
95    }
[6814]96
[6951]97    void RocketController::moveToPosition(const Vector3& target)
[6905]98    {
[6951]99        if (!this->getControllableEntity())
[6905]100            return;
101        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
[7018]102        float distance = (target - this->getControllableEntity()->getWorldPosition()).length();
103
104
105        if (distance > 1000&&this->getControllableEntity()->getVelocity().squaredLength()<160000) 
106            this->getControllableEntity()->setAcceleration(this->rocket_->getOrientation()*Vector3(-20,-20,-20));
107        if (distance <1000) this->rocket_->setAcceleration(0,0,0);
108       
109        this->getControllableEntity()->rotateYaw(-sgn(coord.x)*coord.x*coord.x);
110        this->getControllableEntity()->rotatePitch(sgn(coord.y)*coord.y*coord.y);
[6905]111    }
112
113
114
115
[6803]116}
Note: See TracBrowser for help on using the repository browser.