/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * ... * */ #include "OrxonoxStableHeaders.h" #include "Drone.h" #include "core/XMLPort.h" #include "BulletDynamics/Dynamics/btRigidBody.h" namespace orxonox { // put your code in here: // create the factory for the drone CreateFactory(Drone); Drone::Drone(BaseObject* creator) : ControllableEntity(creator) { //put your code in here: // - register the drone class to the core // - create a new controller and pass our this pointer to it as creator RegisterObject(Drone); this->localLinearAcceleration_.setValue(0, 0, 0); this->localAngularAcceleration_.setValue(0, 0, 0);this->rotationThrust_ = 0; this->steering_ = Vector3::ZERO; this->setCollisionType(WorldEntity::Dynamic); myController = new DroneController(static_cast(this)); } Drone::~Drone() { if( this->myController ) delete this->myController; } void Drone::XMLPort(Element& xmlelement, XMLPort::Mode mode) { // this calls the XMLPort function of the parent class SUPER(Drone, XMLPort, xmlelement, mode); XMLPortParamVariable(Drone, "rotationThrust", rotationThrust_, xmlelement, mode); } void Drone::tick(float dt) { SUPER(Drone, tick, dt); //if (this->hasLocalController()) //{ 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); this->steering_.z = -value.x; } void Drone::moveRightLeft(const Vector2& value) { this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); this->steering_.x = value.x; } void Drone::moveUpDown(const Vector2& value) { this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); this->steering_.y = value.x; } void Drone::rotateYaw(const Vector2& value) { this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x); } void Drone::rotatePitch(const Vector2& value) { this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x); } void Drone::rotateRoll(const Vector2& value) { this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); } }