Changeset 2775
- Timestamp:
- Mar 12, 2009, 11:12:01 AM (16 years ago)
- Location:
- code/branches/tutorial/src/orxonox/objects
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/tutorial/src/orxonox/objects/controllers/DroneController.cc
r2767 r2775 32 32 #include "util/Math.h" 33 33 34 35 34 namespace orxonox 36 35 { … … 40 39 // - make sure to register the object in the factory 41 40 // - do any kind of initialisation 42 43 44 41 42 43 45 44 // this checks that our creator really is a drone 46 45 // and saves the pointer to the drone for the controlling commands 47 assert(dynamic_cast<Drone*>(creator) !=0);46 assert(dynamic_cast<Drone*>(creator) != 0); 48 47 this->setControllableEntity(dynamic_cast<Drone*>(creator)); 49 48 } … … 57 56 // Place your code here: 58 57 // - steering commands 59 Drone *myDrone = static_cast<Drone*>(this->getControllableEntity());58 Drone* myDrone = static_cast<Drone*>(this->getControllableEntity()); 60 59 // you can use the following commands for steering 61 60 // - moveFrontBack, moveRightLeft, moveUpDown 62 61 // - rotatePitch, rotateYaw, rotateRoll 63 62 // - apply the to myDrone (e.g. myDrone->rotateYaw(..) ) 64 63 65 64 } 66 65 } -
code/branches/tutorial/src/orxonox/objects/worldentities/Drone.cc
r2766 r2775 37 37 // PLACE YOUR CODE HERE 38 38 // create the factory for the drone 39 CreateFactory(Drone);40 39 41 40 Drone::Drone(BaseObject* creator) : ControllableEntity(creator) … … 45 44 // - register the drone class to the core 46 45 // - create a new controller and pass our this pointer to it as creator 47 46 48 47 this->localLinearAcceleration_.setValue(0, 0, 0); 49 48 this->localAngularAcceleration_.setValue(0, 0, 0); … … 52 51 this->rotationThrust_ = 10; 53 52 this->steering_ = Vector3::ZERO; 54 53 55 54 this->setCollisionType(WorldEntity::Dynamic); 56 57 myController_ = new DroneController(static_cast<BaseObject*>(this));55 56 this->myController_ = new DroneController(this); 58 57 } 59 58 60 59 Drone::~Drone() 61 60 { 62 if ( this->myController_)61 if (this->isInitialized() && this->myController_) 63 62 delete this->myController_; 64 63 } … … 79 78 // PLACE YOUR CODE HERE 80 79 // make sure the tick function of the base class gets called here 81 80 82 81 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); 83 82 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); 84 83 if (this->localLinearAcceleration_.z() > 0) 85 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);84 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); 86 85 else 87 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);86 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 88 87 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 89 88 this->localLinearAcceleration_.setValue(0, 0, 0); 90 89 91 90 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; 92 91 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 93 92 this->localAngularAcceleration_.setValue(0, 0, 0); 94 93 } 95 96 94 95 97 96 void Drone::moveFrontBack(const Vector2& value) 98 97 { … … 127 126 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); 128 127 } 129 130 128 } -
code/branches/tutorial/src/orxonox/objects/worldentities/Drone.h
r2766 r2775 45 45 virtual void tick(float dt); 46 46 47 47 48 48 virtual void moveFrontBack(const Vector2& value); 49 49 virtual void moveRightLeft(const Vector2& value); … … 53 53 virtual void rotatePitch(const Vector2& value); 54 54 virtual void rotateRoll(const Vector2& value); 55 56 55 56 57 57 inline void moveFrontBack(float value) 58 58 { this->moveFrontBack(Vector2(value, 0)); } … … 61 61 inline void moveUpDown(float value) 62 62 { this->moveUpDown(Vector2(value, 0)); } 63 63 64 64 inline void rotateYaw(float value) 65 65 { this->rotateYaw(Vector2(value, 0)); } … … 68 68 inline void rotateRoll(float value) 69 69 { this->rotateRoll(Vector2(value, 0)); } 70 70 71 71 private: 72 DroneController *myController_;73 72 DroneController* myController_; 73 74 74 Vector3 steering_; 75 75 btVector3 localLinearAcceleration_;
Note: See TracChangeset
for help on using the changeset viewer.