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