Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/particles2/src/orxonox/worldentities/Rocket.cc @ 6059

Last change on this file since 6059 was 6059, checked in by cdaniel, 14 years ago
File size: 6.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 *      Reto Grieder
24 *   Co-authors:
25 *      Martin Stypinski
26 *
27 */
28
29#include "Rocket.h"
30
31#include "core/XMLPort.h"
32#include "BulletDynamics/Dynamics/btRigidBody.h"
33
34namespace orxonox
35{
36        CreateFactory(Rocket);    // put your code in here:
37    // create the factory for the Rocket
38
39    /**
40    @brief
41        Constructor. Registers the object and initializes some default values.
42    */
43    Rocket::Rocket(BaseObject* creator) : ControllableEntity(creator)
44    {
45        this->myController_ = 0;
46        // put your code in here:
47        RegisterObject(Rocket);// - register the Rocket class to the core
48       
49        this->localLinearAcceleration_.setValue(0, 0, 0);
50        this->localAngularAcceleration_.setValue(0, 0, 0);
51        this->primaryThrust_  = 100;
52        this->auxilaryThrust_ = 100;
53        this->rotationThrust_ = 10;
54       
55        this->setCollisionType(WorldEntity::Kinematic);
56       
57        this->myController_ = new RocketController(static_cast<BaseObject*>(this)); //!< Creates a new controller and passes our this pointer to it as creator.
58    }
59
60    /**
61    @brief
62        Destructor. Destroys controller, if present.
63    */
64    Rocket::~Rocket()
65    {
66        if( this->myController_ != NULL )
67            this->myController_->destroy();
68    }
69
70    /**
71    @brief
72        Method for creating a Rocket through XML.
73    */
74    void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
75    {
76        // this calls the XMLPort function of the parent class
77        SUPER(Rocket, XMLPort, xmlelement, mode);
78
79        // put your code in here:
80                XMLPortParam(Rocket, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);
81                //XMLPortParam(Rocket, "auxilaryThrust", setAuxilaryThrust, getAuxilaryThrust, xmlelement, mode);
82                //XMLPortParam(Rocket, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode);
83        // make sure you add the variables primaryThrust_, auxilaryThrust_ and rotationThrust_ to xmlport
84        // make sure that the set- and get-functions exist.
85        // variables can be added by the following command
86        // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunction, getFunction, xmlelement, mode)
87 
88    }
89
90    /**
91    @brief
92        Defines which actions the Rocket has to take in each tick.
93    @param dt
94        The length of the tick.
95    */
96    void Rocket::tick(float dt)
97    {
98        SUPER(Rocket, tick, dt);
99       
100        //if (this->hasLocalController())
101        //{
102            this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
103            this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
104            if (this->localLinearAcceleration_.z() > 0)
105              this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
106            else
107              this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
108            this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
109            this->localLinearAcceleration_.setValue(0, 0, 0);
110       
111            this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
112            this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
113            this->localAngularAcceleration_.setValue(0, 0, 0);
114        //}
115    }
116   
117    /**
118    @brief
119        Moves the Rocket in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector.
120    @param value
121        The vector determining the amount of the movement.
122    */
123    void Rocket::moveFrontBack(const Vector2& value)
124    {
125        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
126    }
127
128    /**
129    @brief
130        Moves the Rocket in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector.
131    @param value
132        The vector determining the amount of the movement.
133    */
134    void Rocket::moveRightLeft(const Vector2& value)
135    {
136        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
137    }
138
139    /**
140    @brief
141        Moves the Rocket in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.
142    @param value
143        The vector determining the amount of the movement.
144    */
145    void Rocket::moveUpDown(const Vector2& value)
146    {
147        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
148    }
149
150    /**
151    @brief
152        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
153    @param value
154        The vector determining the amount of the angular movement.
155    */
156    void Rocket::rotateYaw(const Vector2& value)
157    {
158        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);
159    }
160
161    /**
162    @brief
163        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
164    @param value
165        The vector determining the amount of the angular movement.
166    */
167    void Rocket::rotatePitch(const Vector2& value)
168    {
169        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
170    }
171
172    /**
173    @brief
174        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
175    @param value
176        The vector determining the amount of the angular movement.
177    */
178    void Rocket::rotateRoll(const Vector2& value)
179    {
180        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
181    }
182   
183}
Note: See TracBrowser for help on using the repository browser.