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

C:/data/physeng_code/include/cyclone/pfgen.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 licence. Use of this software
00009  * implies agreement with all terms and conditions of the accompanying
00010  * software licence.
00011  */
00012 
00018 #ifndef CYCLONE_PFGEN_H
00019 #define CYCLONE_PFGEN_H
00020 
00021 #include "core.h"
00022 #include "particle.h"
00024 #include <vector>
00025 
00026 namespace cyclone {
00028 
00030 
00034     class ParticleForceGenerator
00035     {
00036     public:
00037 
00042         virtual void updateForce(Particle *particle, real duration) = 0;
00043     };
00045 
00047 
00051     class ParticleGravity : public ParticleForceGenerator
00052     {
00054         Vector3 gravity;
00055 
00056     public:
00057 
00059         ParticleGravity(const Vector3 &gravity);
00060 
00062         virtual void updateForce(Particle *particle, real duration);
00063     };
00065 
00067 
00071     class ParticleDrag : public ParticleForceGenerator
00072     {
00074         real k1;
00075 
00077         real k2;
00078 
00079     public:
00080 
00082         ParticleDrag(real k1, real k2);
00083 
00085         virtual void updateForce(Particle *particle, real duration);
00086     };
00088 
00090 
00094     class ParticleAnchoredSpring : public ParticleForceGenerator
00095     {
00096         protected:
00098         Vector3 *anchor;
00099 
00101         real springConstant;
00102 
00104         real restLength;
00105 
00106     public:
00107                 ParticleAnchoredSpring();
00108 
00110         ParticleAnchoredSpring(Vector3 *anchor,
00111                                                            real springConstant, 
00112                                                            real restLength);
00113 
00115                 const Vector3* getAnchor() const { return anchor; }
00116 
00118                 void init(Vector3 *anchor,
00119                                   real springConstant, 
00120                                   real restLength);
00121 
00123         virtual void updateForce(Particle *particle, real duration);
00124     };
00126 
00131         class ParticleAnchoredBungee : public ParticleAnchoredSpring
00132         {
00133         public:
00135                 virtual void updateForce(Particle *particle, real duration);
00136         };
00137 
00139 
00143     class ParticleFakeSpring : public ParticleForceGenerator
00144     {
00146         Vector3 *anchor;
00147 
00149         real springConstant;
00150 
00152         real damping;
00153 
00154     public:
00155 
00157         ParticleFakeSpring(Vector3 *anchor, real springConstant,
00158             real damping);
00159 
00161         virtual void updateForce(Particle *particle, real duration);
00162     };
00164 
00166 
00169     class ParticleSpring : public ParticleForceGenerator
00170     {
00172         Particle *other;
00173 
00175         real springConstant;
00176 
00178         real restLength;
00179 
00180     public:
00181 
00183         ParticleSpring(Particle *other,
00184             real springConstant, real restLength);
00185 
00187         virtual void updateForce(Particle *particle, real duration);
00188     };
00190 
00192 
00196     class ParticleBungee : public ParticleForceGenerator
00197     {
00199         Particle *other;
00200 
00202         real springConstant;
00203 
00208         real restLength;
00209 
00210     public:
00211 
00213         ParticleBungee(Particle *other,
00214             real springConstant, real restLength);
00215 
00217         virtual void updateForce(Particle *particle, real duration);
00218     };
00220 
00222 
00226     class ParticleBuoyancy : public ParticleForceGenerator
00227     {
00232         real maxDepth;
00233 
00237         real volume;
00238 
00243         real waterHeight;
00244 
00249         real liquidDensity;
00250 
00251     public:
00252 
00254         ParticleBuoyancy(real maxDepth, real volume, real waterHeight,
00255             real liquidDensity = 1000.0f);
00256 
00258         virtual void updateForce(Particle *particle, real duration);
00259     };
00261 
00263 
00266     class ParticleForceRegistry
00267     {
00268     protected:
00269 
00274         struct ParticleForceRegistration
00275         {
00276             Particle *particle;
00277             ParticleForceGenerator *fg;
00278         };
00279 
00283         typedef std::vector<ParticleForceRegistration> Registry;
00284         Registry registrations;
00285 
00286     public:
00291         void add(Particle* particle, ParticleForceGenerator *fg);
00292 
00298         void remove(Particle* particle, ParticleForceGenerator *fg);
00299 
00305         void clear();
00306 
00311         void updateForces(real duration);
00312     };
00313 }
00315 
00316 #endif // CYCLONE_PFGEN_H