| 1 |  | 
|---|
| 2 | // Arrival Class | 
|---|
| 3 |  | 
|---|
| 4 |  | 
|---|
| 5 | #ifndef _Arrival_H__ | 
|---|
| 6 | #define _Arrival_H__ | 
|---|
| 7 |  | 
|---|
| 8 | #include "misc/Vector3.h" | 
|---|
| 9 | #include "misc/Quaternion.h" | 
|---|
| 10 |  | 
|---|
| 11 | namespace orxonox | 
|---|
| 12 | { | 
|---|
| 13 |   class Arrival | 
|---|
| 14 |   { | 
|---|
| 15 |   public: | 
|---|
| 16 |     Vector3 location;           //!< locationvector of the element | 
|---|
| 17 |     Vector3 speed;              //!< speedvector of the element | 
|---|
| 18 |     Vector3 acceleration;       //!< accelerationvector of the element | 
|---|
| 19 |     Vector3 target;             //!< target to arrive | 
|---|
| 20 |     int accelerationForwards;   //!< from steering-interface | 
|---|
| 21 |     int MaxSpeed;               //!< from steering-interface | 
|---|
| 22 |  | 
|---|
| 23 |  | 
|---|
| 24 |     Arrival() { | 
|---|
| 25 |       acceleration = (0,0,0); | 
|---|
| 26 |       speed = (0,0,0); | 
|---|
| 27 |       location = (0,0,0); | 
|---|
| 28 |       target = (0,0,0); | 
|---|
| 29 |     } | 
|---|
| 30 |  | 
|---|
| 31 |     Arrival(Vector3 location_, Vector3 speed_, Vector3 acceleration_, Vector3 target_) { | 
|---|
| 32 |       acceleration = acceleration_; | 
|---|
| 33 |       speed = speed_; | 
|---|
| 34 |       location = location_; | 
|---|
| 35 |       target = target_; | 
|---|
| 36 |     } | 
|---|
| 37 |  | 
|---|
| 38 |     void setValues(Vector3 location_, Vector3 speed_, Vector3 acceleration_, Vector3 target_) { | 
|---|
| 39 |       acceleration = acceleration_; | 
|---|
| 40 |       speed = speed_; | 
|---|
| 41 |       location = location_; | 
|---|
| 42 |       target = target_; | 
|---|
| 43 |     } | 
|---|
| 44 |  | 
|---|
| 45 |     void setTarget(Vector3 target_) { | 
|---|
| 46 |       setValues(this->location, this->speed, this->acceleration, target_); | 
|---|
| 47 |     } | 
|---|
| 48 |  | 
|---|
| 49 |     Vector3 getDirection() { | 
|---|
| 50 |       Vector3 direction = target-location; | 
|---|
| 51 |     } | 
|---|
| 52 |  | 
|---|
| 53 |     double relativeDirectApproach() { | 
|---|
| 54 |       // Maxspeed / accelerationForwards = time needed to break with max acceleration | 
|---|
| 55 |       // 2*getDistance()length/(MaxSpeed/accelerationForwards)^2 = required acceleration to arrive at the target with speed = 0 | 
|---|
| 56 |       return (accelerationForwards / (2*getDirection().length() / ((MaxSpeed/accelerationForwards)*(MaxSpeed/accelerationForwards))) ); | 
|---|
| 57 |     } | 
|---|
| 58 |  | 
|---|
| 59 |     void Approach() { | 
|---|
| 60 |       Quaternion rotation = Quaternion(0,0,0,0); | 
|---|
| 61 |       if (relativeDirectApproach() > 1) | 
|---|
| 62 |       { | 
|---|
| 63 |         float length = speed.length(); | 
|---|
| 64 |         speed = (speed+getDirection()); | 
|---|
| 65 |         speed.normalise(); | 
|---|
| 66 |         speed = speed*length; | 
|---|
| 67 |         if (relativeDirectApproach() > 4) | 
|---|
| 68 |         { | 
|---|
| 69 |           //accelerate | 
|---|
| 70 |         } | 
|---|
| 71 |         else | 
|---|
| 72 |         { | 
|---|
| 73 |           // speed will stay constant | 
|---|
| 74 |         } | 
|---|
| 75 |       } | 
|---|
| 76 |       else { | 
|---|
| 77 |       } | 
|---|
| 78 |     } | 
|---|
| 79 |  | 
|---|
| 80 |   }; | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | #endif /* _Arrival_H__ */ | 
|---|