- Timestamp:
- Nov 27, 2015, 7:58:44 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
r10877 r10879 30 30 #include "worldentities/pawns/SpaceShip.h" 31 31 #include "util/Math.h" 32 32 #include <OgreMatrix3.h> 33 33 namespace orxonox 34 34 { … … 37 37 FlyingController::FlyingController( Context* context ): CommonController( context ) 38 38 { 39 this->rotationProgress_ = 0; 39 40 this->spread_ = 200; 40 41 this->tolerance_ = 80; … … 108 109 this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt ); 109 110 110 if ( distance < 300 ) 111 { 112 if ( bHasTargetOrientation_ ) 113 { 114 copyTargetOrientation( dt ); 115 } 116 } 111 117 112 if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01)) 118 113 this->getControllableEntity() ->moveFrontBack( SPEED * dt ); 114 115 // if ( bHasTargetOrientation_ && (rotateX > -0.005 && rotateX < 0.005 && rotateY > -0.005 && rotateY < 0.005) ) 116 // { 117 copyTargetOrientation( dt ); 118 // } 119 119 120 } 120 121 else … … 130 131 void FlyingController::copyOrientation( const Quaternion& orient, float dt ) 131 132 { 132 133 double diff=orient.getRoll(false).valueRadians() - 134 ( this->getControllableEntity() ->getOrientation() .getRoll( false ).valueRadians() ); 135 while( diff>math::twoPi)diff-=math::twoPi; 136 while( diff<-math::twoPi )diff+=math::twoPi; 137 138 this->getControllableEntity() ->rotateRoll(diff * ROTATEFACTOR * dt); 133 //inspired by 134 //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_ 135 //how can I make my objects rotate smoothly? 136 137 Quaternion myOrient = this->getControllableEntity()->getOrientation(); 138 this->rotationProgress_ += dt/50.0f; 139 140 if (this->rotationProgress_ > 1) 141 { 142 this->rotationProgress_ = 0; 143 } 144 else 145 { 146 Quaternion delta = Quaternion::Slerp(this->rotationProgress_, myOrient, orient, true); 147 148 Matrix3 orientMatrix, myMatrix; 149 delta.ToRotationMatrix(orientMatrix); 150 myOrient.ToRotationMatrix (myMatrix); 151 152 Radian yRad, pRad, rRad, yMy, pMy, rMy; 153 orientMatrix.ToEulerAnglesYXZ(yRad, pRad, rRad); 154 myMatrix.ToEulerAnglesYXZ (yMy, pMy, rMy); 155 orxout (internal_error) << "dt = " << dt << endl; 156 this->getControllableEntity()->rotateRoll (50.0f*dt*(rRad.valueRadians() - rMy.valueRadians())); 157 //this->getControllableEntity()->setOrientation(delta); 158 } 159 //this shit works. How? 160 139 161 } 140 162 //change log: increased precision, increased rotation speed
Note: See TracChangeset
for help on using the changeset viewer.