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