00001 /*************************************************************************** 00002 * Copyright (C) 2005 by David Saxton * 00003 * david@bluehaze.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 ***************************************************************************/ 00010 00011 #ifndef MECHANICSSIMULATION_H 00012 #define MECHANICSSIMULATION_H 00013 00014 #include <qguardedptr.h> 00015 #include <qobject.h> 00016 #include <qvaluelist.h> 00017 00018 class MechanicsItem; 00019 class MechanicsDocument; 00020 typedef QValueList<MechanicsItem*> MechanicsItemList; 00021 00022 00027 class Vector2D 00028 { 00029 public: 00030 Vector2D(); 00031 00032 double length() const; 00033 double lengthSquared() const { return x*x + y*y; } 00034 00035 double x; 00036 double y; 00037 }; 00038 00039 00044 class RigidBodyState 00045 { 00046 public: 00047 RigidBodyState(); 00048 00049 Vector2D linearMomentum; 00050 double angularMomentum; 00051 Vector2D position; // Position of center of mass 00052 }; 00053 00054 00058 class MechanicsSimulation : public QObject 00059 { 00060 Q_OBJECT 00061 public: 00062 MechanicsSimulation( MechanicsDocument *mechanicsDocument ); 00063 ~MechanicsSimulation(); 00064 00065 MechanicsDocument* mechanicsDocument() const { return p_mechanicsDocument; } 00066 00067 protected slots: 00068 void slotAdvance(); 00069 00070 protected: 00071 QGuardedPtr<MechanicsDocument> p_mechanicsDocument; 00072 QTimer *m_advanceTmr; 00073 }; 00074 00075 00083 class RigidBody 00084 { 00085 public: 00086 RigidBody( MechanicsDocument *mechanicsDocument ); 00087 ~RigidBody(); 00088 00092 void advance( int phase, double delta ); 00097 bool addMechanicsItem( MechanicsItem *item ); 00101 MechanicsItem *overallParent() const { return p_overallParent; } 00105 void updateRigidBodyInfo(); 00106 00107 protected: 00112 bool findOverallParent(); 00116 void moveBy( double dx, double dy ); 00122 void rotateBy( double dtheta ); 00123 00124 MechanicsItemList m_mechanicsItemList; 00125 MechanicsItem *p_overallParent; 00126 MechanicsDocument *p_mechanicsDocument; 00127 00128 RigidBodyState m_rigidBodyState; 00129 double m_mass; 00130 double m_momentOfInertia; 00131 }; 00132 00133 #endif
1.5.1