Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11777


Ignore:
Timestamp:
Feb 19, 2018, 10:32:12 PM (6 years ago)
Author:
landauf
Message:

[Waypoints_HS17] removed lots of copy-paste- and otherwise unnecessary code

Location:
code/branches/Presentation_HS17_merge
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Presentation_HS17_merge/data/levels/ArrowLevel.oxw

    r11774 r11777  
    6060       <Model scale="10" mesh="arrow.mesh"/>
    6161      </attached>
     62      <controller>
     63        <ArrowController accuracy = 2000>
     64          <gpspoints>
     65            <Model mesh="cube.mesh" scale=8 position="100,100,100"/>
     66            <Model mesh="cube.mesh" scale=8 position="400,200,187"/>
     67            <Model mesh="cube.mesh" scale=8 position="-200,-500,615"/>
     68            <Model mesh="cube.mesh" scale=8 position="0,0,0"/>     
     69          </gpspoints>
     70        </ArrowController>
     71      </controller>
    6272    </Arrow>
    6373
    64 <ArrowController accuracy = 2000>
    65       <gpspoints>
    66         <Model mesh="cube.mesh" scale=8 position="100,100,100"/>
    67         <Model mesh="cube.mesh" scale=8 position="400,200,187"/>
    68         <Model mesh="cube.mesh" scale=8 position="-200,-500,615"/>
    69         <Model mesh="cube.mesh" scale=8 position="0,0,0"/>     
    70       </gpspoints>
    71         </ArrowController>
    7274
    7375
  • code/branches/Presentation_HS17_merge/src/orxonox/controllers/ArrowController.cc

    r11774 r11777  
    2121 *
    2222 *   Author:
    23  *      Oli Scheuss
     23 *      jostoffe
    2424 *   Co-authors:
    25  *      Damian 'Mozork' Frick
     25 *      ...
    2626 *
    2727 */
     
    2929#include "ArrowController.h"
    3030#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"
    3434#include "util/Math.h"
    3535
     
    3939    RegisterClass(ArrowController);
    4040
    41 
    42 
    43     /**
    44     @brief
    45         Constructor.
    46     */
    4741    ArrowController::ArrowController(Context* context) : Controller(context)
    4842    {
     
    5246        this->currentGPSPoint_ = 0;
    5347        this->accuracy_ = 1000.0f;
     48    }
    5449
    55         arrow = nullptr;
     50    ArrowController::~ArrowController()
     51    {
     52      for (WorldEntity* gpspoint : this->gpspoints_)
     53        {
     54            if(gpspoint)
     55                gpspoint->destroy();
     56        }
    5657
    57         for(Arrow* a: ObjectList<Arrow>())
    58             arrow = a;
     58    }
    5959
    60         assert(arrow != nullptr);
    61         this->setControllableEntity(arrow);
    62 
    63         orxout() << "constructor aufgerufen" << endl;
    64     }
    65    
    6660    //Set the distance you need to reach before the next waypoint will be selected
    6761    void ArrowController::setAccuracy(float accuracy){
     
    8579            return nullptr;
    8680    }
    87     /**
    88     @brief
    89         Destructor.
    90     */
    91 
    92     ArrowController::~ArrowController()
    93     {
    94       for (WorldEntity* gpspoint : this->gpspoints_)
    95         {
    96             if(gpspoint)
    97                 gpspoint->destroy();
    98         }
    99 
    100     }
    101 
    10281
    10382    void ArrowController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
  • code/branches/Presentation_HS17_merge/src/orxonox/controllers/ArrowController.h

    r11774 r11777  
    2121 *
    2222 *   Author:
    23  *      Oli Scheuss
     23 *      jostoffe
    2424 *   Co-authors:
    25  *      Damian 'Mozork' Frick
     25 *      ...
    2626 *
    2727 */
     
    3838namespace orxonox
    3939{
    40     /**
    41     @brief
    42         Controller for the Arrow of the PPS tutorial.
    43     @author
    44         Oli Scheuss
    45     */
    4640    class _OrxonoxExport ArrowController : public Controller, public Tickable
    4741    {
     
    5953            virtual void tick(float dt); //!< The controlling happens here. This method defines what the controller has to do each tick.
    6054
    61         protected:
    62 
     55        private:
    6356            std::vector<WeakPtr<WorldEntity>> gpspoints_;
    6457            size_t currentGPSPoint_;
    6558            float accuracy_;
    66             WorldEntity* defaultGPSpoint_;
    67 
    68         private:
    69             Arrow *arrow;
    7059    };
    7160}
  • code/branches/Presentation_HS17_merge/src/orxonox/worldentities/Arrow.cc

    r11774 r11777  
    2121 *
    2222 *   Author:
    23  *      Oli Scheuss
     23 *      jostoffe
    2424 *   Co-authors:
    25  *      Damian 'Mozork' Frick
     25 *      ...
    2626 *
    2727 */
     
    3030
    3131#include "core/CoreIncludes.h"
    32 #include "BulletDynamics/Dynamics/btRigidBody.h"
    3332
    3433namespace orxonox
     
    3635
    3736    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
    4438    Arrow::Arrow(Context* context) : ControllableEntity(context)
    4539    {
    4640        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        
    5741    }
    58 
    59     /**
    60     @brief
    61         Destructor. Destroys controller, if present.
    62     */
    63     Arrow::~Arrow()
    64     {
    65 
    66     }
    67 
    68     /**
    69     @brief
    70         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 class
    75         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     @brief
    85         Defines which actions the Arrow has to take in each tick.
    86     @param dt
    87         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         else
    98             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     @brief
    109         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 value
    111         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     @brief
    120         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 value
    122         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     @brief
    131         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 value
    133         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     @brief
    142         Rotates the Arrow around the y-axis by the amount specified by the first component of the input 2-dim vector.
    143     @param value
    144         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     @brief
    153         Rotates the Arrow around the x-axis by the amount specified by the first component of the input 2-dim vector.
    154     @param value
    155         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     @brief
    164         Rotates the Arrow around the z-axis by the amount specified by the first component of the input 2-dim vector.
    165     @param value
    166         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 
    17442}
  • code/branches/Presentation_HS17_merge/src/orxonox/worldentities/Arrow.h

    r11774 r11777  
    2121 *
    2222 *   Author:
    23  *      Oli Scheuss
     23 *      jostoffe
    2424 *   Co-authors:
    25  *      Damian 'Mozork' Frick
     25 *      ...
    2626 *
    2727 */
     
    3333
    3434#include "core/XMLPort.h"
    35 //#include "controllers/ArrowController.h"
    3635
    3736#include "ControllableEntity.h"
    38 #include "WorldEntity.h"
    3937
    4038namespace orxonox {
    4139
    42     /**
    43     @brief
    44         Drone, that is made to move upon a specified pattern.
    45         This class was constructed for the PPS tutorial.
    46     @author
    47         Oli Scheuss
    48     */
    4940    class _OrxonoxExport Arrow : public ControllableEntity
    5041    {
    5142        public:
    5243            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;
    14345    };
    14446
Note: See TracChangeset for help on using the changeset viewer.