Documentation


massSpringEngine.h

Go to the documentation of this file.
00001 #ifndef MASS_SPRING_ENGINE_H
00002 #define MASS_SPRING_ENGINE_H
00003 
00004 #include "engine.h"
00005 #include <animal/massspringsolver.h>
00006 
00007 namespace animal {
00008 
00016 template< typename Inv_Masses,
00017          typename Velocities,
00018          typename SpringStiffness,
00019          typename IndexedSprings,
00020          typename Points,
00021          typename Real = float >
00022 class MassSpringEngine :
00023   public Engine,
00024   public MassSpringSolver<Points,Velocities,Inv_Masses,SpringStiffness,IndexedSprings>
00025 {  
00026   public:
00028    MassSpringEngine();
00029 
00031    virtual ~MassSpringEngine();
00032   
00033    //===============================================================
00036    
00038    virtual void reset();
00039   
00041    virtual void move(double dt);
00042    
00044    void draw();
00045    
00047    virtual void getBoundingBox(float &minX, float &minY, float &minZ, float &maxX, float &maxY, float &maxZ);
00048    
00050    void mousePressEvent( MouseEvent* );
00051 
00053    bool get_compressed_ok();
00054    
00056    void set_compressed_ok(bool ok);
00057    
00059    bool get_elongated_ok();
00060    
00062    void set_elongated_ok(bool ok);
00063    
00065    bool get_displayMassSpring();
00066    
00068    void set_displayMassSpring(bool display);
00069    
00071    void set_pointSize( int );
00073    int get_pointSize(  ) const;
00075    void set_lineWidth( int );
00077    int get_lineWidth(  ) const;
00078     
00079    // ----------  FF: picking -----------------------------
00082     class ConstrainedPoint: public ConstrainedItem
00083     {
00084     public:
00086         ConstrainedPoint( MassSpringEngine* mse, int index );
00087 
00089         virtual void getPoint( float& x, float& y, float& z ) const;
00090         
00092         virtual void moveTo( float x, float y, float z ) const;
00093         
00095         virtual ~ConstrainedPoint();
00096         
00098         virtual void print() const;
00099 
00101         virtual bool operator == ( const ConstrainedItem* ) const;
00102 
00103     protected:
00104         MassSpringEngine* _mse;
00105         int _index;
00106         float invmass;
00107 
00108     };
00109     friend class ConstrainedPoint;
00110 
00112    virtual ConstrainedItem* pickPoint( float origin[3], float direction[3], float threshold );
00113    // ----------  end FF: picking -----------------------------
00114     
00116     //===============================================================
00117 
00118 //  protected:
00119 
00120     typedef MassSpringSolver<Points,Velocities,Inv_Masses,SpringStiffness,IndexedSprings> _MassSpringSolver; 
00121   typedef typename _MassSpringSolver::Index Index;
00122 
00123 //  protected: // Members
00124     Velocities * _velocities;
00125     Points * _points;
00126     Points _initialPoints;    
00127     Points _initialVelocities; 
00128     int _pointSize;             
00129     int _lineWidth;             
00130     
00131 //  private:
00132     vector<float> elongation;    
00133    struct rgb
00134    {
00135      float r;
00136     float g;
00137     float b; 
00138   };
00139   vector<rgb> colours;    
00140     
00141   bool compressed_ok;    
00142   bool elongated_ok;    
00143   bool displayMassSpring;  
00144   
00145 }; // class MassSpringEngine
00146 
00147 template<class Container>
00148 void resize(Container &C, int size)
00149 {
00150   C.resize(size);
00151 }
00152 
00153 }      // namespace animal
00154 
00155 #endif //MASS_SPRING_ENGINE_H

Generated on Thu Dec 23 13:52:25 2004 by doxygen 1.3.6