[Orxonox-commit 5403] r10066 - in code/branches/ScriptableController: data/gui/scripts src/orxonox/controllers
smerkli at orxonox.net
smerkli at orxonox.net
Wed May 21 15:28:28 CEST 2014
Author: smerkli
Date: 2014-05-21 15:28:28 +0200 (Wed, 21 May 2014)
New Revision: 10066
Modified:
code/branches/ScriptableController/data/gui/scripts/testscript.lua
code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc
code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h
Log:
Some cleanups, added a "change look" command
Modified: code/branches/ScriptableController/data/gui/scripts/testscript.lua
===================================================================
--- code/branches/ScriptableController/data/gui/scripts/testscript.lua 2014-05-21 12:32:41 UTC (rev 10065)
+++ code/branches/ScriptableController/data/gui/scripts/testscript.lua 2014-05-21 13:28:28 UTC (rev 10066)
@@ -19,7 +19,7 @@
if ctrl ~= nil then
-- Move to the starting point at (xl+3000,yl,zl) while looking
-- at xl,yl,zl over the time span of 3 seconds
- ctrl:eventScheduler("mal", xl+3000,yl,zl, xl,yl,zl, 3, 0)
+ ctrl:eventScheduler("mal", xl+3000,yl,zl, xl,yl,zl, 1, 0)
-- From there, perform a rotation around the harvester placed there
-- in 100 steps
@@ -28,16 +28,21 @@
xt = math.cos(t)
yt = math.sin(t)
- ctrl:eventScheduler("mal", xl+3000*xt, yl+3000*yt, zl, xl, yl, zl, 3*dt, 3*t+2.9)
+ ctrl:eventScheduler("mal", xl+3000*xt, yl+3000*yt, zl, xl, yl, zl, dt, t+0.9)
end
-- Update absolute time
- Tabs = 3*math.pi + 2.9
+ Tabs = math.pi + 0.9
-- Move away again, still looking at the station
ctrl:eventScheduler("mal", 0,0,1000, xl,yl,zl, 3, Tabs+0.4)
+ -- Update absolute time
+ Tabs = Tabs + 0.4 + 3
+ -- Transition the look from (xl,yl,zl) to (3500,0,0) in 3 seconds
+ ctrl:eventScheduler("chl", xl, yl, zl, 3500, 0, 0, 3, Tabs)
+
end
Modified: code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc
===================================================================
--- code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc 2014-05-21 12:32:41 UTC (rev 10065)
+++ code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc 2014-05-21 13:28:28 UTC (rev 10066)
@@ -46,7 +46,6 @@
*/
this->ctrlid_ = 0;
-
/* Set default values for all variables */
/* - pointers to zero */
this->player_ = NULL;
@@ -54,13 +53,11 @@
/* - times */
this->scTime = 0.0f;
- this->timeToTarget = 0.0f;
this->eventTime = 0.0f;
/* - Points in space */
- this->target = Vector3(0,0,0);
this->startpos = Vector3(0,0,0);
- this->lookAtPosition = Vector3(0,0,0);
+ //this->lookAtPosition = Vector3(0,0,0);
/* - Processing flag */
this->processing = false;
@@ -94,14 +91,6 @@
this->entity_->setVisible(false);
}
- /* Yet to be implemented and tested */
- //void ScriptController::yieldControl()
- //{
- //this->player_->startControl(this->entity_);
- //this->setActive(false);
- //this->controllableEntity_ = NULL;
- //}
-
const Vector3& ScriptController::getPosition()
{
return this->entity_->getPosition();
@@ -135,18 +124,22 @@
void ScriptController::execute(event ev)
{
- orxout() << "Executing event " << ev.fctName
- << " with parameters:\n "
- << ev.x1 << " " << ev.y1 << " " << ev.z1 << "\n"
- << ev.x2 << " " << ev.y2 << " " << ev.z2 << "\n"
- << ev.duration << endl;
+ /* Debugging output */
+ //orxout() << "Executing event " << ev.fctName
+ //<< " with parameters:\n "
+ //<< ev.x1 << " " << ev.y1 << " " << ev.z1 << "\n"
+ //<< ev.x2 << " " << ev.y2 << " " << ev.z2 << "\n"
+ //<< ev.duration << endl;
+ /* Event is starting, hence set the time to 0 */
this->eventTime = 0.0f;
- this->startpos = this->entity_->getPosition();
this->processing = true;
- if(ev.fctName == "mal")
- moveAndLook(ev.x1, ev.y1, ev.z1, ev.x2, ev.y2, ev.z2, ev.duration);
+ /* Copy the event into the currentEvent holder */
+ this->currentEvent = ev;
+
+ /* Store starting position */
+ this->startpos = this->entity_->getPosition();
}
@@ -156,33 +149,26 @@
SUPER(ScriptController, tick, dt);
/* If this controller has no entity entry, do nothing */
- if( !(this->entity_) )
- return;
+ if( !(this->entity_) ) return;
- //orxout() << "Size 0: " << this->eventList.size() << endl;
-
/* See if time has come for the next event to be run */
if(this->eventList.size() > 0 && this->eventList[0].eventTime <= scTime)
- {
- /* Execute the next event on the list */
+ { /* Execute the next event on the list */
this->execute(this->eventList[0]);
this->eventList.erase(this->eventList.begin());
this->eventno -= 1;
- //orxout() << "Size 1: " << this->eventList.size() << endl;
- //orxout() << "Eventno is now: " << this->eventno << endl;
}
/* Update the local timers in this object */
- scTime += dt;
- eventTime += dt;
+ scTime += dt; eventTime += dt;
/* If we've arrived at the target, stop processing */
- if( eventTime > timeToTarget && this->processing == true)
+ if( eventTime > currentEvent.duration && this->processing == true)
{ this->processing = false;
- //orxout() << "Size 4: " << this->eventList.size() << endl;
- //orxout() << "Eventno: " << this->eventno << endl;
-
+ /* If we reached the last event, also reenable the normal movement
+ * and make the model visible again
+ */
if( this->eventno == 0 )
{
this->entity_->mouseLook();
@@ -193,49 +179,37 @@
/* Get a variable that specifies how far along the trajectory
* we are
*/
- float dl = eventTime / timeToTarget;
+ float dl = eventTime / currentEvent.duration;
+ /* Depending */
/* Do some moving */
if( this->processing )
{
- /* Set the position to the correct place in the trajectory */
- this->entity_->setPosition( (1-dl)*startpos + dl * target );
+ if( this->currentEvent.fctName == "mal" )
+ {
+ /* Set the position to the correct place in the trajectory */
+ this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1);
- /* Look at the specified position */
- this->entity_->lookAt(lookAtPosition);
+ /* Look at the specified position */
+ this->entity_->lookAt(this->currentEvent.v2);
+ /* Update look at position */
+ //this->lookAtPosition = this->currentEvent.v2;
+ }
+ else if( this->currentEvent.fctName == "chl" )
+ {
+ /* Sweep the look from v1 to v2 */
+ this->entity_->lookAt( (1-dl)*this->currentEvent.v1 +
+ dl * this->currentEvent.v2 );
+ }
+
+
/* Force mouse look */
if( this->entity_->isInMouseLook() == false )
this->entity_->mouseLook();
}
}
- void ScriptController::moveAndLook(
- float xm, float ym, float zm,
- float xl, float yl, float zl,
- float t )
- {
- orxout()<<"moveAndLook executed"<<endl;
-
- /* Set the local variables required for this event */
- this->target = Vector3(xm,ym,zm);
- this->lookAtPosition = Vector3(xl,yl,zl);
- this->timeToTarget = t;
-
-
- orxout() << "Moving This-pointer: " << this << endl;
-
- if(this->entity_ != NULL)
- orxout()<<"not-NULL-entity"<<endl;
- else
- return;
-
- if(this->player_ != NULL)
- orxout()<<"not-NULL-player"<<endl;
- else
- return;
- }
-
void ScriptController::eventScheduler(std::string instruction,
float x1, float y1, float z1,
float x2, float y2, float z2,
@@ -249,8 +223,10 @@
/* Fill the structure with all the provided information */
tmp.fctName = instruction;
- tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
- tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
+ //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
+ //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
+ tmp.v1 = Vector3(x1,y1,z1);
+ tmp.v2 = Vector3(x2,y2,z2);
tmp.duration = duration;
tmp.eventTime = executionTime;
Modified: code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h
===================================================================
--- code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h 2014-05-21 12:32:41 UTC (rev 10065)
+++ code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h 2014-05-21 13:28:28 UTC (rev 10066)
@@ -38,21 +38,20 @@
namespace orxonox // tolua_export
{ // tolua_export
+ /** Structure to describe a single event */
struct event
{
+ /** Instruction for this event */
std::string fctName;
- float x1;
- float y1;
- float z1;
- float x2;
- float y2;
- float z2;
+ Vector3 v1;
+ Vector3 v2;
+ /** Time span of the event */
float duration;
+ /** Start point in time of the event */
float eventTime;
-
};
class _OrxonoxExport ScriptController // tolua_export
@@ -60,11 +59,8 @@
{ // tolua_export
public:
ScriptController(Context* context);
-
virtual ~ScriptController() { }
- //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-
void takeControl(int ctrlid);
void setPlayer(PlayerInfo* player) { this->player_ = player; }
@@ -72,9 +68,6 @@
// LUA interface
// tolua_begin
- void moveAndLook(float xm, float ym, float zm,
- float xl, float yl, float zl, float t);
-
void eventScheduler(std::string instruction,
float x1, float y1, float z1,
float x2, float y2, float z2,
@@ -114,19 +107,16 @@
* now */
bool processing;
- /* Data about the point to go to and what to look at */
- /* - Target position */
- Vector3 target;
+ /* Data about the event currently being processed */
+ /* - The event itself */
+ event currentEvent;
- /* - Time it should take to get there */
- float timeToTarget;
-
/* - Time this event has been going on for */
float eventTime;
Vector3 startpos;
/* - Position to look at during that transition */
- Vector3 lookAtPosition;
+ //Vector3 lookAtPosition;
};// tolua_export
} // tolua_export
More information about the Orxonox-commit
mailing list