- Timestamp:
- Feb 19, 2018, 10:32:12 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Presentation_HS17_merge/src/orxonox/worldentities/Arrow.cc
r11774 r11777 21 21 * 22 22 * Author: 23 * Oli Scheuss23 * jostoffe 24 24 * Co-authors: 25 * Damian 'Mozork' Frick25 * ... 26 26 * 27 27 */ … … 30 30 31 31 #include "core/CoreIncludes.h" 32 #include "BulletDynamics/Dynamics/btRigidBody.h"33 32 34 33 namespace orxonox … … 36 35 37 36 RegisterClass(Arrow); 38 /** 39 @brief 40 Constructor. Registers the object and initializes some default values. 41 @param creator 42 The creator of this object. 43 */ 37 44 38 Arrow::Arrow(Context* context) : ControllableEntity(context) 45 39 { 46 40 RegisterObject(Arrow); 47 48 this->localLinearAcceleration_.setValue(0, 0, 0);49 this->localAngularAcceleration_.setValue(0, 0, 0);50 this->primaryThrust_ = 100;51 this->auxiliaryThrust_ = 100;52 this->rotationThrust_ = 10;53 54 this->setCollisionType(CollisionType::Dynamic);55 56 57 41 } 58 59 /**60 @brief61 Destructor. Destroys controller, if present.62 */63 Arrow::~Arrow()64 {65 66 }67 68 /**69 @brief70 Method for creating a Arrow through XML.71 */72 void Arrow::XMLPort(Element& xmlelement, XMLPort::Mode mode)73 {74 // This calls the XMLPort function of the parent class75 SUPER(Arrow, XMLPort, xmlelement, mode);76 77 XMLPortParam(Arrow, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);78 XMLPortParam(Arrow, "auxiliaryThrust", setAuxiliaryThrust, getAuxiliaryThrust, xmlelement, mode);79 XMLPortParam(Arrow, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode);80 81 }82 83 /**84 @brief85 Defines which actions the Arrow has to take in each tick.86 @param dt87 The length of the tick.88 */89 void Arrow::tick(float dt)90 {91 SUPER(Arrow, tick, dt);92 93 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxiliaryThrust_);94 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxiliaryThrust_);95 if (this->localLinearAcceleration_.z() > 0)96 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxiliaryThrust_);97 else98 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);99 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);100 this->localLinearAcceleration_.setValue(0, 0, 0);101 102 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;103 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);104 this->localAngularAcceleration_.setValue(0, 0, 0);105 }106 107 /**108 @brief109 Moves the Arrow in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector.110 @param value111 The vector determining the amount of the movement.112 */113 void Arrow::moveFrontBack(const Vector2& value)114 {115 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);116 }117 118 /**119 @brief120 Moves the Arrow in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector.121 @param value122 The vector determining the amount of the movement.123 */124 void Arrow::moveRightLeft(const Vector2& value)125 {126 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);127 }128 129 /**130 @brief131 Moves the Arrow in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.132 @param value133 The vector determining the amount of the movement.134 */135 void Arrow::moveUpDown(const Vector2& value)136 {137 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);138 }139 140 /**141 @brief142 Rotates the Arrow around the y-axis by the amount specified by the first component of the input 2-dim vector.143 @param value144 The vector determining the amount of the angular movement.145 */146 void Arrow::rotateYaw(const Vector2& value)147 {148 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);149 }150 151 /**152 @brief153 Rotates the Arrow around the x-axis by the amount specified by the first component of the input 2-dim vector.154 @param value155 The vector determining the amount of the angular movement.156 */157 void Arrow::rotatePitch(const Vector2& value)158 {159 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);160 }161 162 /**163 @brief164 Rotates the Arrow around the z-axis by the amount specified by the first component of the input 2-dim vector.165 @param value166 The vector determining the amount of the angular movement.167 */168 void Arrow::rotateRoll(const Vector2& value)169 {170 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);171 }172 173 174 42 }
Note: See TracChangeset
for help on using the changeset viewer.