Cyclone Cyclone: C:/data/physeng_code/include/cyclone/fgen.h Source File

C:/data/physeng_code/include/cyclone/fgen.h

Go to the documentation of this file.
00001 /*
00002  * Interface file for the force generators.
00003  * 
00004  * Part of the Cyclone physics system.
00005  * 
00006  * Copyright (c) Icosagon 2003. All Rights Reserved.
00007  *
00008  * This software is distributed under license. Use of this software
00009  * implies agreement with all terms and conditions of the accompanying
00010  * software license.
00011  */
00012 
00018 #ifndef CYCLONE_FGEN_H
00019 #define CYCLONE_FGEN_H
00020 
00021 #include "body.h"
00022 #include "pfgen.h"
00023 #include <vector>
00024 
00025 namespace cyclone {
00026 
00028 
00032     class ForceGenerator
00033     {
00034     public:
00035 
00040         virtual void updateForce(RigidBody *body, real duration) = 0;
00041     };
00043 
00045 
00049     class Gravity : public ForceGenerator
00050     {
00052         Vector3 gravity;
00053 
00054     public:
00055 
00057         Gravity(const Vector3 &gravity);
00058 
00060         virtual void updateForce(RigidBody *body, real duration);
00061     };
00063 
00065 
00068     class Spring : public ForceGenerator
00069     {
00074         Vector3 connectionPoint;
00075 
00080         Vector3 otherConnectionPoint;
00081 
00083         RigidBody *other;
00084 
00086         real springConstant;
00087 
00089         real restLength;
00090 
00091     public:
00092 
00094         Spring(const Vector3 &localConnectionPt,
00095                RigidBody *other,
00096                const Vector3 &otherConnectionPt,
00097                real springConstant,
00098                real restLength);
00099 
00101         virtual void updateForce(RigidBody *body, real duration);
00102     };
00104 
00106 
00112     class Explosion : public ForceGenerator, 
00113                       public ParticleForceGenerator
00114     {
00119         real timePassed;
00120 
00121     public:
00123         // Properties of the explosion, these are public because
00124         // there are so many and providing a suitable constructor
00125         // would be cumbersome:
00126 
00130         Vector3 detonation;
00131 
00134         // ... Other Explosion code as before ...
00135 
00137 
00139 
00143         real implosionMaxRadius;
00144 
00150         real implosionMinRadius;
00151 
00156         real implosionDuration;
00157 
00164         real implosionForce;
00166 
00168 
00174         real shockwaveSpeed;
00175 
00181         real shockwaveThickness;
00182 
00191          real peakConcussionForce;
00192 
00197          real concussionDuration;
00198 
00201 
00206          real peakConvectionForce;
00207 
00211          real chimneyRadius;
00212 
00216          real chimneyHeight;
00217 
00224          real convectionDuration;
00226 
00228     public:
00232         Explosion();
00233 
00238         virtual void updateForce(RigidBody * body, real duration);
00239 
00244         virtual void updateForce(Particle *particle, real duration) = 0;
00245         
00247     };
00249 
00251 
00254     class Aero : public ForceGenerator
00255     {
00256         protected:
00261         Matrix3 tensor;
00262 
00267         Vector3 position;
00268 
00275         const Vector3* windspeed;
00276 
00277     public:
00282         Aero(const Matrix3 &tensor, const Vector3 &position,
00283              const Vector3 *windspeed);
00284 
00288         virtual void updateForce(RigidBody *body, real duration);
00289 
00290         protected: 
00296                 void updateForceFromTensor(RigidBody *body, real duration, 
00297                                                                    const Matrix3 &tensor);
00298     };
00300 
00302 
00309     class AeroControl : public Aero
00310     {
00311         protected:
00316         Matrix3 maxTensor;
00317 
00322         Matrix3 minTensor;
00323 
00330         real controlSetting;
00331 
00332     private:
00337         Matrix3 getTensor();
00338 
00339     public:
00344         AeroControl(const Matrix3 &base,
00345                     const Matrix3 &min, const Matrix3 &max,
00346                     const Vector3 &position, const Vector3 *windspeed);
00347 
00355         void setControl(real value);
00356 
00360         virtual void updateForce(RigidBody *body, real duration);
00361     };
00363 
00365 
00369     class AngledAero : public Aero
00370     {
00375         Quaternion orientation;
00376 
00377     public:
00381         AngledAero(const Matrix3 &tensor, const Vector3 &position,
00382              const Vector3 *windspeed);
00383 
00390         void setOrientation(const Quaternion &quat);
00391 
00395         virtual void updateForce(RigidBody *body, real duration);
00396     };
00398 
00400 
00403     class Buoyancy : public ForceGenerator
00404     {
00409         real maxDepth;
00410 
00414         real volume;
00415 
00420         real waterHeight;
00421 
00426         real liquidDensity;
00427 
00431         Vector3 centreOfBuoyancy;
00432 
00433     public:
00434 
00436         Buoyancy(const Vector3 &cOfB, 
00437             real maxDepth, real volume, real waterHeight,
00438             real liquidDensity = 1000.0f);
00439 
00443         virtual void updateForce(RigidBody *body, real duration);
00444     };
00445 
00449         class ForceRegistry
00450         {
00451         protected:
00452 
00457                 struct ForceRegistration
00458                 {
00459                         RigidBody *body;
00460                         ForceGenerator *fg;
00461                 };
00462 
00466                 typedef std::vector<ForceRegistration> Registry;
00467                 Registry registrations;
00468 
00469         public:
00474                 void add(RigidBody* body, ForceGenerator *fg);
00475 
00481                 void remove(RigidBody* body, ForceGenerator *fg);
00482 
00488                 void clear();
00489 
00494                 void updateForces(real duration);
00495         };
00496 }
00497 
00498 
00499 #endif // CYCLONE_FGEN_H