Last change
on this file since 464 was
426,
checked in by motth, 17 years ago
|
added actual flocking code and two frameworks
|
File size:
1.5 KB
|
Rev | Line | |
---|
[426] | 1 | |
---|
| 2 | // Arrival Class |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | #ifndef Flocking_Class |
---|
| 6 | #define Flocking_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 | 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 | rotation = speed.getRotationTo(getDirection()); |
---|
| 68 | // do that turn |
---|
| 69 | |
---|
| 70 | } |
---|
| 71 | else { |
---|
| 72 | |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | } |
---|
| 76 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.