Changeset 2041 for code/branches/objecthierarchy/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
- Timestamp:
- Oct 29, 2008, 12:48:11 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2040 r2041 58 58 this->bInvertYAxis_ = false; 59 59 60 this->setDestroyWhenPlayerLeft(true); 61 60 62 this->setConfigValues(); 61 63 this->registerVariables(); … … 80 82 void SpaceShip::registerVariables() 81 83 { 84 REGISTERDATA(this->maxSpeed_, network::direction::toclient); 85 REGISTERDATA(this->maxSecondarySpeed_, network::direction::toclient); 86 REGISTERDATA(this->maxRotation_, network::direction::toclient); 87 REGISTERDATA(this->translationAcceleration_, network::direction::toclient); 88 REGISTERDATA(this->rotationAcceleration_, network::direction::toclient); 89 REGISTERDATA(this->translationDamping_, network::direction::toclient); 82 90 } 83 91 … … 89 97 void SpaceShip::tick(float dt) 90 98 { 91 // ##################################### 92 // ############# STEERING ############## 93 // ##################################### 94 95 Vector3 velocity = this->getVelocity(); 96 if (velocity.x > this->maxSecondarySpeed_) 97 velocity.x = this->maxSecondarySpeed_; 98 if (velocity.x < -this->maxSecondarySpeed_) 99 velocity.x = -this->maxSecondarySpeed_; 100 if (velocity.y > this->maxSecondarySpeed_) 101 velocity.y = this->maxSecondarySpeed_; 102 if (velocity.y < -this->maxSecondarySpeed_) 103 velocity.y = -this->maxSecondarySpeed_; 104 if (velocity.z > this->maxSecondarySpeed_) 105 velocity.z = this->maxSecondarySpeed_; 106 if (velocity.z < -this->maxSpeed_) 107 velocity.z = -this->maxSpeed_; 108 109 // normalize velocity and acceleration 110 for (size_t dimension = 0; dimension < 3; ++dimension) 99 if (this->isLocallyControlled()) 111 100 { 112 if (this->acceleration_[dimension] == 0) 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 acceleration 120 for (size_t dimension = 0; dimension < 3; ++dimension) 113 121 { 114 if ( velocity[dimension] >0)122 if (this->acceleration_[dimension] == 0) 115 123 { 116 velocity[dimension] -= (this->translationDamping_ * dt);117 if (velocity[dimension] < 0)118 velocity[dimension] = 0;119 }120 else if (velocity[dimension] < 0)121 {122 velocity[dimension] += (this->translationDamping_ * dt);123 124 if (velocity[dimension] > 0) 124 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 } 125 136 } 126 137 } 138 139 this->setVelocity(velocity); 127 140 } 128 141 129 this->setVelocity(velocity);130 131 142 132 143 SUPER(SpaceShip, tick, dt); 133 144 134 145 135 this->yaw(this->yawRotation_ * dt); 136 if (this->bInvertYAxis_) 137 this->pitch(Degree(-this->pitchRotation_ * dt)); 138 else 139 this->pitch(Degree( this->pitchRotation_ * dt)); 140 this->roll(this->rollRotation_ * dt); 141 142 this->acceleration_.x = 0; 143 this->acceleration_.y = 0; 144 this->acceleration_.z = 0; 145 146 this->yawRotation_ = this->zeroDegree_; 147 this->pitchRotation_ = this->zeroDegree_; 148 this->rollRotation_ = this->zeroDegree_; 146 if (this->isLocallyControlled()) 147 { 148 this->yaw(this->yawRotation_ * dt); 149 if (this->bInvertYAxis_) 150 this->pitch(Degree(-this->pitchRotation_ * dt)); 151 else 152 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 } 149 163 } 150 164
Note: See TracChangeset
for help on using the changeset viewer.