[Orxonox-commit 6142] r10800 - code/branches/AI_HS15/src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Fri Nov 13 16:45:45 CET 2015
Author: gania
Date: 2015-11-13 16:45:44 +0100 (Fri, 13 Nov 2015)
New Revision: 10800
Modified:
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
Log:
compilable
Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-11-12 12:03:34 UTC (rev 10799)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-11-13 15:45:44 UTC (rev 10800)
@@ -25,6 +25,7 @@
* Dominik Solenicki
*
*/
+//bug or feature? Press 4 control keys from {Q,W,E,A,S,D,C} at the same time or 3 keys from {Q,E,A,D}, spaceship goes in free fly mode
#include "controllers/CommonController.h"
#include "core/XMLPort.h"
@@ -44,8 +45,8 @@
{
RegisterClass( CommonController );
- float SPEED = 0.7f/0.02f;
- float ROTATEFACTOR = 0.3f/0.02f;
+ float SPEED = 0.9f/0.02f;
+ float ROTATEFACTOR = 0.5f/0.02f;
CommonController::CommonController( Context* context ): Controller( context )
{
@@ -131,7 +132,7 @@
this->target_->getVelocity()
) );*/
this->setPositionOfTarget( this->target_->getWorldPosition() );
- this->setOrientationOfTarget( this->target_->getControllableEntity() ->getOrientation() );
+ this->setOrientationOfTarget( this->target_->getOrientation() );
Vector3 diffVector = this->positionOfTarget_ - thisPosition;
@@ -159,31 +160,28 @@
//if diff is insignificant
if ( bThisIsLookingAtTarget && bTargetIsLookingAtThis )
{
- //if this can make target overshoot
- if ( diffLength < 200 )
+ //no way to dodge
+ if ( diffLength < 400 )
{
Vector3* target = new Vector3 ( 0, -200, -200 );
- moveToPoint(
- *target,
- randomInRange( 45, 180 )
- );
+ this->setTargetPosition( this->positionOfTarget_ );
+
+
}
//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 )
);
- Vector3 projection = randVector.dotProduct( diffUnit )* diffUnit;
+ Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
*randVector -= projection;
- target += randVector;
- moveToPoint(
- *target,
- randomInRange( 45, 180 )
- );
+ target += *randVector;
+ this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() + target );
+
}
}
//this has advantage
@@ -201,6 +199,50 @@
}
}
}
+ else
+ {
+ //if diff is insignificant
+ if ( bThisIsLookingAtTarget && bTargetIsLookingAtThis )
+ {
+ //no way to dodge
+ if ( diffLength < 400 )
+ {
+ Vector3* target = new Vector3 ( 0, -200, -200 );
+ this->setTargetPosition( this->positionOfTarget_ );
+
+ }
+ //do scissors
+ else
+ {
+ Vector3 target = ( diffUnit )* 150.0f;
+ Vector3* randVector = new Vector3(
+ randomInRange( -300, 300 ),
+ randomInRange( -300, 300 ),
+ randomInRange( -300, 300 )
+ );
+ Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
+ *randVector -= projection;
+ target += *randVector;
+ this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() + target );
+
+ }
+ }
+ //target has advantage
+ else
+ {
+ //if too close
+ if ( diffLength < 300 )
+ {
+ this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() );
+ }
+ //move closer
+ else
+ {
+ this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector );
+ }
+ }
+ }
+ this->bShooting_ = true;
}
if ( this->getControllableEntity() && !this->target_ )
@@ -729,7 +771,7 @@
if ( !this->target_ )
return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) );
else
- return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->target_->getPosition() ) );
+ return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->positionOfTarget_ ) );
}
bool CommonController::isLookingAtTarget( float angle )const
@@ -737,12 +779,14 @@
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->positionOfTarget_ ) < angle );
}
bool CommonController::canFire()
{
float squaredDistance = squaredDistanceToTarget();
+ this->setPositionOfTarget( this->target_->getPosition() );
+
if ( this->bShooting_ && squaredDistance < 9000000 && squaredDistance > 10000 && this->isLookingAtTarget( math::pi /( 0.0002f*squaredDistance )) )
{
return true;
@@ -759,14 +803,14 @@
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->positionOfTarget_ = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
+ this->bHasPositionOfTarget_ = ( this->positionOfTarget_ != Vector3::ZERO );
Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
if ( pawn )
//pawn->setAimPosition( this->getControllableEntity() ->getWorldPosition() + 4000*( this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT ));
- pawn->setAimPosition( this->targetPosition_ );
+ pawn->setAimPosition( this->positionOfTarget_ );
this->getControllableEntity() ->fire( 0 );
}
Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h 2015-11-12 12:03:34 UTC (rev 10799)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h 2015-11-13 15:45:44 UTC (rev 10800)
@@ -82,7 +82,7 @@
public:
static const float hardcoded_projectile_speed = 750;
- static const float ACTION_INTERVAL = 1.0f;
+ static const float ACTION_INTERVAL = 2.0f;
CommonController(Context* context);
@@ -166,7 +166,7 @@
bool bShooting_;
WeakPtr<ControllableEntity> objectiveTarget_;
-
+ void maneuver();
void chooseManeuverType();
void gunsD();
void attack();
Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc 2015-11-12 12:03:34 UTC (rev 10799)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc 2015-11-13 15:45:44 UTC (rev 10800)
@@ -68,11 +68,11 @@
this->bShooting_ = true;
}*/
- /* if (this->bHasTargetPosition_)
+ if (this->bHasTargetPosition_)
{
- this->moveToTargetPosition();
- }*/
- if (executingMoveToPoint_)
+ this->moveToTargetPosition(dt);
+ }
+ /* if (executingMoveToPoint_)
{
executingMoveToPoint_ = !this->moveAndRoll(dt);
}
@@ -88,9 +88,9 @@
);
Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
float diffLength = diffVector.length();
- /* Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);
+ Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);
Vector3* targetPosition = new Vector3 ( 0, 0, -200 );
- Vector3 target = rotationToTarget * (*targetPosition);*/
+ Vector3 target = rotationToTarget * (*targetPosition);
if (diffLength > 200)
this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector);
@@ -105,8 +105,8 @@
this->attack();
this->moveAndRoll(dt);
}
- }
- if (this->bShooting_)
+ }*/
+ if (this->bShooting_ && this->canFire())
doFire();
SUPER(DivisionController, tick, dt);
@@ -134,6 +134,8 @@
}
}*/
//this->chooseManeuverType();
+ this->maneuver();
+
switch (this->maneuverType_)
{
case ManeuverType::NONE:
More information about the Orxonox-commit
mailing list