- Timestamp:
- Dec 7, 2015, 8:34:20 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
r10888 r10923 24 24 25 25 * Co-authors: 26 * Dominik Solenicki26 * ... 27 27 * 28 28 */ … … 46 46 FlyingController::~FlyingController() 47 47 { 48 49 48 } 50 49 … … 76 75 { 77 76 case FormationMode::WALL: 78 { return "WALL"; break;}77 { return "WALL"; } 79 78 case FormationMode::FINGER4: 80 { return "FINGER4"; break;}79 { return "FINGER4"; } 81 80 case FormationMode::DIAMOND: 82 { return "DIAMOND"; break;}81 { return "DIAMOND"; } 83 82 default: 84 return "DIAMOND"; break;83 return "DIAMOND"; 85 84 } 86 85 } … … 89 88 this->bHasTargetPosition_ = false; 90 89 } 91 void FlyingController::moveToPosition(const Vector3& target, float dt) 92 { 90 void FlyingController::moveToPosition(const Vector3& targetPosition, float dt) 91 { 92 if (!this->getControllableEntity()) 93 return; 93 94 ControllableEntity* entity = this->getControllableEntity(); 94 95 95 float distance = ( target - entity->getPosition() ).length();96 float distance = ( targetPosition - entity->getPosition() ).length(); 96 97 97 98 if ( distance >= this->tolerance_ ) … … 101 102 entity->getOrientation() * WorldEntity::FRONT, 102 103 entity->getOrientation() * WorldEntity::UP, 103 target );104 targetPosition ); 104 105 float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f ); 105 106 float rotateY = clamp( coord.y * 10, -1.0f, 1.0f ); … … 107 108 entity->rotatePitch( ROTATEFACTOR * rotateY * dt ); 108 109 109 if (distance > this->tolerance_*1.5f || (rotateX > -0.0 1 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))110 if (distance > this->tolerance_*1.5f || (rotateX > -0.03 && rotateX < 0.03 && rotateY > -0.03 && rotateY < 0.03)) 110 111 entity->moveFrontBack( SPEED * dt ); 111 112 copyTargetOrientation(dt); … … 123 124 void FlyingController::copyOrientation(const Quaternion& orient, float dt) 124 125 { 125 // inspired by126 //copied from 126 127 //http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Quaternion+and+Rotation+Primer&structure=Tutorials#Q._How_can_I_make_my_objects_rotate_smoothly_You_mentioned_slerp_etc_ 127 128 //how can I make my objects rotate smoothly? 128 129 if (!this->getControllableEntity()) 130 return; 129 131 Quaternion myOrient = this->getControllableEntity()->getOrientation(); 130 132 this->rotationProgress_ += dt; … … 137 139 else 138 140 { 139 140 Quaternion delta = Quaternion::Slerp(rotationProgress_, myOrient, orient, true); 141 Quaternion deltaOrientation = Quaternion::Slerp(rotationProgress_, myOrient, orient, true); 141 142 142 //rotate roll builds a Quaternion in roll method of WorldEntity, then it sets orientation. 143 //it is faster just to set orientation, plus that way there is no need in calculating the roll angle. 144 //On the downside, however, ship might also yaw and pitch, but this effect is neglectable, as we only call 145 //copyOrientation after we move our ship, thus it doesn't affect ships's flying direction too much. 146 //If you don't like the code style, you are welcomed to uncomment the code below 147 //and comment out setOrientation part, it will work just fine, but it will also be a tiny bit slower. 148 //P.S. apperantly it did affect ship's direction and did so way too much. 149 Matrix3 orientMatrix, myMatrix; 150 151 delta.ToRotationMatrix(orientMatrix); 143 Matrix3 deltaMatrix, myMatrix; 144 145 deltaOrientation.ToRotationMatrix(deltaMatrix); 152 146 myOrient.ToRotationMatrix (myMatrix); 153 147 154 Radian yRad, pRad, rRad, yMy, pMy, rMy; 155 orientMatrix.ToEulerAnglesYXZ(yRad, pRad, rRad); 156 myMatrix.ToEulerAnglesYXZ (yMy, pMy, rMy); 157 158 this->getControllableEntity()->rotateRoll ((rRad.valueRadians() - rMy.valueRadians())*ROTATEFACTOR*dt); 159 // this->getControllableEntity()->setOrientation(delta); 160 } 161 162 163 } 164 //change log: increased precision, increased rotation speed 148 Radian yawDelta, pitchDelta, rollDelta, yawMy, pitchMy, rollMy; 149 deltaMatrix.ToEulerAnglesYXZ(yawDelta, pitchDelta, rollDelta); 150 myMatrix.ToEulerAnglesYXZ (yawMy, pitchMy, rollMy); 151 152 if (!this->getControllableEntity()) 153 return; 154 this->getControllableEntity()->rotateRoll ((rollDelta.valueRadians() - rollMy.valueRadians())*ROTATEFACTOR*dt); 155 } 156 } 157 165 158 void FlyingController::copyTargetOrientation(float dt) 166 159 { 167 160 if (bHasTargetOrientation_) 168 161 { 169 copyOrientation(targetOrientation_, dt);162 this->copyOrientation(targetOrientation_, dt); 170 163 } 171 164 } … … 186 179 { 187 180 if (target) 188 setTargetOrientation(target->getOrientation());181 this->setTargetOrientation(target->getOrientation()); 189 182 } 190 183 void FlyingController::boostControl() 191 184 { 185 if (!this->getControllableEntity()) 186 return; 192 187 SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity()); 193 188 if(ship == NULL) return; … … 221 216 + (orient* (targetRelativePosition))); 222 217 //let ship finish rotating. also don't call copyOrientation to often as it is a slow function. 223 if ( this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_)218 if (static_cast<int>(rnd(1.0f) * 100) % 3 == 0) 224 219 this->setTargetOrientation (orient); 225 220 this->setTargetPosition (targetAbsolutePosition);
Note: See TracChangeset
for help on using the changeset viewer.