• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

step/stepcore

softbody.h

Go to the documentation of this file.
00001 /* This file is part of StepCore library.
00002    Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
00003 
00004    StepCore library is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2 of the License, or
00007    (at your option) any later version.
00008 
00009    StepCore library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with StepCore; if not, write to the Free Software
00016    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 } // namespace StepCore
00148 
00149 #endif
00150 

step/stepcore

Skip menu "step/stepcore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal