step/stepcore
softbody.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #ifndef STEPCORE_SOFTBODY_H
00024 #define STEPCORE_SOFTBODY_H
00025
00026 #include "particle.h"
00027 #include "spring.h"
00028 #include "world.h"
00029 #include <cmath>
00030
00031 namespace StepCore {
00032
00036 class SoftBodyParticle: public Particle
00037 {
00038 STEPCORE_OBJECT(SoftBodyParticle)
00039
00040 public:
00042 explicit SoftBodyParticle(Vector2d position = Vector2d(0), Vector2d velocity = Vector2d(0), double mass = 1)
00043 : Particle(position, velocity, mass) {}
00044 };
00045
00049 class SoftBodySpring: public Spring
00050 {
00051 STEPCORE_OBJECT(SoftBodySpring)
00052
00053 public:
00055 explicit SoftBodySpring(double restLength = 0, double stiffness = 1, double damping = 0,
00056 Item* bodyPtr1 = 0, Item* bodyPtr2 = 0)
00057 : Spring(restLength, stiffness, damping, bodyPtr1, bodyPtr2) {}
00058 };
00059
00060 typedef std::vector<SoftBodyParticle*> SoftBodyParticleList;
00061
00065 class SoftBody: public ItemGroup
00066 {
00067 STEPCORE_OBJECT(SoftBody)
00068
00069 public:
00071 SoftBody(): _showInternalItems(true) { setColor(0xffa9a9a9); }
00072
00082 ItemList createSoftBodyItems(const Vector2d& position, const Vector2d& size, const Vector2i& split,
00083 double bodyMass, double youngModulus, double bodyDamping);
00084
00086 void addItems(const ItemList& items);
00087
00089 Vector2d position() const;
00091 void setPosition(const Vector2d position);
00092
00094 Vector2d velocity() const;
00096 void setVelocity(const Vector2d velocity);
00097
00099 double angularVelocity() const;
00101 void setAngularVelocity(double angularVelocity);
00102
00104 double angularMomentum() const;
00105
00107 void setAngularMomentum(double angularMomentum);
00108
00110 Vector2d acceleration() const { return force()/mass(); }
00111
00113 double angularAcceleration() const { return torque()/inertia(); }
00114
00116 Vector2d force() const;
00118 double torque() const;
00119
00121 double mass() const;
00122
00124 double inertia() const;
00125
00127 bool showInternalItems() const { return _showInternalItems; }
00129 void setShowInternalItems(bool showInternalItems) {
00130 _showInternalItems = showInternalItems; }
00131
00133 const SoftBodyParticleList& borderParticles();
00134
00135 QString borderParticleNames() const;
00136 void setBorderParticleNames(const QString& borderParticleNames);
00137
00138 void worldItemRemoved(Item* item);
00139 void setWorld(World* world);
00140
00141 protected:
00142 SoftBodyParticleList _borderParticles;
00143 QString _borderParticleNames;
00144 bool _showInternalItems;
00145 };
00146
00147 }
00148
00149 #endif
00150