00001 //=========================================================================== 00002 /* 00003 This file is part of the GEL dynamics engine. 00004 Copyright (C) 2003-2009 by Francois Conti, Stanford University. 00005 All rights reserved. 00006 00007 \author <http://www.chai3d.org> 00008 \author Francois Conti 00009 \version 2.0.0 $Rev: 251 $ 00010 */ 00011 //=========================================================================== 00012 00013 //--------------------------------------------------------------------------- 00014 #ifndef CGELLinearSpringH 00015 #define CGELLinearSpringH 00016 //--------------------------------------------------------------------------- 00017 #include "chai3d.h" 00018 #include "CGELMassParticle.h" 00019 //--------------------------------------------------------------------------- 00020 00021 //=========================================================================== 00029 //=========================================================================== 00030 00031 //=========================================================================== 00039 //=========================================================================== 00040 class cGELLinearSpring 00041 { 00042 public: 00043 00044 //----------------------------------------------------------------------- 00045 // CONSTRUCTOR & DESTRUCTOR: 00046 //----------------------------------------------------------------------- 00047 00049 cGELLinearSpring(cGELMassParticle* a_node0, cGELMassParticle* a_node1); 00050 00052 ~cGELLinearSpring(); 00053 00054 00055 //----------------------------------------------------------------------- 00056 // METHODS: 00057 //----------------------------------------------------------------------- 00058 00059 //----------------------------------------------------------------------- 00063 //----------------------------------------------------------------------- 00064 inline void render() 00065 { 00066 // render link 00067 glColor4fv( (const float *)&m_color); 00068 glBegin(GL_LINES); 00069 glVertex3dv( (const double *)&m_node0->m_pos); 00070 glVertex3dv( (const double *)&m_node1->m_pos); 00071 glEnd(); 00072 } 00073 00074 00075 //----------------------------------------------------------------------- 00079 //----------------------------------------------------------------------- 00080 inline void computeForces() 00081 { 00082 // update basic parameters of current link 00083 cVector3d m_link01 = cSub(m_node1->m_pos, m_node0->m_pos); 00084 double m_length = m_link01.length(); 00085 00086 //------------------------------------------------------------- 00087 // ELONGATION: 00088 //------------------------------------------------------------- 00089 // if distance too small, no forces are applied 00090 if (m_length < 0.000001) { return; } 00091 00092 // elongation compute force 00093 double f = m_kSpringElongation * (m_length - m_length0); 00094 00095 // apply force 00096 if (m_length > 0.000001) 00097 { 00098 cVector3d force = cMul(f/m_length, m_link01); 00099 m_node0->addForce(force); 00100 cVector3d tmpfrc = cMul(-1, force); 00101 m_node1->addForce(tmpfrc); 00102 } 00103 } 00104 00105 00106 //----------------------------------------------------------------------- 00107 // MEMBERS - GRAPHICAL PROPERTIES: 00108 //----------------------------------------------------------------------- 00109 00111 cColorf m_color; 00112 00113 00114 //----------------------------------------------------------------------- 00115 // MEMBERS - MASS NODES: 00116 //----------------------------------------------------------------------- 00117 00119 cGELMassParticle *m_node0; 00120 00122 cGELMassParticle *m_node1; 00123 00124 00125 //----------------------------------------------------------------------- 00126 // MEMBERS - PHYSICAL PROPERTIES: 00127 //----------------------------------------------------------------------- 00128 00130 double m_kSpringElongation; 00131 00133 bool m_enabled; 00134 00136 double m_kDamperElongation; 00137 00139 double m_length0; 00140 00141 00142 public: 00143 00144 //----------------------------------------------------------------------- 00145 // MEMBERS - DEFAULT SETTINGS: 00146 //----------------------------------------------------------------------- 00147 00149 static double default_kSpringElongation; // [N/m] 00150 00152 static cColorf default_color; 00153 }; 00154 00155 //--------------------------------------------------------------------------- 00156 #endif 00157 //--------------------------------------------------------------------------- 00158