[11230] | 1 | #include "Waypoint.h" |
---|
| 2 | |
---|
| 3 | #include <OgreSceneNode.h> |
---|
| 4 | #include <BulletDynamics/Dynamics/btRigidBody.h> |
---|
| 5 | #include "util/OrxAssert.h" |
---|
| 6 | #include "core/CoreIncludes.h" |
---|
| 7 | |
---|
| 8 | namespace orxonox |
---|
| 9 | { |
---|
| 10 | RegisterClass(Waypoint); |
---|
| 11 | |
---|
| 12 | Waypoint::Waypoint(Context* context) : StaticEntity(context) |
---|
| 13 | { |
---|
| 14 | RegisterObject(Waypoint); |
---|
| 15 | |
---|
| 16 | this->setPriority(Priority::VeryLow); |
---|
| 17 | |
---|
| 18 | this->registerVariables(); |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | Waypoint::~Waypoint() |
---|
| 22 | { |
---|
| 23 | } |
---|
| 24 | |
---|
[11237] | 25 | |
---|
| 26 | void Waypoint::XMLPort(Element& xmlelement, XMLPort::Mode mode){ |
---|
| 27 | SUPER(Waypoint, XMLPort, xmlelement, mode); // From the SpaceShip.cc file |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | //XMLPortObject(SpaceShip, Engine, "engines", addEngine, getEngine, xmlelement, mode); // TRY ADDING THE WAYPOINT ARROW LIKE AN ENGINE |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | |
---|
[11230] | 37 | void Waypoint::registerVariables() |
---|
| 38 | { |
---|
| 39 | // Ugly const casts, but are valid because position and orientation are not actually const |
---|
[11237] | 40 | registerVariable(const_cast<Vector3&>(this->getPosition()), \ |
---|
| 41 | VariableDirection::ToClient, new NetworkCallback<StaticEntity>(this, &StaticEntity::positionChanged)); |
---|
| 42 | registerVariable(const_cast<Quaternion&>(this->getOrientation()), |
---|
| 43 | VariableDirection::ToClient, new NetworkCallback<StaticEntity>(this, &StaticEntity::orientationChanged)); |
---|
[11230] | 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | void Waypoint::setOrientation(const Quaternion& orientation) |
---|
| 49 | { |
---|
| 50 | if (this->addedToPhysicalWorld()) |
---|
| 51 | { |
---|
| 52 | orxout(internal_warning) << "Attempting to change the orientation of a StaticEntity at physics run time. Ignoring change." << endl; |
---|
| 53 | return; |
---|
| 54 | } |
---|
| 55 | if (this->isStatic()) |
---|
| 56 | { |
---|
| 57 | btTransform transf = this->physicalBody_->getWorldTransform(); |
---|
| 58 | transf.setRotation(btQuaternion(orientation.x, orientation.y, orientation.z, orientation.w)); |
---|
| 59 | this->physicalBody_->setWorldTransform(transf); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | this->node_->setOrientation(orientation); |
---|
[11237] | 63 | |
---|
[11230] | 64 | } |
---|
[11237] | 65 | |
---|
| 66 | Vector3 Waypoint::toAimPosition(RadarViewable* target) const |
---|
| 67 | { |
---|
| 68 | Vector3 wePosition = HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition(); |
---|
| 69 | Vector3 targetPosition = target->getRVWorldPosition(); |
---|
| 70 | Vector3 targetSpeed = target->getRVVelocity(); |
---|
| 71 | |
---|
| 72 | return getPredictedPosition(wePosition, this->currentMunitionSpeed_, targetPosition, targetSpeed); |
---|
| 73 | } |
---|
| 74 | |
---|
[11230] | 75 | /* |
---|
| 76 | bool StaticEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) const |
---|
| 77 | { |
---|
| 78 | if (type == WorldEntity::CollisionType::Kinematic || type == WorldEntity::CollisionType::Dynamic) |
---|
| 79 | { |
---|
| 80 | orxout(internal_warning) << "Cannot tell a StaticEntity to have kinematic or dynamic collision type! Ignoring." << endl; |
---|
| 81 | assert(false); // Only in debug mode |
---|
| 82 | return false; |
---|
| 83 | } |
---|
| 84 | else |
---|
| 85 | return true; |
---|
| 86 | } |
---|
| 87 | */ |
---|
| 88 | void Waypoint::setWorldTransform(const btTransform& worldTrans) |
---|
| 89 | { |
---|
| 90 | OrxAssert(false, "Setting world transform of a StaticEntity, which is CF_STATIC!"); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | void Waypoint::getWorldTransform(btTransform& worldTrans) const |
---|
| 94 | { |
---|
| 95 | worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z)); |
---|
| 96 | worldTrans.setRotation(btQuaternion(node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z, node_->getOrientation().w)); |
---|
| 97 | } |
---|
| 98 | } |
---|
[11237] | 99 | |
---|
| 100 | |
---|
| 101 | const Pawn* pawnPtr = orxonox_cast<const Pawn*>(it->first->getWorldEntity()); |
---|
| 102 | |
---|
| 103 | if (pawnPtr) { |
---|
| 104 | float position = pawnPtr->getPosition(); |
---|