- Timestamp:
- Dec 14, 2008, 10:55:04 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2442 r2453 47 47 RegisterObject(SpaceShip); 48 48 49 this->zeroDegree_ = 0; 49 this->primaryThrust_ = 100; 50 this->auxilaryThrust_ = 30; 51 this->rotationThrust_ = 10; 50 52 51 this->maxSpeed_ = 0; 52 this->maxSecondarySpeed_ = 0; 53 this->maxRotation_ = 0; 54 this->translationAcceleration_ = 0; 55 this->rotationAcceleration_ = 0; 56 this->translationDamping_ = 0; 57 58 this->yawRotation_ = 0; 59 this->pitchRotation_ = 0; 60 this->rollRotation_ = 0; 53 this->localLinearAcceleration_.setValue(0, 0, 0); 54 this->localAngularAcceleration_.setValue(0, 0, 0); 61 55 62 56 this->bInvertYAxis_ = false; 63 57 64 58 this->setDestroyWhenPlayerLeft(true); 59 60 // SpaceShip is always a physical object per default 61 // Be aware of this call: The collision type legality check will not reach derived classes! 62 this->setCollisionType(WorldEntity::Dynamic); 65 63 66 64 this->setConfigValues(); … … 76 74 SUPER(SpaceShip, XMLPort, xmlelement, mode); 77 75 78 XMLPortParam(SpaceShip, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode); 79 XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode); 80 XMLPortParam(SpaceShip, "maxrotation", setMaxRotation, getMaxRotation, xmlelement, mode); 81 XMLPortParam(SpaceShip, "transacc", setTransAcc, getTransAcc, xmlelement, mode); 82 XMLPortParam(SpaceShip, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); 83 XMLPortParam(SpaceShip, "transdamp", setTransDamp, getTransDamp, xmlelement, mode); 84 85 if (this->physicalBody_) 86 { 87 this->physicalBody_->setDamping(0.7, 0.3); 88 } 76 XMLPortParamVariable(SpaceShip, "primaryThrust", primaryThrust_, xmlelement, mode); 77 XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode); 78 XMLPortParamVariable(SpaceShip, "rotationThrust", rotationThrust_, xmlelement, mode); 89 79 } 90 80 91 81 void SpaceShip::registerVariables() 92 82 { 93 registerVariable(this->maxSpeed_, variableDirection::toclient); 94 registerVariable(this->maxSecondarySpeed_, variableDirection::toclient); 95 registerVariable(this->maxRotation_, variableDirection::toclient); 96 registerVariable(this->translationAcceleration_, variableDirection::toclient); 97 registerVariable(this->rotationAcceleration_, variableDirection::toclient); 98 registerVariable(this->translationDamping_, variableDirection::toclient); 83 registerVariable(this->primaryThrust_, variableDirection::toclient); 84 registerVariable(this->auxilaryThrust_, variableDirection::toclient); 85 registerVariable(this->rotationThrust_, variableDirection::toclient); 99 86 } 100 87 … … 104 91 } 105 92 93 bool SpaceShip::isCollisionTypeLegal(WorldEntity::CollisionType type) const 94 { 95 if (type != WorldEntity::Dynamic) 96 { 97 ThrowException(PhysicsViolation, "Cannot tell a SpaceShip not to be dynamic!"); 98 return false; 99 } 100 else 101 return true; 102 } 103 106 104 void SpaceShip::tick(float dt) 107 105 { 108 106 SUPER(SpaceShip, tick, dt); 107 108 if (this->isLocallyControlled()) 109 { 110 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); 111 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); 112 if (this->localLinearAcceleration_.z() > 0) 113 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); 114 else 115 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 116 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 117 this->localLinearAcceleration_.setValue(0, 0, 0); 118 119 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; 120 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 121 this->localAngularAcceleration_.setValue(0, 0, 0); 122 } 109 123 } 110 124 111 125 void SpaceShip::moveFrontBack(const Vector2& value) 112 126 { 113 assert(this->physicalBody_); 114 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 100)); 127 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 115 128 } 116 129 117 130 void SpaceShip::moveRightLeft(const Vector2& value) 118 131 { 119 this-> physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 100, 0.0f, 0.0f));132 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 120 133 } 121 134 122 135 void SpaceShip::moveUpDown(const Vector2& value) 123 136 { 124 this-> physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 100, 0.0f));137 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 125 138 } 126 139 127 140 void SpaceShip::rotateYaw(const Vector2& value) 128 141 { 129 this-> physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 1 / this->physicalBody_->getInvInertiaDiagLocal().y() * value.y * orientationGain, 0.0f));142 this->localAngularAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 130 143 } 131 144 132 145 void SpaceShip::rotatePitch(const Vector2& value) 133 146 { 134 this-> physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(1 / this->physicalBody_->getInvInertiaDiagLocal().x() * value.y * orientationGain, 0.0f, 0.0f));147 this->localAngularAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 135 148 } 136 149 137 150 void SpaceShip::rotateRoll(const Vector2& value) 138 151 { 139 this-> physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -1 / this->physicalBody_->getInvInertiaDiagLocal().z() * value.y * orientationGain));152 this->localAngularAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 140 153 } 141 154
Note: See TracChangeset
for help on using the changeset viewer.