- Timestamp:
- Apr 12, 2018, 4:12:25 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/3DPacman_FS18/src/modules/Pacman/PacmanPointSphere.cc
r11844 r11859 27 27 */ 28 28 29 #include "Pacman Ghost.h"29 #include "PacmanPointSphere.h" 30 30 31 31 #include "core/CoreIncludes.h" … … 34 34 namespace orxonox 35 35 { 36 RegisterClass(Pacman Ghost);36 RegisterClass(PacmanPointSphere); 37 37 38 38 /** … … 42 42 The creator of this object. 43 43 */ 44 Pacman Ghost::PacmanGhost(Context* context) : ControllableEntity(context)44 PacmanPointSphere::PacmanPointSphere(Context* context) : ControllableEntity(context) 45 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 this->primaryThrust_ = 100; 53 this->auxiliaryThrust_ = 100; 54 this->rotationThrust_ = 10; 55 56 this->setCollisionType(CollisionType::Dynamic); 46 RegisterObject(PacmanPointSphere); 47 this->setCollisionType(CollisionType::none); 57 48 } 58 49 … … 61 52 Destructor. Destroys controller, if present. 62 53 */ 63 Pacman Ghost::~PacmanGhost()54 PacmanPointSphere::~PacmanPointSphere() 64 55 { 65 56 // 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 57 } 69 58 … … 72 61 Method for creating a AutonomousDrone through XML. 73 62 */ 74 void Pacman Ghost::XMLPort(Element& xmlelement, XMLPort::Mode mode)63 void PacmanPointSphere::XMLPort(Element& xmlelement, XMLPort::Mode mode) 75 64 { 76 // This calls the XMLPort function of the parent class 77 SUPER(PacmanGhost, XMLPort, xmlelement, mode); 65 SUPER(PacmanPointSphere, XMLPort, xmlelement, mode); 78 66 79 XMLPortParam(PacmanGhost, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode); 80 // Make sure you add the variables auxiliaryThrust_ and rotationThrust_ to XMLPort. 81 // Variables can be added by the following command 82 // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunctionName, getFunctionName, xmlelement, mode); 83 // Also make sure that you also create the get- and set-functions in AutonomousDrone.h. As you can see, the get- and set-functions for the variable primaryThrust_ has already been specified there, so you can get your inspiration from there. 67 XMLPortParam(PacmanPointSphere, "resetposition", setResetPosition, getResetPosition, xmlelement, mode); 84 68 } 85 69 86 /** 87 @brief 88 Defines which actions the AutonomousDrone has to take in each tick. 89 @param dt 90 The length of the tick. 91 */ 92 void PacmanGhost::tick(float dt) 70 71 void PacmanPointSphere::tick(float dt) 93 72 { 94 73 SUPER(PacmanGhost, tick, dt); 95 96 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxiliaryThrust_);97 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxiliaryThrust_);98 if (this->localLinearAcceleration_.z() > 0)99 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxiliaryThrust_);100 else101 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);102 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);103 this->localLinearAcceleration_.setValue(0, 0, 0);104 105 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;106 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);107 this->localAngularAcceleration_.setValue(0, 0, 0);108 109 74 } 110 75 111 /** 112 @brief 113 Moves the AutonomousDrone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector. 114 @param value 115 The vector determining the amount of the movement. 116 */ 117 void PacmanGhost::moveFrontBack(const Vector2& value) 76 bool PacmanPointSphere::taken(Vector3 playerpos) 118 77 { 119 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 78 if((abs(this->resetposition.x - playerpos.x)<0.1) && (abs(this->resetposition.z - playerpos.z)<0.1)){ 79 this->setPosition(Vector3(resetposition.x, -50, resetposition.z)); 80 return true; 81 } 82 83 return false; 120 84 } 121 85 122 /** 123 @brief 124 Moves the AutonomousDrone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector. 125 @param value 126 The vector determining the amount of the movement. 127 */ 128 void PacmanGhost::moveRightLeft(const Vector2& value) 129 { 130 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 86 87 void PacmanPointSphere::resetPacmanPointSphere(){ 88 this->setPosition(resetposition); 131 89 } 132 133 /**134 @brief135 Moves the AutonomousDrone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.136 @param value137 The vector determining the amount of the movement.138 */139 void PacmanGhost::moveUpDown(const Vector2& value)140 {141 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);142 }143 144 /**145 @brief146 Rotates the AutonomousDrone around the y-axis by the amount specified by the first component of the input 2-dim vector.147 @param value148 The vector determining the amount of the angular movement.149 */150 void PacmanGhost::rotateYaw(const Vector2& value)151 {152 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);153 }154 155 /**156 @brief157 Rotates the AutonomousDrone around the x-axis by the amount specified by the first component of the input 2-dim vector.158 @param value159 The vector determining the amount of the angular movement.160 */161 void PacmanGhost::rotatePitch(const Vector2& value)162 {163 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);164 }165 166 /**167 @brief168 Rotates the AutonomousDrone around the z-axis by the amount specified by the first component of the input 2-dim vector.169 @param value170 The vector determining the amount of the angular movement.171 */172 void PacmanGhost::rotateRoll(const Vector2& value)173 {174 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);175 }176 177 90 }
Note: See TracChangeset
for help on using the changeset viewer.