Changeset 11777 for code/branches/Presentation_HS17_merge/src/orxonox
- Timestamp:
- Feb 19, 2018, 10:32:12 PM (7 years ago)
- Location:
- code/branches/Presentation_HS17_merge/src/orxonox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Presentation_HS17_merge/src/orxonox/controllers/ArrowController.cc
r11774 r11777 21 21 * 22 22 * Author: 23 * Oli Scheuss23 * jostoffe 24 24 * Co-authors: 25 * Damian 'Mozork' Frick25 * ... 26 26 * 27 27 */ … … 29 29 #include "ArrowController.h" 30 30 #include "HumanController.h" 31 #include "worldentities/ WorldEntity.h"32 33 #include " worldentities/Arrow.h"31 #include "worldentities/ControllableEntity.h" 32 33 #include "core/CoreIncludes.h" 34 34 #include "util/Math.h" 35 35 … … 39 39 RegisterClass(ArrowController); 40 40 41 42 43 /**44 @brief45 Constructor.46 */47 41 ArrowController::ArrowController(Context* context) : Controller(context) 48 42 { … … 52 46 this->currentGPSPoint_ = 0; 53 47 this->accuracy_ = 1000.0f; 48 } 54 49 55 arrow = nullptr; 50 ArrowController::~ArrowController() 51 { 52 for (WorldEntity* gpspoint : this->gpspoints_) 53 { 54 if(gpspoint) 55 gpspoint->destroy(); 56 } 56 57 57 for(Arrow* a: ObjectList<Arrow>()) 58 arrow = a; 58 } 59 59 60 assert(arrow != nullptr);61 this->setControllableEntity(arrow);62 63 orxout() << "constructor aufgerufen" << endl;64 }65 66 60 //Set the distance you need to reach before the next waypoint will be selected 67 61 void ArrowController::setAccuracy(float accuracy){ … … 85 79 return nullptr; 86 80 } 87 /**88 @brief89 Destructor.90 */91 92 ArrowController::~ArrowController()93 {94 for (WorldEntity* gpspoint : this->gpspoints_)95 {96 if(gpspoint)97 gpspoint->destroy();98 }99 100 }101 102 81 103 82 void ArrowController::XMLPort(Element& xmlelement, XMLPort::Mode mode) -
code/branches/Presentation_HS17_merge/src/orxonox/controllers/ArrowController.h
r11774 r11777 21 21 * 22 22 * Author: 23 * Oli Scheuss23 * jostoffe 24 24 * Co-authors: 25 * Damian 'Mozork' Frick25 * ... 26 26 * 27 27 */ … … 38 38 namespace orxonox 39 39 { 40 /**41 @brief42 Controller for the Arrow of the PPS tutorial.43 @author44 Oli Scheuss45 */46 40 class _OrxonoxExport ArrowController : public Controller, public Tickable 47 41 { … … 59 53 virtual void tick(float dt); //!< The controlling happens here. This method defines what the controller has to do each tick. 60 54 61 protected: 62 55 private: 63 56 std::vector<WeakPtr<WorldEntity>> gpspoints_; 64 57 size_t currentGPSPoint_; 65 58 float accuracy_; 66 WorldEntity* defaultGPSpoint_;67 68 private:69 Arrow *arrow;70 59 }; 71 60 } -
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 } -
code/branches/Presentation_HS17_merge/src/orxonox/worldentities/Arrow.h
r11774 r11777 21 21 * 22 22 * Author: 23 * Oli Scheuss23 * jostoffe 24 24 * Co-authors: 25 * Damian 'Mozork' Frick25 * ... 26 26 * 27 27 */ … … 33 33 34 34 #include "core/XMLPort.h" 35 //#include "controllers/ArrowController.h"36 35 37 36 #include "ControllableEntity.h" 38 #include "WorldEntity.h"39 37 40 38 namespace orxonox { 41 39 42 /**43 @brief44 Drone, that is made to move upon a specified pattern.45 This class was constructed for the PPS tutorial.46 @author47 Oli Scheuss48 */49 40 class _OrxonoxExport Arrow : public ControllableEntity 50 41 { 51 42 public: 52 43 Arrow(Context* context); 53 virtual ~Arrow(); 54 55 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating an Arrow through XML. 56 virtual void tick(float dt); //!< Defines which actions the Arrow has to take in each tick. 57 58 virtual void moveFrontBack(const Vector2& value); 59 virtual void moveRightLeft(const Vector2& value); 60 virtual void moveUpDown(const Vector2& value); 61 62 virtual void rotateYaw(const Vector2& value); 63 virtual void rotatePitch(const Vector2& value); 64 virtual void rotateRoll(const Vector2& value); 65 66 /** 67 @brief Moves the Drone in the Front/Back-direction by the specifed amount. 68 @param value The amount by which the drone is to be moved. 69 */ 70 inline void moveFrontBack(float value) 71 { this->moveFrontBack(Vector2(value, 0)); } 72 /** 73 @brief Moves the Drone in the Right/Left-direction by the specifed amount. 74 @param value The amount by which the drone is to be moved. 75 */ 76 inline void moveRightLeft(float value) 77 { this->moveRightLeft(Vector2(value, 0)); } 78 /** 79 @brief Moves the Drone in the Up/Down-direction by the specifed amount. 80 @param value The amount by which the drone is to be moved. 81 */ 82 inline void moveUpDown(float value) 83 { this->moveUpDown(Vector2(value, 0)); } 84 85 /** 86 @brief Rotates the Drone around the y-axis by the specifed amount. 87 @param value The amount by which the drone is to be rotated. 88 */ 89 inline void rotateYaw(float value) 90 { this->rotateYaw(Vector2(value, 0)); } 91 /** 92 @brief Rotates the Drone around the x-axis by the specifed amount. 93 @param value The amount by which the drone is to be rotated. 94 */ 95 inline void rotatePitch(float value) 96 { this->rotatePitch(Vector2(value, 0)); } 97 /** 98 @brief Rotates the Drone around the z-axis by the specifed amount. 99 @param value The amount by which the drone is to be rotated. 100 */ 101 inline void rotateRoll(float value) 102 { this->rotateRoll(Vector2(value, 0)); } 103 104 /** 105 @brief Sets the primary thrust to the input amount. 106 @param thrust The amount of thrust. 107 */ 108 inline void setPrimaryThrust( float thrust ) 109 { this->primaryThrust_ = thrust; } 110 //TODO: Place your set-functions here. 111 112 inline void setAuxiliaryThrust ( float thrust ) 113 { this -> auxiliaryThrust_ = thrust; } 114 115 inline void setRotationThrust (float thrust) 116 { this -> rotationThrust_ = thrust;} 117 // Hint: auxiliary thrust, rotation thrust. 118 119 /** 120 @brief Gets the primary thrust to the input amount. 121 @return The amount of thrust. 122 */ 123 inline float getPrimaryThrust() 124 { return this->primaryThrust_; } 125 126 inline float getAuxiliaryThrust() 127 { return this->auxiliaryThrust_;} 128 129 inline float getRotationThrust() 130 { return this->rotationThrust_;} 131 132 //TODO: Place your get-functions here. 133 134 private: 135 //ArrowController *myController_; //!< The controller of the Arrow. 136 137 btVector3 localLinearAcceleration_; //!< The linear acceleration that is used to move the Arrow the next tick. 138 btVector3 localAngularAcceleration_; //!< The linear angular acceleration that is used to move the Arrow the next tick. 139 float primaryThrust_; //!< The amount of primary thrust. This is just used, when moving forward. 140 float auxiliaryThrust_; //!< The amount of auxiliary thrust. Used for all other movements (except for rotations). 141 float rotationThrust_; //!< The amount of rotation thrust. Used for rotations only.s 142 44 virtual ~Arrow() = default; 143 45 }; 144 46
Note: See TracChangeset
for help on using the changeset viewer.