Changeset 2314 for code/branches/physics/src/orxonox/objects/worldentities
- Timestamp:
- Dec 3, 2008, 1:18:14 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2303 r2314 81 81 XMLPortParam(SpaceShip, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); 82 82 XMLPortParam(SpaceShip, "transdamp", setTransDamp, getTransDamp, xmlelement, mode); 83 84 if (this->physicalBody_) 85 { 86 this->physicalBody_->setDamping(0.8, 0.9); 87 this->physicalBody_->setActivationState(DISABLE_DEACTIVATION); 88 } 83 89 } 84 90 … … 106 112 // ##################################### 107 113 108 Vector3 velocity = this->getVelocity();109 if (velocity.x > this->maxSecondarySpeed_)110 velocity.x = this->maxSecondarySpeed_;111 if (velocity.x < -this->maxSecondarySpeed_)112 velocity.x = -this->maxSecondarySpeed_;113 if (velocity.y > this->maxSecondarySpeed_)114 velocity.y = this->maxSecondarySpeed_;115 if (velocity.y < -this->maxSecondarySpeed_)116 velocity.y = -this->maxSecondarySpeed_;117 if (velocity.z > this->maxSecondarySpeed_)118 velocity.z = this->maxSecondarySpeed_;119 if (velocity.z < -this->maxSpeed_)120 velocity.z = -this->maxSpeed_;114 //Vector3 velocity = this->getVelocity(); 115 //if (velocity.x > this->maxSecondarySpeed_) 116 // velocity.x = this->maxSecondarySpeed_; 117 //if (velocity.x < -this->maxSecondarySpeed_) 118 // velocity.x = -this->maxSecondarySpeed_; 119 //if (velocity.y > this->maxSecondarySpeed_) 120 // velocity.y = this->maxSecondarySpeed_; 121 //if (velocity.y < -this->maxSecondarySpeed_) 122 // velocity.y = -this->maxSecondarySpeed_; 123 //if (velocity.z > this->maxSecondarySpeed_) 124 // velocity.z = this->maxSecondarySpeed_; 125 //if (velocity.z < -this->maxSpeed_) 126 // velocity.z = -this->maxSpeed_; 121 127 122 128 // normalize velocity and acceleration 123 for (size_t dimension = 0; dimension < 3; ++dimension)124 {125 if (this->acceleration_[dimension] == 0)126 {127 if (velocity[dimension] > 0)128 {129 velocity[dimension] -= (this->translationDamping_ * dt);130 if (velocity[dimension] < 0)131 velocity[dimension] = 0;132 }133 else if (velocity[dimension] < 0)134 {135 velocity[dimension] += (this->translationDamping_ * dt);136 if (velocity[dimension] > 0)137 velocity[dimension] = 0;138 }139 }140 }141 142 this->setVelocity(velocity);129 //for (size_t dimension = 0; dimension < 3; ++dimension) 130 //{ 131 // if (this->acceleration_[dimension] == 0) 132 // { 133 // if (velocity[dimension] > 0) 134 // { 135 // velocity[dimension] -= (this->translationDamping_ * dt); 136 // if (velocity[dimension] < 0) 137 // velocity[dimension] = 0; 138 // } 139 // else if (velocity[dimension] < 0) 140 // { 141 // velocity[dimension] += (this->translationDamping_ * dt); 142 // if (velocity[dimension] > 0) 143 // velocity[dimension] = 0; 144 // } 145 // } 146 //} 147 148 //this->setVelocity(velocity); 143 149 } 144 150 … … 147 153 148 154 149 if (this->isLocallyControlled())150 {151 this->yaw(this->yawRotation_ * dt);152 if (this->bInvertYAxis_)153 this->pitch(Degree(-this->pitchRotation_ * dt));154 else155 this->pitch(Degree( this->pitchRotation_ * dt));156 this->roll(this->rollRotation_ * dt);157 158 this->acceleration_.x = 0;159 this->acceleration_.y = 0;160 this->acceleration_.z = 0;161 162 this->yawRotation_ = this->zeroDegree_;163 this->pitchRotation_ = this->zeroDegree_;164 this->rollRotation_ = this->zeroDegree_;165 }155 //if (this->isLocallyControlled()) 156 //{ 157 // this->yaw(this->yawRotation_ * dt); 158 // if (this->bInvertYAxis_) 159 // this->pitch(Degree(-this->pitchRotation_ * dt)); 160 // else 161 // this->pitch(Degree( this->pitchRotation_ * dt)); 162 // this->roll(this->rollRotation_ * dt); 163 164 // this->acceleration_.x = 0; 165 // this->acceleration_.y = 0; 166 // this->acceleration_.z = 0; 167 168 // this->yawRotation_ = this->zeroDegree_; 169 // this->pitchRotation_ = this->zeroDegree_; 170 // this->rollRotation_ = this->zeroDegree_; 171 //} 166 172 } 167 173 … … 169 175 { 170 176 assert(this->physicalBody_); 171 this->physicalBody_->applyCentralForce( btVector3(0.0f, 0.0f, -1.0f/this->physicalBody_->getInvMass() * value.x));177 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 100)); 172 178 // this->acceleration_.z = -this->translationAcceleration_ * value.x; 173 179 } … … 175 181 void SpaceShip::moveRightLeft(const Vector2& value) 176 182 { 177 this->physicalBody_->applyCentralForce( btVector3(1.0f/this->physicalBody_->getInvMass() * value.x, 0.0f, 0.0f));183 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 100, 0.0f, 0.0f)); 178 184 // this->acceleration_.x = this->translationAcceleration_ * value.x; 179 185 } … … 181 187 void SpaceShip::moveUpDown(const Vector2& value) 182 188 { 183 this->physicalBody_->applyCentralForce( btVector3(0.0f, 1.0f/this->physicalBody_->getInvMass() * value.x, 0.0f));189 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 100, 0.0f)); 184 190 // this->acceleration_.y = this->translationAcceleration_ * value.x; 185 191 } … … 187 193 void SpaceShip::rotateYaw(const Vector2& value) 188 194 { 189 Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 190 if (temp > this->maxRotation_) 191 temp = this->maxRotation_; 192 if (temp < -this->maxRotation_) 193 temp = -this->maxRotation_; 194 this->yawRotation_ = Degree(temp); 195 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 10000, 0.0f)); 196 //Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 197 //if (temp > this->maxRotation_) 198 // temp = this->maxRotation_; 199 //if (temp < -this->maxRotation_) 200 // temp = -this->maxRotation_; 201 //this->yawRotation_ = Degree(temp); 195 202 } 196 203 197 204 void SpaceShip::rotatePitch(const Vector2& value) 198 205 { 199 Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 200 if (temp > this->maxRotation_) 201 temp = this->maxRotation_; 202 if (temp < -this->maxRotation_) 203 temp = -this->maxRotation_; 204 this->pitchRotation_ = Degree(temp); 206 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 10000, 0.0f, 0.0f)); 207 //Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 208 //if (temp > this->maxRotation_) 209 // temp = this->maxRotation_; 210 //if (temp < -this->maxRotation_) 211 // temp = -this->maxRotation_; 212 //this->pitchRotation_ = Degree(temp); 205 213 } 206 214 207 215 void SpaceShip::rotateRoll(const Vector2& value) 208 216 { 209 Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 210 if (temp > this->maxRotation_) 211 temp = this->maxRotation_; 212 if (temp < -this->maxRotation_) 213 temp = -this->maxRotation_; 214 this->rollRotation_ = Degree(temp); 217 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 10000)); 218 //Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 219 //if (temp > this->maxRotation_) 220 // temp = this->maxRotation_; 221 //if (temp < -this->maxRotation_) 222 // temp = -this->maxRotation_; 223 //this->rollRotation_ = Degree(temp); 215 224 } 216 225
Note: See TracChangeset
for help on using the changeset viewer.