- Timestamp:
- Dec 14, 2008, 4:16:52 PM (16 years ago)
- Location:
- code/branches/physics_merge
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics_merge
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2371 r2442 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 … … 78 82 XMLPortParam(SpaceShip, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); 79 83 XMLPortParam(SpaceShip, "transdamp", setTransDamp, getTransDamp, xmlelement, mode); 84 85 if (this->physicalBody_) 86 { 87 this->physicalBody_->setDamping(0.7, 0.3); 88 } 80 89 } 81 90 … … 97 106 void SpaceShip::tick(float dt) 98 107 { 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 108 SUPER(SpaceShip, tick, dt); 144 145 146 if (this->isLocallyControlled())147 {148 this->yaw(this->yawRotation_ * dt);149 if (this->bInvertYAxis_)150 this->pitch(Degree(-this->pitchRotation_ * dt));151 else152 this->pitch(Degree( this->pitchRotation_ * dt));153 this->roll(this->rollRotation_ * dt);154 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_;162 }163 109 } 164 110 165 111 void SpaceShip::moveFrontBack(const Vector2& value) 166 112 { 167 this->acceleration_.z = -this->translationAcceleration_ * value.x; 113 assert(this->physicalBody_); 114 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 100)); 168 115 } 169 116 170 117 void SpaceShip::moveRightLeft(const Vector2& value) 171 118 { 172 this-> acceleration_.x = this->translationAcceleration_ * value.x;119 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 100, 0.0f, 0.0f)); 173 120 } 174 121 175 122 void SpaceShip::moveUpDown(const Vector2& value) 176 123 { 177 this-> acceleration_.y = this->translationAcceleration_ * value.x;124 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 100, 0.0f)); 178 125 } 179 126 180 127 void SpaceShip::rotateYaw(const Vector2& value) 181 128 { 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); 129 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 1 / this->physicalBody_->getInvInertiaDiagLocal().y() * value.y * orientationGain, 0.0f)); 188 130 } 189 131 190 132 void SpaceShip::rotatePitch(const Vector2& value) 191 133 { 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); 134 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(1 / this->physicalBody_->getInvInertiaDiagLocal().x() * value.y * orientationGain, 0.0f, 0.0f)); 198 135 } 199 136 200 137 void SpaceShip::rotateRoll(const Vector2& value) 201 138 { 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); 139 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -1 / this->physicalBody_->getInvInertiaDiagLocal().z() * value.y * orientationGain)); 208 140 } 209 141 -
code/branches/physics_merge/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2371 r2442 29 29 #include "OrxonoxStableHeaders.h" 30 30 #include "Spectator.h" 31 32 #include <OgreBillboardSet.h> 31 33 32 34 #include "core/CoreIncludes.h" … … 63 65 this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1); 64 66 if (this->greetingFlare_->getBillboardSet()) 65 this-> getNode()->attachObject(this->greetingFlare_->getBillboardSet());67 this->attachOgreObject(this->greetingFlare_->getBillboardSet()); 66 68 this->greetingFlare_->setVisible(false); 67 69 this->bGreetingFlareVisible_ = false; … … 78 80 { 79 81 if (this->greetingFlare_->getBillboardSet()) 80 this-> getNode()->detachObject(this->greetingFlare_->getBillboardSet());82 this->detachOgreObject(this->greetingFlare_->getBillboardSet()); 81 83 delete this->greetingFlare_; 82 84 } … … 110 112 Vector3 velocity = this->getVelocity(); 111 113 velocity.normalise(); 112 this->setVelocity( velocity * this->speed_);114 this->setVelocity(this->getOrientation() * velocity * this->speed_); 113 115 114 116 this->yaw(Radian(this->yaw_ * this->rotationSpeed_));
Note: See TracChangeset
for help on using the changeset viewer.