Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 27, 2015, 7:58:44 PM (8 years ago)
Author:
gania
Message:

finished copyOrientation function. Now ships move smoothly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc

    r10877 r10879  
    3030#include "worldentities/pawns/SpaceShip.h"
    3131#include "util/Math.h"
    32 
     32#include <OgreMatrix3.h>
    3333namespace orxonox
    3434{   
     
    3737    FlyingController::FlyingController( Context* context ): CommonController( context )
    3838    {
     39        this->rotationProgress_ = 0;
    3940        this->spread_ = 200;
    4041        this->tolerance_ = 80;
     
    108109            this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
    109110
    110             if ( distance < 300 )
    111             {
    112                 if ( bHasTargetOrientation_ )
    113                 {
    114                     copyTargetOrientation( dt );
    115                 }
    116             }
     111         
    117112            if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
    118113                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           
    119120        }
    120121        else
     
    130131    void FlyingController::copyOrientation( const Quaternion& orient, float dt )
    131132    {
    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       
    139161    }
    140162    //change log: increased precision, increased rotation speed
Note: See TracChangeset for help on using the changeset viewer.