- Timestamp:
- Dec 15, 2008, 12:53:05 AM (16 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
- Property svn:mergeinfo changed
-
code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2371 r2459 30 30 #include "SpaceShip.h" 31 31 32 #include "BulletDynamics/Dynamics/btRigidBody.h" 33 34 #include "util/Math.h" 35 #include "util/Exception.h" 32 36 #include "core/CoreIncludes.h" 33 37 #include "core/ConfigValueIncludes.h" 34 38 #include "core/XMLPort.h" 35 #include "util/Math.h"36 39 37 40 namespace orxonox 38 41 { 42 const float orientationGain = 100; 39 43 CreateFactory(SpaceShip); 40 44 … … 43 47 RegisterObject(SpaceShip); 44 48 45 this->zeroDegree_ = 0; 49 this->primaryThrust_ = 100; 50 this->auxilaryThrust_ = 30; 51 this->rotationThrust_ = 10; 46 52 47 this->maxSpeed_ = 0; 48 this->maxSecondarySpeed_ = 0; 49 this->maxRotation_ = 0; 50 this->translationAcceleration_ = 0; 51 this->rotationAcceleration_ = 0; 52 this->translationDamping_ = 0; 53 54 this->yawRotation_ = 0; 55 this->pitchRotation_ = 0; 56 this->rollRotation_ = 0; 53 this->localLinearAcceleration_.setValue(0, 0, 0); 54 this->localAngularAcceleration_.setValue(0, 0, 0); 57 55 58 56 this->bInvertYAxis_ = false; 59 57 60 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); 61 63 62 64 this->setConfigValues(); … … 72 74 SUPER(SpaceShip, XMLPort, xmlelement, mode); 73 75 74 XMLPortParam(SpaceShip, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode); 75 XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode); 76 XMLPortParam(SpaceShip, "maxrotation", setMaxRotation, getMaxRotation, xmlelement, mode); 77 XMLPortParam(SpaceShip, "transacc", setTransAcc, getTransAcc, xmlelement, mode); 78 XMLPortParam(SpaceShip, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); 79 XMLPortParam(SpaceShip, "transdamp", setTransDamp, getTransDamp, xmlelement, mode); 76 XMLPortParamVariable(SpaceShip, "primaryThrust", primaryThrust_, xmlelement, mode); 77 XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode); 78 XMLPortParamVariable(SpaceShip, "rotationThrust", rotationThrust_, xmlelement, mode); 80 79 } 81 80 82 81 void SpaceShip::registerVariables() 83 82 { 84 registerVariable(this->maxSpeed_, variableDirection::toclient); 85 registerVariable(this->maxSecondarySpeed_, variableDirection::toclient); 86 registerVariable(this->maxRotation_, variableDirection::toclient); 87 registerVariable(this->translationAcceleration_, variableDirection::toclient); 88 registerVariable(this->rotationAcceleration_, variableDirection::toclient); 89 registerVariable(this->translationDamping_, variableDirection::toclient); 83 registerVariable(this->primaryThrust_, variableDirection::toclient); 84 registerVariable(this->auxilaryThrust_, variableDirection::toclient); 85 registerVariable(this->rotationThrust_, variableDirection::toclient); 90 86 } 91 87 … … 95 91 } 96 92 93 bool SpaceShip::isCollisionTypeLegal(WorldEntity::CollisionType type) const 94 { 95 if (type != WorldEntity::Dynamic) 96 { 97 CCOUT(1) << "Error: Cannot tell a SpaceShip not to be dynamic! Ignoring." << std::endl; 98 assert(false); // Only in debug mode 99 return false; 100 } 101 else 102 return true; 103 } 104 97 105 void SpaceShip::tick(float dt) 98 106 { 99 if (this->isLocallyControlled())100 {101 // #####################################102 // ############# STEERING ##############103 // #####################################104 105 Vector3 velocity = this->getVelocity();106 if (velocity.x > this->maxSecondarySpeed_)107 velocity.x = this->maxSecondarySpeed_;108 if (velocity.x < -this->maxSecondarySpeed_)109 velocity.x = -this->maxSecondarySpeed_;110 if (velocity.y > this->maxSecondarySpeed_)111 velocity.y = this->maxSecondarySpeed_;112 if (velocity.y < -this->maxSecondarySpeed_)113 velocity.y = -this->maxSecondarySpeed_;114 if (velocity.z > this->maxSecondarySpeed_)115 velocity.z = this->maxSecondarySpeed_;116 if (velocity.z < -this->maxSpeed_)117 velocity.z = -this->maxSpeed_;118 119 // normalize velocity and acceleration120 for (size_t dimension = 0; dimension < 3; ++dimension)121 {122 if (this->acceleration_[dimension] == 0)123 {124 if (velocity[dimension] > 0)125 {126 velocity[dimension] -= (this->translationDamping_ * dt);127 if (velocity[dimension] < 0)128 velocity[dimension] = 0;129 }130 else if (velocity[dimension] < 0)131 {132 velocity[dimension] += (this->translationDamping_ * dt);133 if (velocity[dimension] > 0)134 velocity[dimension] = 0;135 }136 }137 }138 139 this->setVelocity(velocity);140 }141 142 143 107 SUPER(SpaceShip, tick, dt); 144 145 108 146 109 if (this->isLocallyControlled()) 147 110 { 148 this->yaw(this->yawRotation_ * dt); 149 if (this->bInvertYAxis_) 150 this->pitch(Degree(-this->pitchRotation_ * dt)); 111 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); 112 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); 113 if (this->localLinearAcceleration_.z() > 0) 114 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); 151 115 else 152 this->pitch(Degree( this->pitchRotation_ * dt)); 153 this->roll(this->rollRotation_ * dt); 116 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 117 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 118 this->localLinearAcceleration_.setValue(0, 0, 0); 154 119 155 this->acceleration_.x = 0; 156 this->acceleration_.y = 0; 157 this->acceleration_.z = 0; 158 159 this->yawRotation_ = this->zeroDegree_; 160 this->pitchRotation_ = this->zeroDegree_; 161 this->rollRotation_ = this->zeroDegree_; 120 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; 121 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 122 this->localAngularAcceleration_.setValue(0, 0, 0); 162 123 } 163 124 } … … 165 126 void SpaceShip::moveFrontBack(const Vector2& value) 166 127 { 167 this-> acceleration_.z = -this->translationAcceleration_ * value.x;128 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 168 129 } 169 130 170 131 void SpaceShip::moveRightLeft(const Vector2& value) 171 132 { 172 this-> acceleration_.x = this->translationAcceleration_ * value.x;133 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 173 134 } 174 135 175 136 void SpaceShip::moveUpDown(const Vector2& value) 176 137 { 177 this-> acceleration_.y = this->translationAcceleration_ * value.x;138 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 178 139 } 179 140 180 141 void SpaceShip::rotateYaw(const Vector2& value) 181 142 { 182 Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 183 if (temp > this->maxRotation_) 184 temp = this->maxRotation_; 185 if (temp < -this->maxRotation_) 186 temp = -this->maxRotation_; 187 this->yawRotation_ = Degree(temp); 143 this->localAngularAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 188 144 } 189 145 190 146 void SpaceShip::rotatePitch(const Vector2& value) 191 147 { 192 Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 193 if (temp > this->maxRotation_) 194 temp = this->maxRotation_; 195 if (temp < -this->maxRotation_) 196 temp = -this->maxRotation_; 197 this->pitchRotation_ = Degree(temp); 148 this->localAngularAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 198 149 } 199 150 200 151 void SpaceShip::rotateRoll(const Vector2& value) 201 152 { 202 Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 203 if (temp > this->maxRotation_) 204 temp = this->maxRotation_; 205 if (temp < -this->maxRotation_) 206 temp = -this->maxRotation_; 207 this->rollRotation_ = Degree(temp); 153 this->localAngularAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 208 154 } 209 155 -
code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.h
r2087 r2459 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 } -
code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2371 r2459 29 29 #include "OrxonoxStableHeaders.h" 30 30 #include "Spectator.h" 31 32 #include <OgreBillboardSet.h> 31 33 32 34 #include "core/CoreIncludes.h" … … 50 52 51 53 this->speed_ = 100; 52 this->rotation Speed_ = 3;54 this->rotationGain_ = 3; 53 55 54 56 this->yaw_ = 0; 55 57 this->pitch_ = 0; 56 58 this->roll_ = 0; 59 this->localVelocity_ = Vector3::ZERO; 57 60 this->setHudTemplate("spectatorhud"); 58 61 this->hudmode_ = 0; … … 63 66 this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1); 64 67 if (this->greetingFlare_->getBillboardSet()) 65 this-> getNode()->attachObject(this->greetingFlare_->getBillboardSet());68 this->attachOgreObject(this->greetingFlare_->getBillboardSet()); 66 69 this->greetingFlare_->setVisible(false); 67 70 this->bGreetingFlareVisible_ = false; … … 78 81 { 79 82 if (this->greetingFlare_->getBillboardSet()) 80 this-> getNode()->detachObject(this->greetingFlare_->getBillboardSet());83 this->detachOgreObject(this->greetingFlare_->getBillboardSet()); 81 84 delete this->greetingFlare_; 82 85 } … … 108 111 if (this->isLocallyControlled()) 109 112 { 110 Vector3 velocity = this->getVelocity(); 111 velocity.normalise(); 112 this->setVelocity(velocity * this->speed_); 113 114 this->yaw(Radian(this->yaw_ * this->rotationSpeed_)); 115 this->pitch(Radian(this->pitch_ * this->rotationSpeed_)); 116 this->roll(Radian(this->roll_ * this->rotationSpeed_)); 113 float localSpeedSquared = this->localVelocity_.squaredLength(); 114 float localSpeed; 115 if (localSpeedSquared > 1.0) 116 localSpeed = this->speed_ / sqrtf(localSpeedSquared); 117 else 118 localSpeed = this->speed_; 119 120 this->localVelocity_.x *= localSpeed; 121 this->localVelocity_.y *= localSpeed; 122 this->localVelocity_.z *= localSpeed; 123 this->setVelocity(this->getOrientation() * this->localVelocity_); 124 this->localVelocity_.x = 0; 125 this->localVelocity_.y = 0; 126 this->localVelocity_.z = 0; 127 128 this->yaw (Radian(this->yaw_ * this->rotationGain_)); 129 this->pitch(Radian(this->pitch_ * this->rotationGain_)); 130 this->roll (Radian(this->roll_ * this->rotationGain_)); 117 131 118 132 this->yaw_ = this->pitch_ = this->roll_ = 0; … … 120 134 121 135 SUPER(Spectator, tick, dt); 122 123 if (this->isLocallyControlled())124 {125 this->setVelocity(Vector3::ZERO);126 }127 136 } 128 137 … … 143 152 void Spectator::moveFrontBack(const Vector2& value) 144 153 { 145 this-> setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::FRONT);154 this->localVelocity_.z -= value.x; 146 155 } 147 156 148 157 void Spectator::moveRightLeft(const Vector2& value) 149 158 { 150 this-> setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::RIGHT);159 this->localVelocity_.x += value.x; 151 160 } 152 161 153 162 void Spectator::moveUpDown(const Vector2& value) 154 163 { 155 this-> setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::UP);164 this->localVelocity_.y += value.x; 156 165 } 157 166 158 167 void Spectator::rotateYaw(const Vector2& value) 159 168 { 160 this->yaw_ = value.y;169 this->yaw_ += value.y; 161 170 } 162 171 163 172 void Spectator::rotatePitch(const Vector2& value) 164 173 { 165 this->pitch_ = value.y;174 this->pitch_ += value.y; 166 175 } 167 176 168 177 void Spectator::rotateRoll(const Vector2& value) 169 178 { 170 this->roll_ = value.y;179 this->roll_ += value.y; 171 180 } 172 181 -
code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.h
r2087 r2459 69 69 70 70 float speed_; 71 float rotation Speed_;71 float rotationGain_; 72 72 73 73 float yaw_; 74 74 float pitch_; 75 75 float roll_; 76 77 Vector3 localVelocity_; 76 78 77 79 int hudmode_;
Note: See TracChangeset
for help on using the changeset viewer.