[Orxonox-commit 6222] r10879 - in code/branches/campaignHS15: data/levels src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Fri Nov 27 19:58:45 CET 2015
Author: gania
Date: 2015-11-27 19:58:44 +0100 (Fri, 27 Nov 2015)
New Revision: 10879
Modified:
code/branches/campaignHS15/data/levels/AITest.oxw
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
Log:
finished copyOrientation function. Now ships move smoothly
Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw 2015-11-27 17:49:54 UTC (rev 10878)
+++ code/branches/campaignHS15/data/levels/AITest.oxw 2015-11-27 18:58:44 UTC (rev 10879)
@@ -61,7 +61,7 @@
<!-- HERE STARTS DEMO FOR THE ACTIONPOINTS.
P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped -->
-
+ <!--
<Model mesh="cube.mesh" scale=8 position="0,0,0" />
<SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
@@ -122,7 +122,7 @@
<Template link=spaceshipassff />
</templates>
</SpaceShip>
-
+ -->
<!-- HERE ENDS DEMO FOR THE ACTIONPOINTS -->
<!-- HERE STARTS DEMO FOR FIGHTING -->
@@ -209,7 +209,7 @@
-->
<!-- HERE ENDS DEMO FOR FIGHTING -->
<!-- HERE STARTS DEMO FOR FORMATIONS -->
- <!--
+
<Model mesh="cube.mesh" scale=8 position=" 0,2000, 0" />
<Model mesh="cube.mesh" scale=8 position=" 0,2000,-2000" />
<Model mesh="cube.mesh" scale=8 position="2000,2000,-2000" />
@@ -220,7 +220,7 @@
<Template link=spaceshipassff />
</templates>
<controller>
- <DivisionController team=0 formationMode="DIAMOND" spread=100>
+ <DivisionController team=0 formationMode="Finger4" spread=100>
<actionpoints>
<Actionpoint position=" 0,2000, 0" action="FLY" loopStart=true/>
<Actionpoint position=" 0,2000,-2000" action="FLY" />
@@ -258,7 +258,7 @@
</WingmanController>
</controller>
</SpaceShip>
- -->
+
<!-- HERE ENDS DEMO FOR FORMATIONS -->
<!--
<SpaceShip position="2000, 2000, 2000" lookat="0,0,0" team=1 name="ss2">
Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc 2015-11-27 17:49:54 UTC (rev 10878)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc 2015-11-27 18:58:44 UTC (rev 10879)
@@ -81,7 +81,14 @@
}
}
if (this->bFirstTick_)
+ {
+ // this->getControllableEntity()->setOrientation(1,0,0,0);
+ // this->getControllableEntity()->rotateRoll(-this->getControllableEntity()->getOrientation().getRoll(true).valueRadians());
+ // this->getControllableEntity()->rotateYaw(-this->getControllableEntity()->getOrientation().getYaw(true).valueRadians());
+ // this->getControllableEntity()->rotatePitch(-this->getControllableEntity()->getOrientation().getPitch(true).valueRadians());
this->bFirstTick_ = false;
+
+ }
SUPER(ActionpointController, tick, dt);
}
ActionpointController::~ActionpointController()
@@ -357,6 +364,7 @@
Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
(this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
this->setTargetPosition(targetAbsolutePosition);
+ this->setTargetOrientation(this->getProtect()->getWorldOrientation());
}
void ActionpointController::nextActionpoint()
{
Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc 2015-11-27 17:49:54 UTC (rev 10878)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc 2015-11-27 18:58:44 UTC (rev 10879)
@@ -29,13 +29,14 @@
#include "core/XMLPort.h"
#include "worldentities/pawns/SpaceShip.h"
#include "util/Math.h"
-
+#include <OgreMatrix3.h>
namespace orxonox
{
RegisterClass (FlyingController);
FlyingController::FlyingController( Context* context ): CommonController( context )
{
+ this->rotationProgress_ = 0;
this->spread_ = 200;
this->tolerance_ = 80;
RegisterObject( FlyingController );
@@ -107,15 +108,15 @@
this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
- if ( distance < 300 )
- {
- if ( bHasTargetOrientation_ )
- {
- copyTargetOrientation( dt );
- }
- }
+
if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
this->getControllableEntity() ->moveFrontBack( SPEED * dt );
+
+ // if ( bHasTargetOrientation_ && (rotateX > -0.005 && rotateX < 0.005 && rotateY > -0.005 && rotateY < 0.005) )
+ // {
+ copyTargetOrientation( dt );
+ // }
+
}
else
{
@@ -129,13 +130,34 @@
}
void FlyingController::copyOrientation( const Quaternion& orient, float dt )
{
+ //inspired by
+ //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_
+ //how can I make my objects rotate smoothly?
+
+ Quaternion myOrient = this->getControllableEntity()->getOrientation();
+ this->rotationProgress_ += dt/50.0f;
- double diff=orient.getRoll(false).valueRadians() -
- ( this->getControllableEntity() ->getOrientation() .getRoll( false ).valueRadians() );
- while( diff>math::twoPi)diff-=math::twoPi;
- while( diff<-math::twoPi )diff+=math::twoPi;
+ if (this->rotationProgress_ > 1)
+ {
+ this->rotationProgress_ = 0;
+ }
+ else
+ {
+ Quaternion delta = Quaternion::Slerp(this->rotationProgress_, myOrient, orient, true);
+
+ Matrix3 orientMatrix, myMatrix;
+ delta.ToRotationMatrix(orientMatrix);
+ myOrient.ToRotationMatrix (myMatrix);
- this->getControllableEntity() ->rotateRoll(diff * ROTATEFACTOR * dt);
+ Radian yRad, pRad, rRad, yMy, pMy, rMy;
+ orientMatrix.ToEulerAnglesYXZ(yRad, pRad, rRad);
+ myMatrix.ToEulerAnglesYXZ (yMy, pMy, rMy);
+ orxout (internal_error) << "dt = " << dt << endl;
+ this->getControllableEntity()->rotateRoll (50.0f*dt*(rRad.valueRadians() - rMy.valueRadians()));
+ //this->getControllableEntity()->setOrientation(delta);
+ }
+ //this shit works. How?
+
}
//change log: increased precision, increased rotation speed
void FlyingController::copyTargetOrientation( float dt )
Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h 2015-11-27 17:49:54 UTC (rev 10878)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h 2015-11-27 18:58:44 UTC (rev 10879)
@@ -81,7 +81,7 @@
virtual void boostControl();
FormationMode::Value formationMode_;
-
+ float rotationProgress_;
bool bHasTargetPosition_;
Vector3 targetPosition_;
bool bHasTargetOrientation_;
Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc 2015-11-27 17:49:54 UTC (rev 10878)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc 2015-11-27 18:58:44 UTC (rev 10879)
@@ -82,34 +82,7 @@
if (this->myDivisionLeader_ && this->myDivisionLeader_->getAction() != Action::FIGHT && this->myDivisionLeader_->getAction() !=
Action::FIGHTALL && this->myDivisionLeader_->getAction() != Action::ATTACK)
{
- ControllableEntity* myEntity = this->getControllableEntity();
- Vector3 myPosition = myEntity->getWorldPosition();
- if (!this->myDivisionLeader_)
- {
- return;
- }
- ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity();
- Quaternion orient = leaderEntity->getWorldOrientation();
- Vector3 leaderPosition = leaderEntity->getWorldPosition();
-
- Vector3 targetRelativePosition = getFormationPosition();
- if (!this->myDivisionLeader_)
- {
- return;
- }
- Vector3 targetAbsolutePosition =
- (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
- + (orient* (targetRelativePosition)));
-
- this->setAction (Action::FLY, targetAbsolutePosition, orient);
- if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
- {
- this->boostControl();
- }
- else
- {
- this->getControllableEntity()->boost(false);
- }
+
}
SUPER(SectionController, tick, dt);
}
@@ -124,7 +97,10 @@
{
LeaderController* newDivisionLeader = findNewDivisionLeader();
this->myDivisionLeader_ = newDivisionLeader;
+ if (this->myDivisionLeader_)
+ {
+ }
}
//----If have leader----
else
@@ -175,6 +151,34 @@
default:
{
//formation flight is executed in tick
+ ControllableEntity* myEntity = this->getControllableEntity();
+ Vector3 myPosition = myEntity->getWorldPosition();
+ if (!this->myDivisionLeader_)
+ {
+ return;
+ }
+ ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity();
+ Quaternion orient = leaderEntity->getWorldOrientation();
+ Vector3 leaderPosition = leaderEntity->getWorldPosition();
+
+ Vector3 targetRelativePosition = getFormationPosition();
+ if (!this->myDivisionLeader_)
+ {
+ return;
+ }
+ Vector3 targetAbsolutePosition =
+ (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
+ + (orient* (targetRelativePosition)));
+
+ this->setAction (Action::FLY, targetAbsolutePosition, orient);
+ if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
+ {
+ this->boostControl();
+ }
+ else
+ {
+ this->getControllableEntity()->boost(false);
+ }
}
}
if (this->hasTarget())
Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc 2015-11-27 17:49:54 UTC (rev 10878)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc 2015-11-27 18:58:44 UTC (rev 10879)
@@ -70,34 +70,6 @@
if (this->myLeader_ && this->myLeader_->getAction() != Action::FIGHT && this->myLeader_->getAction() !=
Action::FIGHTALL && this->myLeader_->getAction() != Action::ATTACK)
{
- ControllableEntity* myEntity = this->getControllableEntity();
- Vector3 myPosition = myEntity->getWorldPosition();
- if (!this->myLeader_)
- {
- return;
- }
- ControllableEntity* leaderEntity = this->myLeader_->getControllableEntity();
- Quaternion orient = leaderEntity->getWorldOrientation();
- Vector3 leaderPosition = leaderEntity->getWorldPosition();
-
- Vector3 targetRelativePosition = getFormationPosition();
- if (!this->myLeader_)
- {
- return;
- }
- Vector3 targetAbsolutePosition =
- (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
- + (orient* (targetRelativePosition)));
-
- this->setAction (Action::FLY, targetAbsolutePosition, orient);
- if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
- {
- this->boostControl();
- }
- else
- {
- this->getControllableEntity()->boost(false);
- }
}
SUPER(WingmanController, tick, dt);
@@ -112,7 +84,10 @@
{
ActionpointController* newLeader = (findNewLeader());
this->myLeader_ = newLeader;
-
+ if (this->myLeader_)
+ {
+
+ }
}
//----If have leader, he will deal with logic----
else
@@ -154,6 +129,33 @@
default:
{
+ ControllableEntity* myEntity = this->getControllableEntity();
+ Vector3 myPosition = myEntity->getWorldPosition();
+ if (!this->myLeader_)
+ {
+ return;
+ }
+ ControllableEntity* leaderEntity = this->myLeader_->getControllableEntity();
+ Quaternion orient = leaderEntity->getWorldOrientation();
+ Vector3 leaderPosition = leaderEntity->getWorldPosition();
+ Vector3 targetRelativePosition = getFormationPosition();
+ if (!this->myLeader_)
+ {
+ return;
+ }
+ Vector3 targetAbsolutePosition =
+ (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
+ + (orient* (targetRelativePosition)));
+
+ this->setAction (Action::FLY, targetAbsolutePosition, orient);
+ if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
+ {
+ this->boostControl();
+ }
+ else
+ {
+ this->getControllableEntity()->boost(false);
+ }
}
}
if (this->hasTarget())
@@ -178,17 +180,17 @@
switch (this->formationMode_){
case FormationMode::WALL:
{
- targetRelativePosition = new Vector3 (2*this->spread_, 0, 0);
+ targetRelativePosition = new Vector3 (2*this->spread_, 0, 0 - this->tolerance_);
break;
}
case FormationMode::FINGER4:
{
- targetRelativePosition = new Vector3 (2*this->spread_, 0, this->spread_);
+ targetRelativePosition = new Vector3 (2*this->spread_, 0, this->spread_ - this->tolerance_);
break;
}
case FormationMode::DIAMOND:
{
- targetRelativePosition = new Vector3 (2*this->spread_, 0, this->spread_);
+ targetRelativePosition = new Vector3 (2*this->spread_, 0, this->spread_ - this->tolerance_);
break;
}
}
@@ -199,17 +201,17 @@
switch (this->formationMode_){
case FormationMode::WALL:
{
- targetRelativePosition = new Vector3 (-2*this->spread_, 0, 0);
+ targetRelativePosition = new Vector3 (-2*this->spread_, 0, 0 - this->tolerance_);
break;
}
case FormationMode::FINGER4:
{
- targetRelativePosition = new Vector3 (-2*this->spread_, 0, this->spread_);
+ targetRelativePosition = new Vector3 (-2*this->spread_, 0, this->spread_ - this->tolerance_);
break;
}
case FormationMode::DIAMOND:
{
- targetRelativePosition = new Vector3 (2*this->spread_, -this->spread_, 0);
+ targetRelativePosition = new Vector3 (2*this->spread_, -this->spread_, 0 - this->tolerance_);
break;
}
}
More information about the Orxonox-commit
mailing list