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, 15 years ago

merged rocket2 branch back into presentation3 branch

File size: 3.8 KB
Line 
1/*
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*/
28
29#include "RocketController.h"
30#include "projectiles/SimpleRocket.h"
31#include "util/Math.h"
32#include "weapons/projectiles/SimpleRocket.h"
33#include "util/Debug.h"
34#include "weapons/weaponmodes/SimpleRocketFire.h"
35#include "worldentities/pawns/Pawn.h"
36
37namespace orxonox
38{
39    /**
40    @brief
41    Constructor.
42    */
43    RocketController::RocketController(BaseObject* creator) : Controller(creator)
44    {
45        RegisterObject(RocketController);
46        COUT(5)<< "RocketController constructed\n";
47
48
49        this->rocket_ = new SimpleRocket(this);
50        this->rocket_->setController(this);
51        this->setControllableEntity(dynamic_cast<ControllableEntity*> (this->rocket_));
52        this->counter_=0;
53    }
54
55
56    /**
57    @brief
58    The controlling happens here. This method defines what the controller has to do each tick.
59    @param dt
60    The duration of the tick.
61    */
62    void RocketController::tick(float dt)
63    {
64        counter_++;
65
66        if (this->target_ && this->rocket_->hasFuel()) {
67            this->setTargetPosition();
68            this->moveToTargetPosition();
69        }
70       
71       
72    }
73
74
75    RocketController::~RocketController()
76    {
77        COUT(5)<< "RocketController destroyed\n";
78    }
79
80    void RocketController::setTargetPosition()
81    {
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());
84    }
85    void RocketController::moveToTargetPosition()
86    {
87        this->moveToPosition(this->targetPosition_);
88    }
89
90
91
92    void RocketController::setTarget(WorldEntity* target)
93    {
94        this->target_ = target;
95    }
96
97    void RocketController::moveToPosition(const Vector3& target)
98    {
99        if (!this->getControllableEntity())
100            return;
101        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
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);
111    }
112
113
114
115
116}
Note: See TracBrowser for help on using the repository browser.