TAPs 0.7.7.3
TAPsSpring.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsSpring.hpp
00003 
00004 Spring class is a class for a spring connecting between two particles in 3D.
00005 
00006 SUKITTI PUNAK   (09/15/2004)
00007 UPDATE          (09/15/2004)
00008 ******************************************************************************/
00009 #ifndef TAPs_SPRING_HPP
00010 #define TAPs_SPRING_HPP
00011 
00012 #include "TAPsParticle.hpp"
00013 
00014 BEGIN_NAMESPACE_TAPs
00015 //=============================================================================
00016 // Forward Class Declarations
00017 template <typename T>   class DeformMesh;
00018 template <typename T>   class Cloth;
00019 //=============================================================================
00020 template <typename T>
00021 class Spring {
00022 //=============================================================================
00023     //-------------------------------------------------------------------------
00024     // Friend Classes
00025     friend class DeformMesh<T>;
00026     friend class Cloth<T>;
00027     //-------------------------------------------------------------------------
00028     // put it through ostream
00029     friend std::ostream &operator<< ( std::ostream &output, Spring<T> const &S )
00030     {
00031         output  << "Spring<" << typeid(T).name() << "> ==> "
00032                 << "\n  -------START--SPRING--INFO-------"
00033                 << "\n  Particle #1: " << S.m_rcP1
00034                 << "\n  Particle #2: " << S.m_rcP2
00035                 << "\n  K Constant:  " << S.m_tK
00036                 << "\n  D Damping:   " << S.m_tD
00037                 << "\n  L Length:    " << S.m_tL
00038                 << "\n  Current Length: " << S.GetCurrentLength()
00039                 << "\n  Force:       " << S.GetForce()
00040                 << "\n  --------END--SPRING--INFO--------\n";
00041         return output;
00042     }
00043 //-----------------------------------------------------------------------------
00044 private:
00045     // Data Members     ========================================================
00046     Particle<T> &   m_rcP1; // reference to connected particle #1
00047     Particle<T> &   m_rcP2; // reference to connected particle #2
00048     T               m_tK;   // tensile spring constant (K)
00049     T               m_tD;   // damping factor (D)
00050     T               m_tL;   // rest length of spring (L)
00051     //-------------------------------------------------------------------------
00052 public:
00053     // Member Functions     ====================================================
00054     Spring ( 
00055         Particle<T> &P1, 
00056         Particle<T> &P2, 
00057         T k, T d, T l );    // constructor
00058     Spring ( 
00059         Particle<T> &P1, 
00060         Particle<T> &P2, 
00061         T k, T d );         // constructor
00062     ~Spring ();             // destructor
00063     //-------------------------------------------------------------------------
00064     // Calculate and Return the (Internal) Force of a Spring
00065     Vector3<T> GetForce () const;
00066     //-------------------------------------------------------------------------
00067     // Get/Set Functions
00068     // REMARK: No const for Particle<T> & and const after the get fns
00069     //         so that the return ref can be modified.
00070     inline Particle<T> & GetParticleOne ();
00071     inline Particle<T> & GetParticleTwo ();
00072     inline T GetConstantK () const;
00073     inline T GetDampingD () const;
00074     inline T GetRestLengthL () const;
00075     inline T GetCurrentLength () const;
00076     //-------------------------------------------------------------------------
00077 private:
00078     // Prohibited Functions ====================================================
00079     // Since a spring refers to two particles, therefore
00080     // Copy Constructor and Assignment Operator are prohibited.
00081     Spring<T> const & operator= ( Spring<T> const &S ); // assignment operator
00082     //-------------------------------------------------------------------------
00083 }; // END CLASS Spring
00084 //=============================================================================
00085 END_NAMESPACE_TAPs
00086 //-----------------------------------------------------------------------------
00087 // Include definition if TAPs_USE_EXPORT is not defined
00088 //#if !defined( TAPs_USE_EXPORT )
00089     #include "TAPsSpring.cpp"
00090 //#endif
00091 //-----------------------------------------------------------------------------
00092 #endif
00093 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00094 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00095 
00096 
00097 
00098 //TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTE
00099 //
00100 //      TAPsSpring    T E S T    P R O G R A M
00101 //
00102 //TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTE
00103 /*
00104 #include <iostream>
00105 #include <iomanip>
00106 using std::cout;
00107 using std::setw;
00108 #include "../Core/Physics/TAPsSpring.hpp"
00109 
00110 int main()
00111 {
00112     TAPs::Particle<float> P1( 1, TAPs::Vector3<float>( 0,0,0 ), TAPs::Vector3<float>( 1,0,0 ), 
00113                              TAPs::Vector3<float>( 0,1,0 ), TAPs::Vector3<float>( 0,0,1 ), true );
00114     TAPs::Particle<float> P2( 1, TAPs::Vector3<float>( 1,1,1 ), TAPs::Vector3<float>( 0.5,0,0 ), 
00115                              TAPs::Vector3<float>( 0,0.5,0 ), TAPs::Vector3<float>( 0,0,0.5 ) );
00116 
00117     TAPs::Spring<float> S( P1, P2, 180, 2, 1.5 );
00118     cout <<   "P1 ==> " << P1;
00119     cout <<   "P2 ==> " << P2;
00120     cout << "\nS  ==> " << S;
00121     cout << "P1- P2 ==> " << P1.GetPosition() - P2.GetPosition() << "\n";
00122     P1.SetPosition( TAPs::Vector3<float>( 2,3,4 ) );
00123     cout << "\nP1.SetPosition( TAPs:Vector3<float>( 2,2,2 ) ) ==> " << P1;
00124     cout << "\nS  ==> " << S;
00125     cout << "P1- P2 ==> " << P1.GetPosition() - P2.GetPosition() << "\n";
00126 
00127     return 0;
00128 }
00129 */
00130 //TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines