- Timestamp:
- Nov 27, 2015, 7:58:44 PM (9 years ago)
- Location:
- code/branches/campaignHS15
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/data/levels/AITest.oxw
r10877 r10879 62 62 <!-- HERE STARTS DEMO FOR THE ACTIONPOINTS. 63 63 P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped --> 64 64 <!-- 65 65 <Model mesh="cube.mesh" scale=8 position="0,0,0" /> 66 66 … … 123 123 </templates> 124 124 </SpaceShip> 125 125 --> 126 126 127 127 <!-- HERE ENDS DEMO FOR THE ACTIONPOINTS --> … … 210 210 <!-- HERE ENDS DEMO FOR FIGHTING --> 211 211 <!-- HERE STARTS DEMO FOR FORMATIONS --> 212 <!--212 213 213 <Model mesh="cube.mesh" scale=8 position=" 0,2000, 0" /> 214 214 <Model mesh="cube.mesh" scale=8 position=" 0,2000,-2000" /> … … 221 221 </templates> 222 222 <controller> 223 <DivisionController team=0 formationMode=" DIAMOND" spread=100>223 <DivisionController team=0 formationMode="Finger4" spread=100> 224 224 <actionpoints> 225 225 <Actionpoint position=" 0,2000, 0" action="FLY" loopStart=true/> … … 259 259 </controller> 260 260 </SpaceShip> 261 -->261 262 262 <!-- HERE ENDS DEMO FOR FORMATIONS --> 263 263 <!-- -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
r10877 r10879 82 82 } 83 83 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()); 84 89 this->bFirstTick_ = false; 90 91 } 85 92 SUPER(ActionpointController, tick, dt); 86 93 } … … 358 365 (this->getProtect()->getWorldOrientation()* (*targetRelativePosition))); 359 366 this->setTargetPosition(targetAbsolutePosition); 367 this->setTargetOrientation(this->getProtect()->getWorldOrientation()); 360 368 } 361 369 void ActionpointController::nextActionpoint() -
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 -
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
r10877 r10879 82 82 FormationMode::Value formationMode_; 83 83 84 84 float rotationProgress_; 85 85 bool bHasTargetPosition_; 86 86 Vector3 targetPosition_; -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
r10877 r10879 83 83 Action::FIGHTALL && this->myDivisionLeader_->getAction() != Action::ATTACK) 84 84 { 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(); 86 155 Vector3 myPosition = myEntity->getWorldPosition(); 87 156 if (!this->myDivisionLeader_) … … 111 180 this->getControllableEntity()->boost(false); 112 181 } 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 else131 {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 tick178 182 } 179 183 } -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
r10877 r10879 71 71 Action::FIGHTALL && this->myLeader_->getAction() != Action::ATTACK) 72 72 { 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 73 132 ControllableEntity* myEntity = this->getControllableEntity(); 74 133 Vector3 myPosition = myEntity->getWorldPosition(); … … 80 139 Quaternion orient = leaderEntity->getWorldOrientation(); 81 140 Vector3 leaderPosition = leaderEntity->getWorldPosition(); 82 83 141 Vector3 targetRelativePosition = getFormationPosition(); 84 142 if (!this->myLeader_) … … 99 157 this->getControllableEntity()->boost(false); 100 158 } 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 else119 {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 157 159 } 158 160 } … … 179 181 case FormationMode::WALL: 180 182 { 181 targetRelativePosition = new Vector3 (2*this->spread_, 0, 0 );183 targetRelativePosition = new Vector3 (2*this->spread_, 0, 0 - this->tolerance_); 182 184 break; 183 185 } 184 186 case FormationMode::FINGER4: 185 187 { 186 targetRelativePosition = new Vector3 (2*this->spread_, 0, this->spread_ );188 targetRelativePosition = new Vector3 (2*this->spread_, 0, this->spread_ - this->tolerance_); 187 189 break; 188 190 } 189 191 case FormationMode::DIAMOND: 190 192 { 191 targetRelativePosition = new Vector3 (2*this->spread_, 0, this->spread_ );193 targetRelativePosition = new Vector3 (2*this->spread_, 0, this->spread_ - this->tolerance_); 192 194 break; 193 195 } … … 200 202 case FormationMode::WALL: 201 203 { 202 targetRelativePosition = new Vector3 (-2*this->spread_, 0, 0 );204 targetRelativePosition = new Vector3 (-2*this->spread_, 0, 0 - this->tolerance_); 203 205 break; 204 206 } 205 207 case FormationMode::FINGER4: 206 208 { 207 targetRelativePosition = new Vector3 (-2*this->spread_, 0, this->spread_ );209 targetRelativePosition = new Vector3 (-2*this->spread_, 0, this->spread_ - this->tolerance_); 208 210 break; 209 211 } 210 212 case FormationMode::DIAMOND: 211 213 { 212 targetRelativePosition = new Vector3 (2*this->spread_, -this->spread_, 0 );214 targetRelativePosition = new Vector3 (2*this->spread_, -this->spread_, 0 - this->tolerance_); 213 215 break; 214 216 }
Note: See TracChangeset
for help on using the changeset viewer.