Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.cc @ 11834

Last change on this file since 11834 was 11834, checked in by dreherm, 6 years ago

Update for ghost controller and ghost class

  • Property svn:executable set to *
File size: 6.3 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 *      Oli Scheuss
24 *   Co-authors:
25 *      Damian 'Mozork' Frick
26 *
27 */
28
29#include "PacmanGhost.h"
30
31#include "core/CoreIncludes.h"
32#include "BulletDynamics/Dynamics/btRigidBody.h"
33
34namespace orxonox
35{
36    RegisterClass(PacmanGhost);
37
38    /**
39    @brief
40        Constructor. Registers the object and initializes some default values.
41    @param creator
42        The creator of this object.
43    */
44    PacmanGhost::PacmanGhost(Context* context) : ControllableEntity(context)
45    {
46        RegisterObject(PacmanGhost);
47
48        this->myController_ = NULL;
49
50        this->localLinearAcceleration_.setValue(0, 0, 0);
51        this->localAngularAcceleration_.setValue(0, 0, 0);
52
53        this->setCollisionType(CollisionType::Dynamic);
54
55        Vector3 resetposition = new Vector3(0,0,0); //Set Default start position
56
57    }
58
59    /**
60    @brief
61        Destructor. Destroys controller, if present.
62    */
63    PacmanGhost::~PacmanGhost()
64    {
65        // Deletes the controller if the object was initialized and the pointer to the controller is not NULL.
66        if( this->isInitialized() && this->myController_ != NULL )
67            delete this->myController_;
68    }
69
70    /**
71    @brief
72        Method for creating a AutonomousDrone through XML.
73    */
74    void PacmanGhost::XMLPort(Element& xmlelement, XMLPort::Mode mode)
75    {
76        // This calls the XMLPort function of the parent class
77        SUPER(PacmanGhost, XMLPort, xmlelement, mode);
78
79        XMLPortParam(PacmanGhost, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);
80        XMLPortParam(PacmanGhost, "auxilliaryThrust", setAuxillaryThrust, getAuxillaryThrust, xmlelement, mode);
81        XMLPortParam(PacmanGhost, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode);
82        XMLPortParam(PacmanGhost, "resetposition", setResetPosition, getResetPosition, xmlelement, mode);
83    }
84
85    /**
86    @brief
87        Defines which actions the AutonomousDrone has to take in each tick.
88    @param dt
89        The length of the tick.
90    */
91    void PacmanGhost::tick(float dt)
92    {
93        SUPER(PacmanGhost, tick, dt);
94
95        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxiliaryThrust_);
96        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxiliaryThrust_);
97        if (this->localLinearAcceleration_.z() > 0)
98            this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxiliaryThrust_);
99        else
100            this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
101        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
102        this->localLinearAcceleration_.setValue(0, 0, 0);
103
104        this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
105        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
106        this->localAngularAcceleration_.setValue(0, 0, 0);
107
108    }
109
110    /**
111    @brief
112        Moves the AutonomousDrone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector.
113    @param value
114        The vector determining the amount of the movement.
115    */
116    void PacmanGhost::moveFrontBack(const Vector2& value)
117    {
118        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
119    }
120
121    /**
122    @brief
123        Moves the AutonomousDrone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector.
124    @param value
125        The vector determining the amount of the movement.
126    */
127    void PacmanGhost::moveRightLeft(const Vector2& value)
128    {
129        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
130    }
131
132    /**
133    @brief
134        Moves the AutonomousDrone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.
135    @param value
136        The vector determining the amount of the movement.
137    */
138    void PacmanGhost::moveUpDown(const Vector2& value)
139    {
140        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
141    }
142
143    /**
144    @brief
145        Rotates the AutonomousDrone around the y-axis by the amount specified by the first component of the input 2-dim vector.
146    @param value
147        The vector determining the amount of the angular movement.
148    */
149    void PacmanGhost::rotateYaw(const Vector2& value)
150    {
151        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);
152    }
153
154    /**
155    @brief
156        Rotates the AutonomousDrone around the x-axis by the amount specified by the first component of the input 2-dim vector.
157    @param value
158        The vector determining the amount of the angular movement.
159    */
160    void PacmanGhost::rotatePitch(const Vector2& value)
161    {
162        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
163    }
164
165    /**
166    @brief
167        Rotates the AutonomousDrone around the z-axis by the amount specified by the first component of the input 2-dim vector.
168    @param value
169        The vector determining the amount of the angular movement.
170    */
171    void PacmanGhost::rotateRoll(const Vector2& value)
172    {
173        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
174    }
175
176}
Note: See TracBrowser for help on using the repository browser.