Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/AI/src/Arrival.h @ 1527

Last change on this file since 1527 was 495, checked in by motth, 17 years ago

fixed a memory leak, added documentation

File size: 1.9 KB
RevLine 
[426]1
2// Arrival Class
3
4
[495]5#ifndef Arrival_Class
6#define Arrical_Class
[426]7
8#include <Ogre.h>
9#include <OgreVector3.h>
10
11
12#include <iostream>
13
14
15#endif
16
17using namespace std;
18using namespace Ogre;
19
20class 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() {
[495]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
[426]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) {
[495]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
[426]81    }
82    else {
83
[495]84
[426]85    }
86
87  }
88}
Note: See TracBrowser for help on using the repository browser.