[Orxonox-commit 76] r2775 - in branches/tutorial/src/orxonox/objects: controllers worldentities
landauf at orxonox.net
landauf at orxonox.net
Thu Mar 12 11:12:01 CET 2009
Author: landauf
Date: 2009-03-12 10:12:01 +0000 (Thu, 12 Mar 2009)
New Revision: 2775
Modified:
branches/tutorial/src/orxonox/objects/controllers/DroneController.cc
branches/tutorial/src/orxonox/objects/worldentities/Drone.cc
branches/tutorial/src/orxonox/objects/worldentities/Drone.h
Log:
small adjustments
Modified: branches/tutorial/src/orxonox/objects/controllers/DroneController.cc
===================================================================
--- branches/tutorial/src/orxonox/objects/controllers/DroneController.cc 2009-03-11 15:40:09 UTC (rev 2774)
+++ branches/tutorial/src/orxonox/objects/controllers/DroneController.cc 2009-03-12 10:12:01 UTC (rev 2775)
@@ -31,7 +31,6 @@
#include "objects/worldentities/Drone.h"
#include "util/Math.h"
-
namespace orxonox
{
DroneController::DroneController(BaseObject* creator) : Controller(creator)
@@ -39,12 +38,12 @@
// Place your code here:
// - make sure to register the object in the factory
// - do any kind of initialisation
-
-
-
+
+
+
// this checks that our creator really is a drone
// and saves the pointer to the drone for the controlling commands
- assert(dynamic_cast<Drone*>(creator)!=0);
+ assert(dynamic_cast<Drone*>(creator) != 0);
this->setControllableEntity(dynamic_cast<Drone*>(creator));
}
@@ -56,11 +55,11 @@
{
// Place your code here:
// - steering commands
- Drone *myDrone = static_cast<Drone*>(this->getControllableEntity());
+ Drone* myDrone = static_cast<Drone*>(this->getControllableEntity());
// you can use the following commands for steering
// - moveFrontBack, moveRightLeft, moveUpDown
// - rotatePitch, rotateYaw, rotateRoll
// - apply the to myDrone (e.g. myDrone->rotateYaw(..) )
-
+
}
}
Modified: branches/tutorial/src/orxonox/objects/worldentities/Drone.cc
===================================================================
--- branches/tutorial/src/orxonox/objects/worldentities/Drone.cc 2009-03-11 15:40:09 UTC (rev 2774)
+++ branches/tutorial/src/orxonox/objects/worldentities/Drone.cc 2009-03-12 10:12:01 UTC (rev 2775)
@@ -36,7 +36,6 @@
{
// PLACE YOUR CODE HERE
// create the factory for the drone
- CreateFactory(Drone);
Drone::Drone(BaseObject* creator) : ControllableEntity(creator)
{
@@ -44,22 +43,22 @@
// PLACE YOUR CODE HERE
// - register the drone class to the core
// - create a new controller and pass our this pointer to it as creator
-
+
this->localLinearAcceleration_.setValue(0, 0, 0);
this->localAngularAcceleration_.setValue(0, 0, 0);
this->primaryThrust_ = 100;
this->auxilaryThrust_ = 100;
this->rotationThrust_ = 10;
this->steering_ = Vector3::ZERO;
-
+
this->setCollisionType(WorldEntity::Dynamic);
-
- myController_ = new DroneController(static_cast<BaseObject*>(this));
+
+ this->myController_ = new DroneController(this);
}
Drone::~Drone()
{
- if( this->myController_ )
+ if (this->isInitialized() && this->myController_)
delete this->myController_;
}
@@ -78,22 +77,22 @@
{
// PLACE YOUR CODE HERE
// make sure the tick function of the base class gets called here
-
+
this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
if (this->localLinearAcceleration_.z() > 0)
- this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
+ this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
else
- this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
+ this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
this->localLinearAcceleration_.setValue(0, 0, 0);
-
+
this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
this->localAngularAcceleration_.setValue(0, 0, 0);
}
-
-
+
+
void Drone::moveFrontBack(const Vector2& value)
{
this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
@@ -126,5 +125,4 @@
{
this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
}
-
}
Modified: branches/tutorial/src/orxonox/objects/worldentities/Drone.h
===================================================================
--- branches/tutorial/src/orxonox/objects/worldentities/Drone.h 2009-03-11 15:40:09 UTC (rev 2774)
+++ branches/tutorial/src/orxonox/objects/worldentities/Drone.h 2009-03-12 10:12:01 UTC (rev 2775)
@@ -44,7 +44,7 @@
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
virtual void tick(float dt);
-
+
virtual void moveFrontBack(const Vector2& value);
virtual void moveRightLeft(const Vector2& value);
virtual void moveUpDown(const Vector2& value);
@@ -52,25 +52,25 @@
virtual void rotateYaw(const Vector2& value);
virtual void rotatePitch(const Vector2& value);
virtual void rotateRoll(const Vector2& value);
-
-
+
+
inline void moveFrontBack(float value)
{ this->moveFrontBack(Vector2(value, 0)); }
inline void moveRightLeft(float value)
{ this->moveRightLeft(Vector2(value, 0)); }
inline void moveUpDown(float value)
{ this->moveUpDown(Vector2(value, 0)); }
-
+
inline void rotateYaw(float value)
{ this->rotateYaw(Vector2(value, 0)); }
inline void rotatePitch(float value)
{ this->rotatePitch(Vector2(value, 0)); }
inline void rotateRoll(float value)
{ this->rotateRoll(Vector2(value, 0)); }
-
+
private:
- DroneController *myController_;
-
+ DroneController* myController_;
+
Vector3 steering_;
btVector3 localLinearAcceleration_;
btVector3 localAngularAcceleration_;
More information about the Orxonox-commit
mailing list