[Orxonox-commit 6223] r10880 - in code/branches/campaignHS15: data/levels src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Fri Nov 27 22:37:59 CET 2015
Author: gania
Date: 2015-11-27 22:37:59 +0100 (Fri, 27 Nov 2015)
New Revision: 10880
Modified:
code/branches/campaignHS15/data/levels/AITest.oxw
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
code/branches/campaignHS15/src/orxonox/controllers/FightingController.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:
cut smoothness, gained performance
Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw 2015-11-27 18:58:44 UTC (rev 10879)
+++ code/branches/campaignHS15/data/levels/AITest.oxw 2015-11-27 21:37:59 UTC (rev 10880)
@@ -220,7 +220,7 @@
<Template link=spaceshipassff />
</templates>
<controller>
- <DivisionController team=0 formationMode="Finger4" spread=100>
+ <DivisionController team=0 formationMode="diamond" spread=100>
<actionpoints>
<Actionpoint position=" 0,2000, 0" action="FLY" loopStart=true/>
<Actionpoint position=" 0,2000,-2000" action="FLY" />
Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc 2015-11-27 18:58:44 UTC (rev 10879)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc 2015-11-27 21:37:59 UTC (rev 10880)
@@ -359,10 +359,9 @@
void ActionpointController::stayNearProtect()
{
- Vector3* targetRelativePosition;
- targetRelativePosition = new Vector3 (0, 300, 300);
+ Vector3 targetRelativePosition(0, 300, 300);
Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
- (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
+ (this->getProtect()->getWorldOrientation()* (targetRelativePosition)));
this->setTargetPosition(targetAbsolutePosition);
this->setTargetOrientation(this->getProtect()->getWorldOrientation());
}
@@ -566,8 +565,7 @@
{
if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
{
- if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_)
- || !this->target_ )
+ if (!this->target_ || (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_))
{
Pawn* newTarget = this->closestTarget();
if ( newTarget &&
Modified: code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc 2015-11-27 18:58:44 UTC (rev 10879)
+++ code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc 2015-11-27 21:37:59 UTC (rev 10880)
@@ -125,7 +125,7 @@
float diffLength = diffVector.length();
Vector3 diffUnit = diffVector/diffLength;
- bool bTargetIsLookingAtThis = CommonController::isLooking ( this->target_, getControllableEntity(), math::pi/10.0f );
+ bool bTargetIsLookingAtThis = CommonController::isLooking ( this->target_, getControllableEntity(), math::pi/20.0f );
//too far? well, come closer then
if ( diffLength > this->attackRange_ )
@@ -190,8 +190,10 @@
factorZ * CommonController::randomInRange( 10000, 40000 )
);
Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
- *randVector -= projection;
- target += *randVector;
+ Vector3 randV = *randVector;
+ delete randVector;
+ randV -= projection;
+ target += randV;
this->setTargetPosition( thisPosition + target );
}
bool FightingController::canFire()
Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc 2015-11-27 18:58:44 UTC (rev 10879)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc 2015-11-27 21:37:59 UTC (rev 10880)
@@ -37,6 +37,7 @@
FlyingController::FlyingController( Context* context ): CommonController( context )
{
this->rotationProgress_ = 0;
+ this->tickCounter_ = 0;
this->spread_ = 200;
this->tolerance_ = 80;
RegisterObject( FlyingController );
@@ -93,30 +94,28 @@
void FlyingController::moveToPosition( const Vector3& target, float dt )
{
ControllableEntity* entity = this->getControllableEntity();
- Vector2 coord = get2DViewCoordinates
- ( entity->getPosition() ,
- entity->getOrientation() * WorldEntity::FRONT,
- entity->getOrientation() * WorldEntity::UP,
- target );
+ this->tickCounter_ += this->tickCounter_ < 100000 ? 1 : -this->tickCounter_ ;
float distance = ( target - this->getControllableEntity() ->getPosition() ).length();
- float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
- float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
+
if ( distance > this->tolerance_ )
{
+ Vector2 coord = get2DViewCoordinates
+ ( entity->getPosition() ,
+ entity->getOrientation() * WorldEntity::FRONT,
+ entity->getOrientation() * WorldEntity::UP,
+ target );
+ float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
+ float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * 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) )
- // {
+ if (this->tickCounter_ % 10 == 0 )
copyTargetOrientation( dt );
- // }
-
}
else
{
@@ -124,6 +123,7 @@
bHasTargetOrientation_ = false;
}
}
+
void FlyingController::moveToTargetPosition(float dt)
{
this->moveToPosition (this->targetPosition_, dt);
@@ -135,7 +135,7 @@
//how can I make my objects rotate smoothly?
Quaternion myOrient = this->getControllableEntity()->getOrientation();
- this->rotationProgress_ += dt/50.0f;
+ this->rotationProgress_ += 5*dt;
if (this->rotationProgress_ > 1)
{
@@ -143,7 +143,7 @@
}
else
{
- Quaternion delta = Quaternion::Slerp(this->rotationProgress_, myOrient, orient, true);
+ Quaternion delta = Quaternion::Slerp(rotationProgress_, myOrient, orient, true);
Matrix3 orientMatrix, myMatrix;
delta.ToRotationMatrix(orientMatrix);
@@ -152,12 +152,11 @@
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()->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 18:58:44 UTC (rev 10879)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h 2015-11-27 21:37:59 UTC (rev 10880)
@@ -82,6 +82,7 @@
FormationMode::Value formationMode_;
float rotationProgress_;
+ int tickCounter_;
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 18:58:44 UTC (rev 10879)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc 2015-11-27 21:37:59 UTC (rev 10880)
@@ -275,7 +275,9 @@
break;
}
}
- return *targetRelativePosition;
+ Vector3 result = *targetRelativePosition;
+ delete targetRelativePosition;
+ return result;
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc 2015-11-27 18:58:44 UTC (rev 10879)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc 2015-11-27 21:37:59 UTC (rev 10880)
@@ -148,6 +148,7 @@
+ (orient* (targetRelativePosition)));
this->setAction (Action::FLY, targetAbsolutePosition, orient);
+
if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
{
this->boostControl();
@@ -216,8 +217,9 @@
}
}
}
-
- return *targetRelativePosition;
+ Vector3 result = *targetRelativePosition;
+ delete targetRelativePosition;
+ return result;
}
//----POST: closest leader that is ready to take a new wingman is returned----
ActionpointController* WingmanController::findNewLeader()
More information about the Orxonox-commit
mailing list