Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10879


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

finished copyOrientation function. Now ships move smoothly

Location:
code/branches/campaignHS15
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/data/levels/AITest.oxw

    r10877 r10879  
    6262<!-- HERE STARTS DEMO FOR THE ACTIONPOINTS.
    6363P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped -->
    64       
     64     <!--  
    6565    <Model mesh="cube.mesh" scale=8 position="0,0,0" />
    6666
     
    123123      </templates>
    124124    </SpaceShip>
    125  
     125  -->
    126126   
    127127<!-- HERE ENDS DEMO FOR THE ACTIONPOINTS -->
     
    210210<!-- HERE ENDS DEMO FOR FIGHTING -->
    211211<!-- HERE STARTS DEMO FOR FORMATIONS -->
    212     <!--
     212   
    213213    <Model mesh="cube.mesh" scale=8 position="   0,2000,    0" />
    214214    <Model mesh="cube.mesh" scale=8 position="   0,2000,-2000" />
     
    221221      </templates>
    222222      <controller>
    223         <DivisionController team=0 formationMode="DIAMOND" spread=100>
     223        <DivisionController team=0 formationMode="Finger4" spread=100>
    224224          <actionpoints>
    225225            <Actionpoint position="   0,2000,    0" action="FLY" loopStart=true/>
     
    259259      </controller>
    260260    </SpaceShip>
    261     -->
     261   
    262262<!-- HERE ENDS DEMO FOR FORMATIONS -->
    263263    <!--
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc

    r10877 r10879  
    8282        }
    8383        if (this->bFirstTick_)
     84        {
     85            // this->getControllableEntity()->setOrientation(1,0,0,0);
     86            // this->getControllableEntity()->rotateRoll(-this->getControllableEntity()->getOrientation().getRoll(true).valueRadians());
     87            // this->getControllableEntity()->rotateYaw(-this->getControllableEntity()->getOrientation().getYaw(true).valueRadians());
     88            // this->getControllableEntity()->rotatePitch(-this->getControllableEntity()->getOrientation().getPitch(true).valueRadians());           
    8489            this->bFirstTick_ = false;
     90
     91        }
    8592                SUPER(ActionpointController, tick, dt);
    8693        }
     
    358365            (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
    359366        this->setTargetPosition(targetAbsolutePosition);
     367        this->setTargetOrientation(this->getProtect()->getWorldOrientation());
    360368    }
    361369    void ActionpointController::nextActionpoint()
  • 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
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h

    r10877 r10879  
    8282            FormationMode::Value formationMode_;
    8383         
    84  
     84            float rotationProgress_;
    8585            bool bHasTargetPosition_;
    8686            Vector3 targetPosition_;
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10877 r10879  
    8383            Action::FIGHTALL && this->myDivisionLeader_->getAction() != Action::ATTACK)
    8484        {
    85             ControllableEntity* myEntity = this->getControllableEntity();
     85           
     86        }   
     87        SUPER(SectionController, tick, dt);
     88    }
     89
     90    void SectionController::action()
     91    {
     92        if (!this || !this->getControllableEntity())
     93            return;
     94
     95        //----If no leader, find one---- 
     96        if (!myDivisionLeader_)
     97        {
     98            LeaderController* newDivisionLeader = findNewDivisionLeader();
     99            this->myDivisionLeader_ = newDivisionLeader;
     100            if (this->myDivisionLeader_)
     101            {
     102
     103            }
     104        }
     105        //----If have leader----
     106        else
     107        {
     108        }
     109        if (!myDivisionLeader_)
     110        {
     111           
     112            ActionpointController::action();
     113            if (!this || !this->getControllableEntity())
     114                return;
     115            if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))
     116            {
     117                if (this->myWingman_)
     118                {
     119                    this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
     120                }   
     121            }
     122        }
     123        else if (myDivisionLeader_)
     124        {
     125            switch (myDivisionLeader_->getAction())
     126            {
     127                case Action::FIGHT:
     128                {
     129                    if (!this->hasTarget())
     130                    {
     131                        this->chooseTarget();
     132                    }
     133                    break;
     134                }
     135                case Action::FIGHTALL:
     136                {
     137                    if (!this->hasTarget())
     138                    {
     139                        this->chooseTarget();
     140                    }
     141                    break;
     142                }
     143                case Action::ATTACK:
     144                {
     145                    if (!this->hasTarget())
     146                    {
     147                        this->chooseTarget();
     148                    }
     149                    break;
     150                }
     151                default:
     152                {
     153                    //formation flight is executed in tick
     154                    ControllableEntity* myEntity = this->getControllableEntity();
    86155            Vector3 myPosition = myEntity->getWorldPosition();
    87156            if (!this->myDivisionLeader_)
     
    111180               this->getControllableEntity()->boost(false);
    112181            }
    113         }   
    114         SUPER(SectionController, tick, dt);
    115     }
    116 
    117     void SectionController::action()
    118     {
    119         if (!this || !this->getControllableEntity())
    120             return;
    121 
    122         //----If no leader, find one---- 
    123         if (!myDivisionLeader_)
    124         {
    125             LeaderController* newDivisionLeader = findNewDivisionLeader();
    126             this->myDivisionLeader_ = newDivisionLeader;
    127 
    128         }
    129         //----If have leader----
    130         else
    131         {
    132         }
    133         if (!myDivisionLeader_)
    134         {
    135            
    136             ActionpointController::action();
    137             if (!this || !this->getControllableEntity())
    138                 return;
    139             if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))
    140             {
    141                 if (this->myWingman_)
    142                 {
    143                     this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
    144                 }   
    145             }
    146         }
    147         else if (myDivisionLeader_)
    148         {
    149             switch (myDivisionLeader_->getAction())
    150             {
    151                 case Action::FIGHT:
    152                 {
    153                     if (!this->hasTarget())
    154                     {
    155                         this->chooseTarget();
    156                     }
    157                     break;
    158                 }
    159                 case Action::FIGHTALL:
    160                 {
    161                     if (!this->hasTarget())
    162                     {
    163                         this->chooseTarget();
    164                     }
    165                     break;
    166                 }
    167                 case Action::ATTACK:
    168                 {
    169                     if (!this->hasTarget())
    170                     {
    171                         this->chooseTarget();
    172                     }
    173                     break;
    174                 }
    175                 default:
    176                 {
    177                     //formation flight is executed in tick
    178182                }
    179183            }
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc

    r10877 r10879  
    7171            Action::FIGHTALL && this->myLeader_->getAction() != Action::ATTACK)
    7272        {
     73        }   
     74       
     75        SUPER(WingmanController, tick, dt);
     76    }
     77   
     78    //----action for hard calculations----
     79    void WingmanController::action()
     80    {
     81
     82        //----If no leader, find one----
     83        if (!this->myLeader_)
     84        {
     85            ActionpointController* newLeader = (findNewLeader());
     86            this->myLeader_ = newLeader;
     87            if (this->myLeader_)
     88            {
     89
     90            }
     91        }
     92        //----If have leader, he will deal with logic----
     93        else
     94        {
     95
     96        }
     97        if (!this->myLeader_)
     98        {
     99           ActionpointController::action();
     100        }
     101        else if (this->myLeader_)
     102        {
     103            switch (this->myLeader_->getAction())
     104            {
     105                case Action::FIGHT:
     106                {
     107                    if (!this->hasTarget())
     108                    {
     109                        this->setTarget(this->myLeader_->getTarget());
     110                    }
     111                    break;
     112                }
     113                case Action::FIGHTALL:
     114                {
     115                    if (!this->hasTarget())
     116                    {
     117                        this->setTarget(this->myLeader_->getTarget());
     118                    }
     119                    break;
     120                }
     121                case Action::ATTACK:
     122                {
     123                    if (!this->hasTarget())
     124                    {
     125                        this->setTarget(this->myLeader_->getTarget());
     126                    }
     127                    break;
     128                }
     129                default:
     130                {
     131                   
    73132            ControllableEntity* myEntity = this->getControllableEntity();
    74133            Vector3 myPosition = myEntity->getWorldPosition();
     
    80139            Quaternion orient = leaderEntity->getWorldOrientation();
    81140            Vector3 leaderPosition = leaderEntity->getWorldPosition();
    82 
    83141            Vector3 targetRelativePosition = getFormationPosition();
    84142            if (!this->myLeader_)
     
    99157               this->getControllableEntity()->boost(false);
    100158            }
    101         }   
    102        
    103         SUPER(WingmanController, tick, dt);
    104     }
    105    
    106     //----action for hard calculations----
    107     void WingmanController::action()
    108     {
    109 
    110         //----If no leader, find one----
    111         if (!this->myLeader_)
    112         {
    113             ActionpointController* newLeader = (findNewLeader());
    114             this->myLeader_ = newLeader;
    115            
    116         }
    117         //----If have leader, he will deal with logic----
    118         else
    119         {
    120 
    121         }
    122         if (!this->myLeader_)
    123         {
    124            ActionpointController::action();
    125         }
    126         else if (this->myLeader_)
    127         {
    128             switch (this->myLeader_->getAction())
    129             {
    130                 case Action::FIGHT:
    131                 {
    132                     if (!this->hasTarget())
    133                     {
    134                         this->setTarget(this->myLeader_->getTarget());
    135                     }
    136                     break;
    137                 }
    138                 case Action::FIGHTALL:
    139                 {
    140                     if (!this->hasTarget())
    141                     {
    142                         this->setTarget(this->myLeader_->getTarget());
    143                     }
    144                     break;
    145                 }
    146                 case Action::ATTACK:
    147                 {
    148                     if (!this->hasTarget())
    149                     {
    150                         this->setTarget(this->myLeader_->getTarget());
    151                     }
    152                     break;
    153                 }
    154                 default:
    155                 {
    156                    
    157159                }
    158160            }
     
    179181                case FormationMode::WALL:
    180182                {
    181                     targetRelativePosition = new Vector3 (2*this->spread_, 0, 0); 
     183                    targetRelativePosition = new Vector3 (2*this->spread_, 0, 0 - this->tolerance_); 
    182184                    break;
    183185                }
    184186                case FormationMode::FINGER4:
    185187                {
    186                     targetRelativePosition = new Vector3 (2*this->spread_, 0, this->spread_); 
     188                    targetRelativePosition = new Vector3 (2*this->spread_, 0, this->spread_ - this->tolerance_); 
    187189                    break;
    188190                }
    189191                case FormationMode::DIAMOND:
    190192                {
    191                     targetRelativePosition = new Vector3 (2*this->spread_, 0, this->spread_);                 
     193                    targetRelativePosition = new Vector3 (2*this->spread_, 0, this->spread_ - this->tolerance_);                 
    192194                    break;
    193195                }
     
    200202                case FormationMode::WALL:
    201203                {
    202                     targetRelativePosition = new Vector3 (-2*this->spread_, 0, 0); 
     204                    targetRelativePosition = new Vector3 (-2*this->spread_, 0, 0 - this->tolerance_); 
    203205                    break;
    204206                }
    205207                case FormationMode::FINGER4:
    206208                {
    207                     targetRelativePosition = new Vector3 (-2*this->spread_, 0, this->spread_); 
     209                    targetRelativePosition = new Vector3 (-2*this->spread_, 0, this->spread_ - this->tolerance_); 
    208210                    break;
    209211                }
    210212                case FormationMode::DIAMOND:
    211213                {
    212                     targetRelativePosition = new Vector3 (2*this->spread_, -this->spread_, 0);                 
     214                    targetRelativePosition = new Vector3 (2*this->spread_, -this->spread_, 0 - this->tolerance_);                 
    213215                    break;
    214216                }
Note: See TracChangeset for help on using the changeset viewer.