[Orxonox-commit 6124] r10782 - code/branches/AI_HS15/src/orxonox/controllers

gania at orxonox.net gania at orxonox.net
Mon Nov 9 11:19:52 CET 2015


Author: gania
Date: 2015-11-09 11:19:51 +0100 (Mon, 09 Nov 2015)
New Revision: 10782

Modified:
   code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
   code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
Log:
not compilable change to move behaviour

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-11-08 20:10:30 UTC (rev 10781)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-11-09 10:19:51 UTC (rev 10782)
@@ -250,17 +250,97 @@
             bHasTargetOrientation_ = false;
         }
     }
+    //to be called in action
+    //PRE: relativeTargetPosition is desired position relative to the spaceship,
+    //angleRoll is the angle of Roll that should be applied by the end of the movement
+    //POST: targetPosition_ and angleRoll_ are set, so that it can be used by MoveAndRoll()
+    void MoveToPoint(const Vector3& relativeTargetPosition, float angleRoll)
+    {
+        ControllableEntity* entity = this->getControllableEntity();
+        if (!entity)
+            return false;
+        Quaternion orient = entity->getWorldOrientation();
 
-    bool CommonController::isCloseAtTarget(float distance) const
+        Vector3 target = orient * relativeTargetPosition + entity->getWorldPosition();
+        setTargetPosition(target);
+        this->angleRoll_ = angleRoll;
+        this->angleRolled_ = 0;
+    }
+    //to be called in tick
+    //PRE: MoveToPoint was called
+    //POST: spaceship changes its yaw and pitch to point towards targetPosition_,
+    //moves towards targetPosition_ by amount depending on dt and its speed,
+    //rolls by amount depending on the difference between angleRoll_ and angleRolled_, dt, and 
+    //angular speed
+    //if position reached with a certain tolerance, and angleRolled_ = angleRoll_, returns false,
+    //otherwise returns true
+    bool MoveAndRoll(float dt)
     {
-        if (!this->getControllableEntity())
+        int tolerance = 60;
+        float rollDiff = angleRoll-angleRolled_;
+        float angleToRoll = 0;
+        ControllableEntity* entity = this->getControllableEntity();
+        if (!entity)
             return false;
+        Vector2 coord = get2DViewCoordinates
+            (entity->getPosition(), 
+            entity->getOrientation() * WorldEntity::FRONT, 
+            entity->getOrientation() * WorldEntity::UP, 
+            targetPosition_);
 
-        if (!this->target_)
-            return (this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_) < distance*distance);
+        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);
+
+        
+        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);
+            
+            //Move
+            this->getControllableEntity()->moveFrontBack(1.2f * SPEED * factor * dt);
+            
+            //Roll
+            angleToRoll = rollDiff * ROTATEFACTOR * dt;
+            this->getControllableEntity()->rotateRoll(angleToRoll);
+            angleRolled_ += angleToRoll;
+            //if still moving, return false
+            return false;
+        }
         else
-            return (this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance);
+        {     
+            if (rollDiff > 0)
+            {
+                //Roll
+                angleToRoll = rollDiff * ROTATEFACTOR * dt;
+                this->getControllableEntity()->rotateRoll(angleToRoll);
+                angleRolled_ += angleToRoll;                
+
+                //Move
+                this->getControllableEntity()->moveFrontBack(0.6f * SPEED * factor);
+                return false;
+            }
+            //if finished, return true;
+            retun true;
+        }
     }
+
+    float squaredDistanceToTarget()
+    {
+        if ( !this->getControllableEntity() )
+            return 0;
+        if ( !this->target_ )
+            return ( this->getControllableEntity()->
+                getPosition().squaredDistance(this->targetPosition_) );
+        else
+            return ( this->getControllableEntity()->
+                getPosition().squaredDistance(this->target_->getPosition()) );
+    }
+    
     bool CommonController::isLookingAtTarget(float angle) const
     {
         if (!this->getControllableEntity())
@@ -271,7 +351,8 @@
 
     bool CommonController::canFire()
     {
-        if ( this->bShooting_ && this->isCloseAtTarget(3000) && this->isLookingAtTarget(math::pi / 20.0f) )
+        float squaredDistance = squaredDistanceToTarget();
+        if ( this->bShooting_ && squaredDistance < 9000000 && squaredDistance > 10000 && this->isLookingAtTarget(math::pi /(0.0002f*squaredDistance)) )
         {
             return true;
         }

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-11-08 20:10:30 UTC (rev 10781)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-11-09 10:19:51 UTC (rev 10782)
@@ -128,7 +128,7 @@
             void copyOrientation(const Quaternion& orient);
             void copyTargetOrientation();
 
-            bool isCloseAtTarget(float distance) const;
+            float squaredDistanceToTarget() const;
             void doFire();
             void aimAtTarget();
             bool isLookingAtTarget(float angle) const;
@@ -149,15 +149,18 @@
             Quaternion targetOrientation_;
 
 
-            bool bHasObjectivePosition_;
-            Vector3 objectivePosition_;
-            bool bHasObjectiveOrientation_;
-            Quaternion objectiveOrientation_;
+            bool bHasPositionOfTarget_;
+            Vector3 positionOfTarget_;
+            bool bHasOrientationOfTarget_;
+            Quaternion orientationOfTarget_;
 
+
             WeakPtr<ControllableEntity> target_;
             bool bShooting_;
             WeakPtr<ControllableEntity> objectiveTarget_;
 
+            float angleRolled_;
+            float angleRoll_;
 
 
             FormationMode::Value formationMode_;




More information about the Orxonox-commit mailing list