[Orxonox-commit 6141] r10799 - code/branches/AI_HS15/src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Thu Nov 12 13:03:34 CET 2015
Author: gania
Date: 2015-11-12 13:03:34 +0100 (Thu, 12 Nov 2015)
New Revision: 10799
Modified:
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
Log:
prettier now
Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-11-12 10:31:46 UTC (rev 10798)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-11-12 12:03:34 UTC (rev 10799)
@@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * of the License, or ( at your option )any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -43,11 +43,11 @@
namespace orxonox
{
- RegisterClass(CommonController);
+ RegisterClass( CommonController );
float SPEED = 0.7f/0.02f;
float ROTATEFACTOR = 0.3f/0.02f;
- CommonController::CommonController(Context* context) : Controller(context)
+ CommonController::CommonController( Context* context ): Controller( context )
{
this->bSetupWorked = false;
@@ -55,40 +55,40 @@
this->executingMoveToPoint_ = false;
this->maneuverType_ = ManeuverType::NONE;
- RegisterObject(CommonController);
+ RegisterObject( CommonController );
}
- CommonController::~CommonController()
+ CommonController::~CommonController()
{
}
- void CommonController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
{
- SUPER(CommonController, XMLPort, xmlelement, mode);
- XMLPortParam(CommonController, "formationMode", setFormationModeXML, getFormationModeXML, xmlelement, mode);
+ SUPER( CommonController, XMLPort, xmlelement, mode );
+ XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML, xmlelement, mode );
}
- void CommonController::setFormationModeXML(std::string val)
+ void CommonController::setFormationModeXML( std::string val )
{
- const std::string valUpper = getUppercase(val);
+ const std::string valUpper = getUppercase( val );
FormationMode::Value value;
- if (valUpper == "VEE")
+ if ( valUpper == "VEE" )
value = FormationMode::VEE;
- else if (valUpper == "WALL")
+ else if ( valUpper == "WALL" )
value = FormationMode::WALL;
- else if (valUpper == "FINGER4")
+ else if ( valUpper == "FINGER4" )
value = FormationMode::FINGER4;
- else if (valUpper == "DIAMOND")
+ else if ( valUpper == "DIAMOND" )
value = FormationMode::DIAMOND;
else
- ThrowException(ParseError, std::string("Attempting to set an unknown FormationMode: '") + val + "'.");
- this->setFormationMode(value);
+ ThrowException( ParseError, std::string( "Attempting to set an unknown FormationMode: '" )+ val + "'." );
+ this->setFormationMode( value );
}
- std::string CommonController::getFormationModeXML()
+ std::string CommonController::getFormationModeXML()
{
- switch (this->formationMode_)
+ switch ( this->formationMode_ )
{
case FormationMode::VEE:
{
@@ -116,28 +116,42 @@
}
}
- void CommonController::maneuver()
+ void CommonController::maneuver()
{
- if (this->target_ && this->bHasPositionOfTarget_ && this->getControllableEntity())
+ if ( this->target_ && this->bHasPositionOfTarget_ && this->getControllableEntity() )
{
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
+ Vector3 thisPosition = this->getControllableEntity() ->getWorldPosition();
+ Quaternion thisOrientation = this->getControllableEntity() ->getOrientation();
+
+ /*this->setPositionOfTarget( getPredictedPosition(
+ thisPosition,
+ hardcoded_projectile_speed,
+ this->target_->getWorldPosition() ,
+ this->target_->getVelocity()
+ ) );*/
+ this->setPositionOfTarget( this->target_->getWorldPosition() );
+ this->setOrientationOfTarget( this->target_->getControllableEntity() ->getOrientation() );
+
+
+ Vector3 diffVector = this->positionOfTarget_ - thisPosition;
float diffLength = diffVector.length();
Vector3 diffUnit = diffVector/diffLength;
- Vector3 myForwardVector = this->getControllableEntity()->getOrientation() * WorldEntity::FRONT;
- float myDotProduct = diffVector.dotProduct(myForwardVector);
+ Vector3 thisForwardVector = thisOrientation * WorldEntity::FRONT;
+ float thisDotProduct = diffVector.dotProduct( thisForwardVector );
- Vector3 opponentForwardVector = this->target_->getOrientation() * WorldEntity::FRONT;
- float opponentDotProduct = diffVector.dotProduct(opponentForwardVector);
+ Vector3 targetForwardVector = this->orientationOfTarget_ * WorldEntity::FRONT;
+ float targetDotProduct = diffVector.dotProduct( targetForwardVector );
- float myAngle = math::arccos ( myForwardVector.dotProduct(diffVector)/(diffLength) );
- float targetAngle = math::arccos ( opponentForwardVector.dotProduct(-diffVector)/(diffLength) );
+ float thisAngle = getAngle( thisPosition, thisForwardVector, this->positionOfTarget_ );
+ float targetAngle = getAngle( this->positionOfTarget_, targetForwardVector, thisPosition );
+
+
+ bool bThisIsLookingAtTarget = ( thisAngle/( diffLength*diffLength ) < math::pi/8000000.0f );
+ bool bTargetIsLookingAtThis = ( targetAngle/( diffLength*diffLength ) < math::pi/8000000.0f );
- bool bThisIsLookingAtTarget = (myAngle/(diffLength*diffLength) < math::pi/8000000.0f);
- bool bTargetIsLookingAtThis = (targetAngle/(diffLength*diffLength) < math::pi/8000000.0f);
-
- float angleDiff = targetAngle - myAngle;
+ float angleDiff = targetAngle - thisAngle;
//if his angle is bigger than mine
if ( angleDiff > 0 )
@@ -151,24 +165,24 @@
Vector3* target = new Vector3 ( 0, -200, -200 );
moveToPoint(
*target,
- randomInRange(45, 180)
+ randomInRange( 45, 180 )
);
}
//do scissors
else
{
- Vector3 target = (diffUnit) * 150.0f
+ Vector3 target = ( diffUnit )* 150.0f
Vector3* randVector = new Vector3(
- randomInRange(-300, 300),
- randomInRange(-300, 300),
- randomInRange(-300, 300)
+ randomInRange( -300, 300 ),
+ randomInRange( -300, 300 ),
+ randomInRange( -300, 300 )
);
- Vector3 projection = randVector.dotProduct(diffUnit) * diffUnit;
+ Vector3 projection = randVector.dotProduct( diffUnit )* diffUnit;
*randVector -= projection;
target += randVector;
moveToPoint(
*target,
- randomInRange(45, 180)
+ randomInRange( 45, 180 )
);
}
}
@@ -178,41 +192,41 @@
//if too close
if ( diffLength < 300 )
{
- this->setTargetPosition( this->getControllableEntity()->getWorldPosition() );
+ this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() );
}
//move closer
else
{
- this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector);
+ this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector );
}
}
}
}
- if (this->getControllableEntity() && !this->target_)
+ if ( this->getControllableEntity() && !this->target_ )
{
this->maneuverType_ = ManeuverType::NONE;
}
- orxout (internal_error) << "ManeuverType = " << this->maneuverType_ << endl;
+ orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
}
- void CommonController::chooseManeuverType()
+ void CommonController::chooseManeuverType()
{
- if (this->target_ && this->bHasPositionOfTarget_ && this->getControllableEntity())
+ if ( this->target_ && this->bHasPositionOfTarget_ && this->getControllableEntity() )
{
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
- Vector3 myForwardVector = this->getControllableEntity()->getOrientation() * WorldEntity::FRONT;
- float myDotProduct = diffVector.dotProduct(myForwardVector);
+ Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity() ->getWorldPosition();
+ Vector3 thisForwardVector = this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT;
+ float thisDotProduct = diffVector.dotProduct( thisForwardVector );
- Vector3 opponentForwardVector = this->target_->getOrientation() * WorldEntity::FRONT;
- float opponentDotProduct = diffVector.dotProduct(opponentForwardVector);
+ Vector3 targetForwardVector = this->target_->getOrientation() * WorldEntity::FRONT;
+ float targetDotProduct = diffVector.dotProduct( targetForwardVector );
- switch ((myDotProduct > 0) - (myDotProduct < 0))
+ switch ( ( thisDotProduct > 0 )- ( thisDotProduct < 0 ))
{
case 1:
{
- switch ((opponentDotProduct > 0) - (opponentDotProduct < 0))
+ switch ( ( targetDotProduct > 0 )- ( targetDotProduct < 0 ))
{
case 1:
{
@@ -234,7 +248,7 @@
}
case 0:
{
- switch ((opponentDotProduct > 0) - (opponentDotProduct < 0))
+ switch ( ( targetDotProduct > 0 )- ( targetDotProduct < 0 ))
{
case 1:
{
@@ -257,7 +271,7 @@
}
case -1:
{
- switch ((opponentDotProduct > 0) - (opponentDotProduct < 0))
+ switch ( ( targetDotProduct > 0 )- ( targetDotProduct < 0 ))
{
case 1:
{
@@ -279,156 +293,156 @@
}
}
}
- if (this->getControllableEntity() && !this->target_)
+ if ( this->getControllableEntity() && !this->target_ )
{
this->maneuverType_ = ManeuverType::NONE;
}
- orxout (internal_error) << "ManeuverType = " << this->maneuverType_ << endl;
+ orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
}
- bool CommonController::setWingman (CommonController* wingman)
+ bool CommonController::setWingman ( CommonController* wingman )
{
return false;
}
- bool CommonController::hasWingman()
+ bool CommonController::hasWingman()
{
return true;
}
- void CommonController::setTarget(ControllableEntity* target)
+ void CommonController::setTarget( ControllableEntity* target )
{
this->target_ = target;
- orxout (internal_error) << " TARGET SET " << endl;
+ orxout ( internal_error ) << " TARGET SET " << endl;
- if (this->target_ )
+ if ( this->target_ )
{
- this->setPositionOfTarget(target_->getWorldPosition());
+ this->setPositionOfTarget( target_->getWorldPosition() );
}
}
- bool CommonController::hasTarget()
+ bool CommonController::hasTarget()
{
- if (this->target_)
+ if ( this->target_ )
return true;
return false;
}
- void CommonController::setPositionOfTarget(const Vector3& target)
+ void CommonController::setPositionOfTarget( const Vector3& target )
{
this->positionOfTarget_ = target;
this->bHasPositionOfTarget_ = true;
}
- void CommonController::setOrientationOfTarget(const Quaternion& orient)
+ void CommonController::setOrientationOfTarget( const Quaternion& orient )
{
this->orientationOfTarget_=orient;
this->bHasOrientationOfTarget_=true;
}
- void CommonController::setTargetPosition(const Vector3& target)
+ void CommonController::setTargetPosition( const Vector3& target )
{
this->targetPosition_ = target;
this->bHasTargetPosition_ = true;
}
- void CommonController::setTargetOrientation(const Quaternion& orient)
+ void CommonController::setTargetOrientation( const Quaternion& orient )
{
this->targetOrientation_=orient;
this->bHasTargetOrientation_=true;
}
- void CommonController::setTargetOrientation(ControllableEntity* target)
+ void CommonController::setTargetOrientation( ControllableEntity* target )
{
- if (target)
- setTargetOrientation(target->getOrientation());
+ if ( target )
+ setTargetOrientation( target->getOrientation() );
}
- /*void CommonController::spin()
+ /*void CommonController::spin()
{
this->moveToTargetPosition();
- this->getControllableEntity()->rotateRoll(8.0f);
+ this->getControllableEntity() ->rotateRoll( 8.0f );
}
- void CommonController::turn180()
+ void CommonController::turn180()
{
- Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
+ Vector2 coord = get2DViewdirection( this->getControllableEntity() ->getPosition() , this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT, this->getControllableEntity() ->getOrientation() * WorldEntity::UP, this->targetPosition_ );
- this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
- this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
+ this->getControllableEntity() ->rotateYaw( -2.0f * sgn( coord.x )* coord.x*coord.x );
+ this->getControllableEntity() ->rotatePitch( 2.0f * sgn( coord.y )* coord.y*coord.y );
- this->getControllableEntity()->moveFrontBack(SPEED);
+ this->getControllableEntity() ->moveFrontBack( SPEED );
}*/
//copy the Roll orientation of given Quaternion.
- void CommonController::copyOrientation(const Quaternion& orient, float dt)
+ void CommonController::copyOrientation( const Quaternion& orient, float dt )
{
//roll angle difference in radian
- float 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;
- this->getControllableEntity()->rotateRoll(diff*ROTATEFACTOR * dt);
+ float 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;
+ this->getControllableEntity() ->rotateRoll( diff*ROTATEFACTOR * dt );
}
- void CommonController::copyTargetOrientation(float dt)
+ void CommonController::copyTargetOrientation( float dt )
{
- if (bHasTargetOrientation_)
+ if ( bHasTargetOrientation_ )
{
- copyOrientation(targetOrientation_, dt);
+ copyOrientation( targetOrientation_, dt );
}
}
- void CommonController::moveToTargetPosition(float dt)
+ void CommonController::moveToTargetPosition( float dt )
{
- this->moveToPosition(this->targetPosition_, dt);
+ this->moveToPosition( this->targetPosition_, dt );
}
- void CommonController::moveToPosition(const Vector3& target, float dt)
+ void CommonController::moveToPosition( const Vector3& target, float dt )
{
float factor = 1;
- if (!this->getControllableEntity())
+ if ( !this->getControllableEntity() )
return;
- if (this->rank_ == Rank::DIVISIONLEADER)
+ if ( this->rank_ == Rank::DIVISIONLEADER )
factor = 0.8;
- if (this->rank_ == Rank::SECTIONLEADER)
+ if ( this->rank_ == Rank::SECTIONLEADER )
factor = 0.9;
- //100 is (so far) the smallest tolerance (empirically found) that can be reached,
+ //100 is ( so far )the smallest tolerance ( empirically found )that can be reached,
//with smaller distance spaceships can't reach position and go circles around it instead
int tolerance = 60;
ControllableEntity* entity = this->getControllableEntity();
Vector2 coord = get2DViewCoordinates
- (entity->getPosition(),
- entity->getOrientation() * WorldEntity::FRONT,
- entity->getOrientation() * WorldEntity::UP,
- target);
+ ( entity->getPosition() ,
+ entity->getOrientation() * WorldEntity::FRONT,
+ entity->getOrientation() * WorldEntity::UP,
+ target );
- float distance = (target - this->getControllableEntity()->getPosition()).length();
+ float distance = ( target - this->getControllableEntity() ->getPosition() ).length();
//rotates should be in range [-1,+1], clamp cuts off all that is not
- float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
- float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
+ float rotateX = clamp( coord.x * 10, -1.0f, 1.0f );
+ float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
- if (distance > tolerance)
+ if ( distance > tolerance )
{
//Yaw and Pitch are enough to start facing the target
- this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR * rotateX * dt);
- this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR * rotateY * dt);
+ this->getControllableEntity() ->rotateYaw( -2.0f * ROTATEFACTOR * rotateX * dt );
+ this->getControllableEntity() ->rotatePitch( 2.0f * ROTATEFACTOR * rotateY * dt );
//300 works, maybe less is better
- if (distance < 400)
+ if ( distance < 400 )
{
//Change roll when close. When Spaceship faces target, roll doesn't affect it's trajectory
//It's important that roll is not changed in the process of changing yaw and pitch
//Wingmen won't face same direction as Leaders, but when Leaders start moving
//Yaw and Pitch will adapt.
- if (bHasTargetOrientation_)
+ if ( bHasTargetOrientation_ )
{
- copyTargetOrientation(dt);
+ copyTargetOrientation( dt );
}
}
- this->getControllableEntity()->moveFrontBack(1.2f*SPEED*factor * dt);
+ this->getControllableEntity() ->moveFrontBack( 1.2f*SPEED*factor * dt );
}
else
{
@@ -436,52 +450,52 @@
bHasTargetOrientation_ = false;
}
}
- float CommonController::randomInRange(float a, float b)
+ float CommonController::randomInRange( float a, float b )
{
- float random = rnd(1.0f);
+ float random = rnd( 1.0f );
float diff = b - a;
float r = random * diff;
return a + r;
}
- void CommonController::attack()
+ void CommonController::attack()
{
- if ( !this->getControllableEntity() )
+ if ( !this->getControllableEntity() )
return;
if ( this->target_ )
{
this->positionOfTarget_ = getPredictedPosition(
- this->getControllableEntity()->getWorldPosition(),
+ this->getControllableEntity() ->getWorldPosition() ,
hardcoded_projectile_speed,
- this->target_->getWorldPosition(),
- this->target_->getVelocity()
+ this->target_->getWorldPosition() ,
+ this->target_->getVelocity()
);
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
+ Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity() ->getWorldPosition();
float diffLength = diffVector.length();
- if (diffLength < 100)
+ if ( diffLength < 100 )
{
Vector3* targetPosition;
targetPosition = new Vector3 (
- //randomInRange(200, 300),
+ //randomInRange( 200, 300 ),
0,
- //randomInRange(-300, -200),
+ //randomInRange( -300, -200 ),
0,
- randomInRange(-300, -400)
+ randomInRange( -300, -400 )
);
- Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);
- Vector3 target = rotationToTarget * (*targetPosition);
+ Quaternion rotationToTarget = ( this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT ).getRotationTo( diffVector );
+ Vector3 target = rotationToTarget * ( *targetPosition );
moveToPoint(
target,
- randomInRange(45, 180)
+ randomInRange( 45, 180 )
);
executingMoveToPoint_ = true;
return;
}
this->bShooting_ = true;
this->positionOfTarget_ = getPredictedPosition(
- this->getControllableEntity()->getWorldPosition(),
+ this->getControllableEntity() ->getWorldPosition() ,
hardcoded_projectile_speed,
- this->target_->getWorldPosition(),
- this->target_->getVelocity()
+ this->target_->getWorldPosition() ,
+ this->target_->getVelocity()
);
this->targetPosition_ = positionOfTarget_;
@@ -491,70 +505,70 @@
this->chooseManeuverType();
}
}
- void CommonController::scissors()
+ void CommonController::scissors()
{
- if ( !this->getControllableEntity() )
+ if ( !this->getControllableEntity() )
return;
if ( this->target_ )
{
this->positionOfTarget_ = getPredictedPosition(
- this->getControllableEntity()->getWorldPosition(),
+ this->getControllableEntity() ->getWorldPosition() ,
hardcoded_projectile_speed,
- this->target_->getWorldPosition(),
- this->target_->getVelocity()
+ this->target_->getWorldPosition() ,
+ this->target_->getVelocity()
);
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
+ Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity() ->getWorldPosition();
float diffLength = diffVector.length();
- Vector3 opponentForwardVector = this->target_->getOrientation() * WorldEntity::FRONT;
- float opponentDotProduct = diffVector.dotProduct(opponentForwardVector);
+ Vector3 targetForwardVector = this->target_->getOrientation() * WorldEntity::FRONT;
+ float targetDotProduct = diffVector.dotProduct( targetForwardVector );
- int f = (int) rnd(100.0f);
- f = (f % 2 == 0 ? 1 : -1);
+ int f = ( int )rnd( 100.0f );
+ f = ( f % 2 == 0 ? 1 : -1 );
- if(!this->executingMoveToPoint_)
+ if( !this->executingMoveToPoint_ )
{
Vector3* targetPosition;
if ( diffLength < 100 )
{
targetPosition = new Vector3 (
- //f * randomInRange(200, 300),
+ //f * randomInRange( 200, 300 ),
0,
- //f * randomInRange(-300, -200),
+ //f * randomInRange( -300, -200 ),
0,
- //randomInRange(-300, -400)
+ //randomInRange( -300, -400 )
0
);
}
else
{
- if ( opponentDotProduct < 0 )
+ if ( targetDotProduct < 0 )
{
targetPosition = new Vector3 (
- //f * randomInRange(200, 300),
+ //f * randomInRange( 200, 300 ),
0,
- //f * randomInRange(-300, -200),
+ //f * randomInRange( -300, -200 ),
0,
- //randomInRange(-300, -400)
+ //randomInRange( -300, -400 )
-300
);
}
else
{
targetPosition = new Vector3 (
- //f * randomInRange(200, 300),
+ //f * randomInRange( 200, 300 ),
0,
- //f * randomInRange(-300, -200),
+ //f * randomInRange( -300, -200 ),
0,
- //randomInRange(-300, -400)
+ //randomInRange( -300, -400 )
300
);
}
}
- Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);
- Vector3 target = rotationToTarget * (*targetPosition);
+ Quaternion rotationToTarget = ( this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT ).getRotationTo( diffVector );
+ Vector3 target = rotationToTarget * ( *targetPosition );
moveToPoint(
target,
- randomInRange(45, 180)
+ randomInRange( 45, 180 )
);
executingMoveToPoint_ = true;
}
@@ -565,61 +579,61 @@
this->chooseManeuverType();
}
}
- void CommonController::gunsD()
+ void CommonController::gunsD()
{
- if ( !this->getControllableEntity() )
+ if ( !this->getControllableEntity() )
return;
if ( this->target_ )
{
this->positionOfTarget_ = getPredictedPosition(
- this->getControllableEntity()->getWorldPosition(),
+ this->getControllableEntity() ->getWorldPosition() ,
hardcoded_projectile_speed,
- this->target_->getWorldPosition(),
- this->target_->getVelocity()
+ this->target_->getWorldPosition() ,
+ this->target_->getVelocity()
);
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
+ Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity() ->getWorldPosition();
float diffLength = diffVector.length();
- if(!this->executingMoveToPoint_)
+ if( !this->executingMoveToPoint_ )
{
Vector3* targetPosition;
if ( diffLength < 200 )
{
targetPosition = new Vector3 (
- //f * randomInRange(200, 300),
+ //f * randomInRange( 200, 300 ),
0,
- //f * randomInRange(-300, -200),
+ //f * randomInRange( -300, -200 ),
0,
- //randomInRange(-300, -400)
+ //randomInRange( -300, -400 )
0
);
}
else if ( diffLength < 500 )
{
targetPosition = new Vector3 (
- //randomInRange(100, 200),
+ //randomInRange( 100, 200 ),
0,
- //randomInRange(-200, -100),
+ //randomInRange( -200, -100 ),
0,
- //randomInRange(-400, -600)
+ //randomInRange( -400, -600 )
500
);
}
else
{
targetPosition = new Vector3 (
- //randomInRange(200, 300),
+ //randomInRange( 200, 300 ),
0,
- //randomInRange(-300, -200),
+ //randomInRange( -300, -200 ),
0,
- //randomInRange(-400, -600)
+ //randomInRange( -400, -600 )
500
);
}
- Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);
- Vector3 target = rotationToTarget * (*targetPosition);
+ Quaternion rotationToTarget = ( this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT ).getRotationTo( diffVector );
+ Vector3 target = rotationToTarget * ( *targetPosition );
moveToPoint(
target,
- randomInRange(45, 180)
+ randomInRange( 45, 180 )
);
executingMoveToPoint_ = true;
}
@@ -632,19 +646,19 @@
//to be called in action
//PRE: relativeTargetPosition is desired position relative to the spaceship,
//angleRoll is the angle in degrees of Roll that should be applied by the end of the movement
- //POST: target orientation and position are set, so that it can be used by MoveAndRoll()
- void CommonController::moveToPoint(const Vector3& relativeTargetPosition, float angleRoll)
+ //POST: target orientation and position are set, so that it can be used by MoveAndRoll()
+ void CommonController::moveToPoint( const Vector3& relativeTargetPosition, float angleRoll )
{
ControllableEntity* entity = this->getControllableEntity();
- if (!entity)
+ if ( !entity )
return;
Quaternion orient = entity->getWorldOrientation();
- Quaternion rotation = Quaternion(Degree(angleRoll), Vector3::UNIT_Z);
+ Quaternion rotation = Quaternion( Degree( angleRoll ), Vector3::UNIT_Z );
Vector3 target = orient * relativeTargetPosition + entity->getWorldPosition();
- setTargetPosition(target);
+ setTargetPosition( target );
orient = orient * rotation;
- this->setTargetOrientation(orient);
+ this->setTargetOrientation( orient );
}
//to be called in tick
@@ -656,47 +670,47 @@
//if position reached with a certain tolerance, and angleRolled_ = angleRoll_, returns false,
//otherwise returns true
//dt is normally around 0.02f, which makes it 1/0.02 = 50 frames/sec
- bool CommonController::moveAndRoll(float dt)
+ bool CommonController::moveAndRoll( float dt )
{
float factor = 1;
- if (!this->getControllableEntity())
+ if ( !this->getControllableEntity() )
return false;
- if (this->rank_ == Rank::DIVISIONLEADER)
+ if ( this->rank_ == Rank::DIVISIONLEADER )
factor = 0.8;
- if (this->rank_ == Rank::SECTIONLEADER)
+ if ( this->rank_ == Rank::SECTIONLEADER )
factor = 0.9;
int tolerance = 60;
ControllableEntity* entity = this->getControllableEntity();
- if (!entity)
+ if ( !entity )
return true;
Vector2 coord = get2DViewCoordinates
- (entity->getPosition(),
- entity->getOrientation() * WorldEntity::FRONT,
- entity->getOrientation() * WorldEntity::UP,
- targetPosition_);
+ ( entity->getPosition() ,
+ entity->getOrientation() * WorldEntity::FRONT,
+ entity->getOrientation() * WorldEntity::UP,
+ targetPosition_ );
- float distance = (targetPosition_ - this->getControllableEntity()->getPosition()).length();
+ float distance = ( targetPosition_ - this->getControllableEntity() ->getPosition() ).length();
//rotates should be in range [-1,+1], clamp cuts off all that is not
- float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
- float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
+ float rotateX = clamp( coord.x * 10, -1.0f, 1.0f );
+ float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
- if (distance > tolerance)
+ if ( distance > tolerance )
{
//Yaw and Pitch are enough to start facing the target
- this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR * rotateX * dt);
- this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR * rotateY * dt);
+ this->getControllableEntity() ->rotateYaw( -2.0f * ROTATEFACTOR * rotateX * dt );
+ this->getControllableEntity() ->rotatePitch( 2.0f * ROTATEFACTOR * rotateY * dt );
//Roll
- if (bHasTargetOrientation_)
+ if ( bHasTargetOrientation_ )
{
- copyTargetOrientation(dt);
+ copyTargetOrientation( dt );
}
//Move
- this->getControllableEntity()->moveFrontBack(1.2f * SPEED * factor * dt);
+ this->getControllableEntity() ->moveFrontBack( 1.2f * SPEED * factor * dt );
//if still moving, return false
return false;
}
@@ -708,28 +722,28 @@
}
}
- float CommonController::squaredDistanceToTarget() const
+ float CommonController::squaredDistanceToTarget() const
{
- if ( !this->getControllableEntity() )
+ if ( !this->getControllableEntity() )
return 0;
if ( !this->target_ )
- return ( this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_) );
+ return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) );
else
- return ( this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) );
+ return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->target_->getPosition() ) );
}
- bool CommonController::isLookingAtTarget(float angle) const
+ bool CommonController::isLookingAtTarget( float angle )const
{
- if (!this->getControllableEntity())
+ if ( !this->getControllableEntity() )
return false;
- return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle);
+ return ( getAngle( this->getControllableEntity() ->getPosition() , this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT, this->targetPosition_ ) < angle );
}
- bool CommonController::canFire()
+ bool CommonController::canFire()
{
float squaredDistance = squaredDistanceToTarget();
- if ( this->bShooting_ && squaredDistance < 9000000 && squaredDistance > 10000 && this->isLookingAtTarget(math::pi /(0.0002f*squaredDistance)) )
+ if ( this->bShooting_ && squaredDistance < 9000000 && squaredDistance > 10000 && this->isLookingAtTarget( math::pi /( 0.0002f*squaredDistance )) )
{
return true;
}
@@ -739,22 +753,22 @@
}
}
- void CommonController::doFire()
+ void CommonController::doFire()
{
- if (!this->target_ || !this->getControllableEntity())
+ if ( !this->target_ || !this->getControllableEntity() )
return;
static const float hardcoded_projectile_speed = 750;
- this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
- this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
+ this->targetPosition_ = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
+ this->bHasTargetPosition_ = ( this->targetPosition_ != Vector3::ZERO );
- Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
+ Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
- if (pawn)
- //pawn->setAimPosition(this->getControllableEntity()->getWorldPosition() + 4000*(this->getControllableEntity()->getOrientation() * WorldEntity::FRONT));
- pawn->setAimPosition(this->targetPosition_);
+ if ( pawn )
+ //pawn->setAimPosition( this->getControllableEntity() ->getWorldPosition() + 4000*( this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT ));
+ pawn->setAimPosition( this->targetPosition_ );
- this->getControllableEntity()->fire(0);
+ this->getControllableEntity() ->fire( 0 );
}
More information about the Orxonox-commit
mailing list