00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __CYLINDER__
00024 #define __CYLINDER__
00025
00026 #include "vector3d.h"
00027 #include "matrix3x3.h"
00028 #include "quaternion.h"
00029 #include "action.h"
00030 #include <vector>
00031
00032 class Agent;
00033 class World;
00034 class Collision;
00035
00036
00037
00038
00039
00040
00041
00042 class Cylinder{
00043 protected:
00044
00045
00046
00047
00048
00049
00050 union{
00051 double height;
00052 double length;
00053 };
00054
00055 union{
00056 double width;
00057 double radius;
00058 };
00059
00060 Matrix3x3 inertia;
00061
00062 Matrix3x3 inertiaInverse;
00063
00064
00065
00066
00067
00068
00069 Point3d gluePosition;
00070
00071
00072
00073 Point3d gluePositionBody;
00074
00075
00076
00077 Point3d position;
00078
00079 Quaternion orientationBase;
00080
00081 Vector3d orientationWorld;
00082
00083 Vector3d velocity;
00084
00085 Vector3d angularVelocity;
00086
00087 Vector3d force;
00088
00089 Vector3d moment;
00090
00091
00092
00093
00094 double energy;
00095
00096 double mass;
00097
00098
00099
00100
00101
00102
00103
00104 Point3d oldPosition;
00105
00106 Quaternion oldOrientationBase;
00107
00108 Vector3d oldVelocity;
00109
00110 Vector3d oldAngularVelocity;
00111
00112 Vector3d oldForce;
00113
00114 Vector3d oldMoment;
00115
00116
00117
00118
00119
00120 vector<Cylinder *> son;
00121
00122 Cylinder *father;
00123
00124 Agent *agent;
00125
00126 World *world;
00127
00128
00129 unsigned char cylinderId;
00130
00131
00132 Action desiredAction;
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 Cylinder *grow(GrowType type, unsigned short int energy);
00143 Cylinder *move(MoveType type, unsigned short int energy);
00144 Cylinder *drop(unsigned char son, const char *creationMessage, unsigned long int messageSize);
00145 Cylinder *createCylinder(double angle, double height, unsigned short int energy);
00146 Cylinder *sendEnergyTo(unsigned char son, unsigned short int energy);
00147 Cylinder *sendMessage(unsigned long int agentId, const char *message, unsigned long int size);
00148
00149
00150
00151 Cylinder *operator()(unsigned short int, unsigned short int &actual);
00152
00153 public:
00154 Cylinder(World *_world, Cylinder *_father,
00155 double newEnergy, double newWidth, double newHeight,
00156 Vector3d newGluePositionBody, bool onAgent);
00157 ~Cylinder();
00158
00159
00160
00161
00162
00163
00164 Point3d getPosition(bool relative=false);
00165 Point3d getGluePosition(bool relative=false);
00166 Point3d getCentreOfGravity(void);
00167
00168 Vector3d getOrientation(){ return orientationWorld; };
00169 Cylinder *getFather(){ return father; };
00170 Agent *getAgent(){ return agent; };
00171 double getHeight(){ return height; };
00172 double getWidth(){ return width; };
00173
00174 double getEnergy(){ return energy; };
00175 double getMass(bool pending=false);
00176
00177 unsigned char getId(){ return cylinderId; };
00178
00179
00180 Cylinder *operator[](unsigned short int);
00181
00182 Cylinder *operator()(unsigned short int n){ unsigned short int a=0; return (*this)(n,a); }
00183 unsigned short int getNumCylinders();
00184
00185 signed short int dist(Cylinder *cyl);
00186 World *getWorld();
00187
00188 void updateMomentOfInertia();
00189
00190
00191
00192 void setNewAgent(Agent *);
00193
00194
00195 Cylinder *dropEnergy(double energyMass);
00196
00197 void newIntention(const Action &a){ desiredAction=a; };
00198
00199 void newCycle();
00200
00201
00202 Cylinder *performAction();
00203
00204
00205
00206
00207
00208
00209
00210 void applyForce(const Vector3d &force, const Point3d &where);
00211
00212 void applyForceOnBody(const Vector3d &force, const Point3d &where);
00213
00214 void applyVelocity(double dtime);
00215
00216 void undoVelocity(void);
00217
00218 void setToGluePosition(void);
00219
00220 void movePosition(const Vector3d &ammount);
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 vector<Collision *> checkCollisions();
00232
00233 Collision *checkGroundCollision(void);
00234
00235 Collision *checkCylinderCollision(Cylinder *other);
00236
00237
00238 friend class Collision;
00239
00240 };
00241
00242 #endif