[597] | 1 | |
---|
| 2 | // Arrival Class |
---|
| 3 | |
---|
| 4 | |
---|
[673] | 5 | #ifndef _Arrival_H__ |
---|
| 6 | #define _Arrival_H__ |
---|
[597] | 7 | |
---|
[708] | 8 | #include "misc/Vector3.h" |
---|
| 9 | #include "misc/Quaternion.h" |
---|
[597] | 10 | |
---|
[708] | 11 | namespace orxonox |
---|
| 12 | { |
---|
| 13 | class Arrival |
---|
| 14 | { |
---|
[597] | 15 | public: |
---|
[618] | 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 |
---|
[597] | 22 | |
---|
| 23 | |
---|
[708] | 24 | Arrival() { |
---|
| 25 | acceleration = (0,0,0); |
---|
| 26 | speed = (0,0,0); |
---|
| 27 | location = (0,0,0); |
---|
| 28 | target = (0,0,0); |
---|
| 29 | } |
---|
[597] | 30 | |
---|
[708] | 31 | Arrival(Vector3 location_, Vector3 speed_, Vector3 acceleration_, Vector3 target_) { |
---|
| 32 | acceleration = acceleration_; |
---|
| 33 | speed = speed_; |
---|
| 34 | location = location_; |
---|
| 35 | target = target_; |
---|
| 36 | } |
---|
[597] | 37 | |
---|
[708] | 38 | void setValues(Vector3 location_, Vector3 speed_, Vector3 acceleration_, Vector3 target_) { |
---|
| 39 | acceleration = acceleration_; |
---|
| 40 | speed = speed_; |
---|
| 41 | location = location_; |
---|
| 42 | target = target_; |
---|
| 43 | } |
---|
[597] | 44 | |
---|
[708] | 45 | void setTarget(Vector3 target_) { |
---|
| 46 | setValues(this->location, this->speed, this->acceleration, target_); |
---|
| 47 | } |
---|
[597] | 48 | |
---|
[708] | 49 | Vector3 getDirection() { |
---|
| 50 | Vector3 direction = target-location; |
---|
| 51 | } |
---|
[597] | 52 | |
---|
[708] | 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 | } |
---|
[597] | 58 | |
---|
[708] | 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 | } |
---|
[597] | 75 | } |
---|
| 76 | else { |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | |
---|
[708] | 80 | }; |
---|
[673] | 81 | } |
---|
| 82 | |
---|
| 83 | #endif /* _Arrival_H__ */ |
---|