Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/shader_HS18/src/orxonox/controllers/AutonomousDroneController.cc @ 12112

Last change on this file since 12112 was 12028, checked in by merholzl, 6 years ago

added scriptable controller

File size: 3.7 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 "AutonomousDroneController.h"
30
31#include "worldentities/AutonomousDrone.h"
32#include "util/Math.h"
33
34namespace orxonox
35{
36    //TODO: Put your code in here:
37    // Create the factory for the drone controller.
38    RegisterClass(AutonomousDroneController);
39    /**
40    @brief
41        Constructor.
42    @param context
43        The context of this object.
44    */
45    AutonomousDroneController::AutonomousDroneController(Context* context) : Controller(context)
46    {
47        //TODO: Place your code here:
48        // Make sure to register the object and create the factory.       
49        RegisterObject(AutonomousDroneController);
50        // This checks that our context really is a drone
51        // and saves the pointer to the drone for the controlling commands
52        /* NOTE from Sandro: This is currently broken */
53        //AutonomousDrone* drone = dynamic_cast<AutonomousDrone*>(context);
54        //assert(drone != nullptr);
55        //this->setControllableEntity(drone);
56    }
57
58    /**
59    @brief
60        Destructor.
61    */
62    AutonomousDroneController::~AutonomousDroneController()
63    {
64
65    }
66
67    /**
68    @brief
69        The controlling happens here. This method defines what the controller has to do each tick.
70    @param dt
71        The duration of the tick.
72    */
73    void AutonomousDroneController::tick(float dt)
74    {
75
76        static int i = 0;
77       
78        /* NOTE: Ugly hack by Sandro to make the tutorial work for the moment.
79         * This will be reverted once the framework update is complete
80         */
81        //AutonomousDrone *myDrone = static_cast<AutonomousDrone*>(this->getControllableEntity());
82        ObjectList<AutonomousDrone> objectList;
83        ObjectList<AutonomousDrone>::iterator it = objectList.begin();
84        AutonomousDrone* myDrone = *it;
85
86        if (myDrone != nullptr)
87        {
88            //TODO: Place your code here:
89            // Steering commands
90            // You can use the commands provided by the AutonomousDrone to steer it:
91            // - moveFrontBack, moveRightLeft, moveUpDown
92            // - rotatePitch, rotateYaw, rotateRoll
93            // You will see, that the AutonomousDrone has two variants for each of these commands, one with a vector as input and one with just a float. Use the one with just the float as input.
94            // Apply them to myDrone (e.g. myDrone->rotateYaw(..) )
95            // dt is the time passed since the last call of the tick function in seconds.
96            int iMax = 100;
97            double R = 250;
98
99            double x = R * cos(math::twoPi/iMax*i);
100            double y = R * sin(math::twoPi/iMax*i);
101
102           
103            const Vector2 motion1 = Vector2(x,0);
104            const Vector2 motion2 = Vector2(y,0);
105
106           
107            myDrone->moveRightLeft(motion1);
108            myDrone->moveUpDown(motion2);
109           
110            i = (i+1)%iMax;
111               
112
113        }
114    }
115}
Note: See TracBrowser for help on using the repository browser.