Changeset 2453
- Timestamp:
- Dec 14, 2008, 10:55:04 PM (16 years ago)
- Location:
- code/branches/physics_merge/src/orxonox/objects/worldentities/pawns
- Files:
-
- 2 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 -
code/branches/physics_merge/src/orxonox/objects/worldentities/pawns/SpaceShip.h
r2087 r2453 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "LinearMath/btVector3.h" 35 34 36 #include "Pawn.h" 35 37 … … 57 59 virtual void fire(); 58 60 59 void setMaxSpeed(float value)60 { this->maxSpeed_ = value; }61 void setMaxSecondarySpeed(float value)62 { this->maxSecondarySpeed_ = value; }63 void setMaxRotation(const Degree& value)64 { this->maxRotation_ = value; }65 void setTransAcc(float value)66 { this->translationAcceleration_ = value; }67 void setRotAcc(const Degree& value)68 { this->rotationAcceleration_ = value; }69 void setTransDamp(float value)70 { this->translationDamping_ = value; }71 72 inline float getMaxSpeed() const73 { return this->maxSpeed_; }74 inline float getMaxSecondarySpeed() const75 { return this->maxSecondarySpeed_; }76 inline float getMaxRotation() const77 { return this->maxRotation_.valueDegrees(); }78 inline float getTransAcc() const79 { return this->translationAcceleration_; }80 inline float getRotAcc() const81 { return this->rotationAcceleration_.valueDegrees(); }82 inline float getTransDamp() const83 { return this->translationDamping_; }84 85 61 protected: 86 62 bool bInvertYAxis_; 87 63 88 float maxSpeed_; 89 float maxSecondarySpeed_; 90 float translationAcceleration_; 91 float translationDamping_; 64 float primaryThrust_; 65 float auxilaryThrust_; 66 float rotationThrust_; 92 67 93 Degree maxRotation_;94 Degree rotationAcceleration_;68 btVector3 localLinearAcceleration_; 69 btVector3 localAngularAcceleration_; 95 70 96 Degree zeroDegree_; 97 Degree pitchRotation_; 98 Degree yawRotation_; 99 Degree rollRotation_; 71 private: 72 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 100 73 }; 101 74 }
Note: See TracChangeset
for help on using the changeset viewer.