Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mac_osx2/src/modules/weapons/RocketController.cc @ 10577

Last change on this file since 10577 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 3.5 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    }
53
54
55    /**
56    @brief
57    The controlling happens here. This method defines what the controller has to do each tick.
58    @param dt
59    The duration of the tick.
60    */
61    void RocketController::tick(float dt)
62    {
63
64        if (this->target_ && this->rocket_->hasFuel()) {
65            this->setTargetPosition();
66            this->moveToTargetPosition();
67        }
68
69
70    }
71
72
73    RocketController::~RocketController()
74    {
75        COUT(5)<< "RocketController destroyed\n";
76    }
77
78    void RocketController::setTargetPosition()
79    {
80        this->targetPosition_=this->target_->getWorldPosition(); //don't really note a difference in the rocket behaviour xD
81        //this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(),this->getControllableEntity()->getVelocity().length() , this->target_->getWorldPosition(), this->target_->getVelocity());
82    }
83    void RocketController::moveToTargetPosition()
84    {
85        this->moveToPosition(this->targetPosition_);
86    }
87
88
89
90    void RocketController::setTarget(WorldEntity* target)
91    {
92        this->target_ = target;
93    }
94
95    void RocketController::moveToPosition(const Vector3& target)
96    {
97        if (!this->getControllableEntity())
98            return;
99
100        Vector2 coord = get2DViewdirection(this->rocket_->getPosition(), this->rocket_->getOrientation() * WorldEntity::FRONT, this->rocket_->getOrientation() * WorldEntity::UP, target);
101        float distance = (target - this->rocket_->getWorldPosition()).length();
102
103
104        if (distance > 1000 && this->rocket_->getVelocity().squaredLength()<160000)
105            this->rocket_->setAcceleration(this->rocket_->getOrientation()*Vector3(-20,-20,-20));
106        if (distance <1000) this->rocket_->setAcceleration(0,0,0);
107
108        this->rocket_->rotateYaw(-sgn(coord.x)*coord.x*coord.x);
109        this->rocket_->rotatePitch(sgn(coord.y)*coord.y*coord.y);
110    }
111
112
113
114
115}
Note: See TracBrowser for help on using the repository browser.