Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 26, 2016, 3:54:24 PM (8 years ago)
Author:
plehmann
Message:

implemented the update function of MoveToTask. but it does not yet work right. it might be more a problem of the controllerDirector than the task.

Location:
code/branches/plehmannFS16
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/plehmannFS16/data/gui/scripts/testscript.lua

    r11183 r11204  
    2323if ctrl ~= nil then
    2424
    25   ctrl:printDebug()
    26   ctrl:debugOut(5)
    27   ctrl:stringOut(3, "hello")
     25  ctrl:moveTo(1, 0, 0, 100, 200)
     26  ctrl:moveTo(20, 0, 0, 100, 200)
     27  ctrl:moveTo(40, 0, 100, 0, 200)
    2828  --ctrl:eventScheduler("mal", xl,yl,zl, xl,yl,zl, 10)
    2929  -- ctrl:eventScheduler("ral", xl, yl, zl, 3, 3000, 0, math.pi)
  • code/branches/plehmannFS16/src/orxonox/controllers/ControllerDirector.h

    r11071 r11204  
    2727 */
    2828
     29/*
     30@todo:
     31
     32in the take control or preparationToTakeControl functions remove the former controller and store it somewhere so it can be put back later.
     33
     34*/
    2935#ifndef _ControllerDirector_H__
    3036#define _ControllerDirector_H__
  • code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc

    r11190 r11204  
    4646#include "scriptTasks/DebugTask.h"
    4747#include "scriptTasks/stringOutTask.h"
     48#include "scriptTasks/MoveToTask.h"
    4849#include "scriptTasks/Task.h"
    4950#include "infos/PlayerInfo.h"
     
    102103        this->setControllableEntity(this->entity_);
    103104        this->entity_->mouseLook();
    104         this->entity_->setVisible(false);
     105        this->entity_->setVisible(true);
    105106       
    106107        // TODO take the human Controllers control  dont forget to give it back in the destructor
     
    116117        // If this controller has no entity entry, do nothing
    117118        if( !(this->entity_) ) return;
    118 
    119 
    120 /*
    121         if(taskQueue_.front()->getStartTime() <= scTime_)
    122         {
    123           activeTasks_.push_back(taskQueue_.front());
    124           taskQueue_.pop();
    125         }
    126 
    127         for(Task* task : activeTasks_)
    128         {
    129           task->tick(dt);
    130         }*/
    131119
    132120        if(!this->taskList_.empty())
     
    211199
    212200      task->initialize(startTime, output);
     201
     202      bool inserted = false;
     203
     204      if(taskList_.empty())
     205      {
     206        taskList_.push_front(task);
     207        inserted = true;
     208      }
     209
     210      else
     211      {
     212        for (std::list<Task*>::iterator it = taskList_.begin(); it != taskList_.end(); it++) // insert sorted by starttime
     213        {
     214          orxout() << "stringOutTask" << endl;
     215
     216          if(task->getStartTime() < (*it)->getStartTime() )
     217          {
     218            taskList_.insert(it, task);
     219            inserted = true;
     220            break;
     221          }
     222        }
     223      }
     224
     225      if (!inserted)
     226      {
     227        taskList_.push_back(task);
     228      }
     229
     230    }
     231
     232    void NewScriptController::moveTo(float startTime, float x, float y, float z, float velocity)
     233    {
     234
     235      MoveToTask* task = new MoveToTask(context_);
     236
     237      Vector3 destination = Vector3(x,y,z);
     238
     239      task->initialize(startTime, player_, destination, velocity);
    213240
    214241      bool inserted = false;
  • code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h

    r11190 r11204  
    2525 *      ...
    2626 *
     27 *
     28 *
    2729 */
    2830
     
    3234#include "scriptTasks/DebugTask.h"
    3335#include "scriptTasks/stringOutTask.h"
     36#include "scriptTasks/MoveToTask.h"
    3437#include "scriptTasks/Task.h"
    3538#include "OrxonoxPrereqs.h"                 /* die ganzen tolua, kopiert aus Dock.h*/
     
    4245{  // tolua_export
    4346
     47    /**
     48    @brief
    4449
     50    A scriptController to carry out tasks on an entity.
     51    The tasks are provided as a lua script.
     52    The commands which are exported to lua have to create the specified task, initialze it and add it to the TaskList.
     53
     54    Important add the export comment after functions that need to be accessed from the lua script.
     55
     56    @todo
     57
     58    take away the human controller and put it back into place when this controller is deleted.
     59    This is probably better done in the controller director class.
     60
     61    remove the startTimes of the tasks so that the lua script is just carried out one task after the other.
     62    to avoid problems when to tasks are carried out simultainiously.
     63
     64    also the velocity while the controller is taking control is kept and hinders the tasks.
     65
     66    the moveToTask does not work right.
     67    */
    4568
    4669    class _OrxonoxExport NewScriptController // tolua_export
     
    6184
    6285            void stringOut(float startTime, std::string output);// tolua_export
     86
     87            void moveTo(float startTime, float x, float y, float z, float velocity);// tolua_export
    6388
    6489            static NewScriptController* getNewScriptController();// tolua_export
  • code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/CMakeLists.txt

    r11183 r11204  
    33  DebugTask.cc
    44  stringOutTask.cc
     5  MoveToTask.cc
    56)
  • code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.cc

    r11190 r11204  
    2323 *      Paul Lehmann
    2424 *   Co-authors:
    25  *      ...
     25 *      ..
    2626 *
    2727 */
     
    4545    void MoveToTask::initialize(float startTime, PlayerInfo* player, Vector3 destination, float velocity)
    4646    {
    47         this->starTime_ = startTime;
     47        this->startTime_ = startTime;
    4848        this->player_ = player;
    4949        this->entity_ = this->player_->getControllableEntity();
    5050        this->destination_ = destination;
    5151        this->velocity_ = velocity;
    52         this->entity->setVelocity( Vector3(0,0,0) )
     52        this->entity_->setVelocity( Vector3(0,0,0) );
     53        // unit vector in the direction of travel
     54        this->direction_ = (destination - this->entity_->getPosition() )/( (destination - this->entity_->getPosition() ).length() );
     55
    5356    }
    5457
     
    5659    {
    5760
    58         float dl = this->velocity_ * dt;
     61        /* Look at the specified position */
     62        this->entity_->lookAt(this->destination_); 
    5963
    60        
    61         /* Set the position to the correct place in the trajectory */
    62         this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1);
     64        this->entity_->setPosition(this->entity_->getPosition() + velocity_ * dt * direction_);
    6365
    64         /* Look at the specified position */
    65         this->entity_->lookAt(this->currentEvent.v2);
     66        //this->entity_->setVelocity( Vector3(0,0,0) );
    6667
     68        orxout() << (this->entity_->getPosition() - destination_ ).length() << endl;
     69
     70        if ((this->entity_->getPosition() - destination_ ).length() > 30)
     71        {
     72            return true;
     73        }
     74        else
     75        {
     76            return false;
     77        }
    6778    }
    6879
  • code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.h

    r11190 r11204  
    4343            virtual ~MoveToTask(){}
    4444
    45             void initialize(float startTime, PlayerInfo* player, vector3 destination);
     45            void initialize(float startTime, PlayerInfo* player, Vector3 destination, float velocity);
    4646
    4747            virtual bool update(float dt) override;
     
    6060            ControllableEntity* entity_;
    6161
    62             vector3 destination_;
     62            Vector3 direction_;
    6363
     64            Vector3 destination_;
     65
     66            // velocitz in m/s
    6467            float velocity_;
    6568
Note: See TracChangeset for help on using the changeset viewer.