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

step/stepcore

spring.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_SPRING_H
00024 #define STEPCORE_SPRING_H
00025 
00026 #include "world.h"
00027 #include "object.h"
00028 #include "particle.h"
00029 #include "rigidbody.h"
00030 #include "vector.h"
00031 
00032 #include <QString>
00033 #include <cmath>
00034 
00035 namespace StepCore
00036 {
00037 
00038 class Spring;
00039 
00043 class SpringErrors: public ObjectErrors
00044 {
00045     STEPCORE_OBJECT(SpringErrors)
00046 
00047 public:
00049     SpringErrors(Item* owner = NULL)
00050         : ObjectErrors(owner), _restLengthVariance(0), _stiffnessVariance(0),
00051           _dampingVariance(0), _localPosition1Variance(0), _localPosition2Variance(0) {}
00052 
00054     Spring* spring() const;
00055 
00057     double restLengthVariance() const { return _restLengthVariance; }
00059     void   setRestLengthVariance(double restLengthVariance) {
00060         _restLengthVariance = restLengthVariance; }
00061 
00063     double lengthVariance() const;
00064 
00066     double stiffnessVariance() const { return _stiffnessVariance; }
00068     void   setStiffnessVariance(double stiffnessVariance) {
00069         _stiffnessVariance = stiffnessVariance; }
00070 
00072     double dampingVariance() const { return _dampingVariance; }
00074     void   setDampingVariance(double dampingVariance) {
00075         _dampingVariance = dampingVariance; }
00076 
00078     Vector2d localPosition1Variance() const { return _localPosition1Variance; }
00080     void setLocalPosition1Variance(const Vector2d& localPosition1Variance) {
00081         _localPosition1Variance = localPosition1Variance; }
00082 
00084     Vector2d localPosition2Variance() const { return _localPosition2Variance; }
00086     void setLocalPosition2Variance(const Vector2d& localPosition2Variance) {
00087         _localPosition2Variance = localPosition2Variance; }
00088 
00090     Vector2d position1Variance() const;
00092     Vector2d position2Variance() const;
00093 
00095     Vector2d velocity1Variance() const;
00097     Vector2d velocity2Variance() const;
00098 
00100     double forceVariance() const;
00101 
00102 protected:
00103     double _restLengthVariance;
00104     double _stiffnessVariance;
00105     double _dampingVariance;
00106 
00107     StepCore::Vector2d _localPosition1Variance;
00108     StepCore::Vector2d _localPosition2Variance;
00109 
00110     friend class Spring;
00111 };
00112 
00113 
00129 class Spring: public Item, public Force
00130 {
00131     STEPCORE_OBJECT(Spring)
00132 
00133 public:
00135     explicit Spring(double restLength = 0, double stiffness = 1, double damping = 0,
00136                 Item* body1 = 0, Item* body2 = 0);
00137 
00138     void calcForce(bool calcVariances);
00139 
00141     double restLength() const { return _restLength; }
00143     void   setRestLength(double restLength) { _restLength = restLength; }
00144 
00146     double length() const { return (position2()-position1()).norm(); }
00147 
00149     double stiffness() const { return _stiffness; }
00151     void   setStiffness(double stiffness) { _stiffness = stiffness; }
00152 
00154     double damping() const { return _damping; }
00156     void setDamping(double damping) { _damping = damping; }
00157 
00159     Object* body1() const { return _body1; }
00161     void setBody1(Object* body1);
00162 
00164     Object* body2() const { return _body2; }
00166     void setBody2(Object* body2);
00167 
00170     Vector2d localPosition1() const { return _localPosition1; }
00173     void setLocalPosition1(const Vector2d& localPosition1) { _localPosition1 = localPosition1; }
00174 
00177     Vector2d localPosition2() const { return _localPosition2; }
00180     void setLocalPosition2(const Vector2d& localPosition2) { _localPosition2 = localPosition2; }
00181 
00183     Vector2d position1() const;
00185     //void setPosition1(const Vector2d& position1) { if(!_body1) _position1 = position1; }
00186 
00188     Vector2d position2() const;
00190     //void setPosition2(const Vector2d& position2) { if(!_body2) _position2 = position2; }
00191     
00193     Vector2d velocity1() const;
00194 
00196     Vector2d velocity2() const;
00197 
00199     double force() const;
00200 
00202     Particle* particle1() const { return _p1; }
00204     Particle* particle2() const { return _p2; }
00206     RigidBody* rigidBody1() const { return _r1; }
00208     RigidBody* rigidBody2() const { return _r2; }
00209 
00210     //void worldItemRemoved(Item* item);
00211     //void setWorld(World* world);
00212 
00214     SpringErrors* springErrors() { return static_cast<SpringErrors*>(objectErrors()); }
00215 
00216 protected:
00217     ObjectErrors* createObjectErrors() { return new SpringErrors(this); }
00218 
00219     Object* _body1;
00220     Object* _body2;
00221     double _restLength;
00222     double _stiffness;
00223     double _damping;
00224     Vector2d _localPosition1;
00225     Vector2d _localPosition2;
00226 
00227     Particle*  _p1;
00228     Particle*  _p2;
00229     RigidBody* _r1;
00230     RigidBody* _r2;
00231 
00232     friend class SpringErrors;
00233 };
00234 
00235 } // namespace StepCore
00236 
00237 #endif
00238 

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