CGELLinearSpring.h
Go to the documentation of this file.
1 //===========================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \version 3.2.0 $Rev: 1869 $
41 */
42 //===========================================================================
43 
44 //---------------------------------------------------------------------------
45 #ifndef CGELLinearSpringH
46 #define CGELLinearSpringH
47 //---------------------------------------------------------------------------
48 #include "CGELMassParticle.h"
49 //---------------------------------------------------------------------------
50 #include "chai3d.h"
51 //---------------------------------------------------------------------------
52 
53 //===========================================================================
60 //===========================================================================
61 
62 //===========================================================================
70 //===========================================================================
72 {
73  //-----------------------------------------------------------------------
74  // CONSTRUCTOR & DESTRUCTOR:
75  //-----------------------------------------------------------------------
76 
77 public:
78 
81 
84 
85 
86  //-----------------------------------------------------------------------
87  // PUBLIC METHODS:
88  //-----------------------------------------------------------------------
89 
90 public:
91 
92  //-----------------------------------------------------------------------
97  //-----------------------------------------------------------------------
98  inline void render()
99  {
100  // render link
101  glColor4fv( (const float *)&m_color);
102  glBegin(GL_LINES);
103  glVertex3dv( (const double *)&m_node0->m_pos);
104  glVertex3dv( (const double *)&m_node1->m_pos);
105  glEnd();
106  }
107 
108 
109  //-----------------------------------------------------------------------
114  //-----------------------------------------------------------------------
115  inline void computeForces()
116  {
117  // update basic parameters of current link
119  double m_length = m_link01.length();
120 
121  //-------------------------------------------------------------
122  // ELONGATION:
123  //-------------------------------------------------------------
124  // if distance too small, no forces are applied
125  if (m_length < 0.000001) { return; }
126 
127  // elongation compute force
128  double f = m_kSpringElongation * (m_length - m_length0);
129 
130  // apply force
131  if (m_length > 0.000001)
132  {
133  chai3d::cVector3d force = cMul(f/m_length, m_link01);
134  m_node0->addForce(force);
135  chai3d::cVector3d tmpfrc = cMul(-1, force);
136  m_node1->addForce(tmpfrc);
137  }
138  }
139 
140 
141  //-----------------------------------------------------------------------
142  // PUBLIC MEMBERS - GRAPHICAL PROPERTIES:
143  //-----------------------------------------------------------------------
144 
145 public:
146 
149 
150 
151  //-----------------------------------------------------------------------
152  // PUBLIC MEMBERS - MASS NODES:
153  //-----------------------------------------------------------------------
154 
155 public:
156 
159 
162 
163 
164  //-----------------------------------------------------------------------
165  // PUBLIC MEMBERS - PHYSICAL PROPERTIES:
166  //-----------------------------------------------------------------------
167 
168 public:
169 
172 
174  bool m_enabled;
175 
178 
180  double m_length0;
181 
182 
183  //-----------------------------------------------------------------------
184  // STATIC MEMBERS - DEFAULT SETTINGS:
185  //-----------------------------------------------------------------------
186 
187 public:
188 
190  static double s_default_kSpringElongation; // [N/m]
191 
194 };
195 
196 //---------------------------------------------------------------------------
197 #endif
198 //---------------------------------------------------------------------------
199 
double m_kDamperElongation
Linear damping.
Definition: CGELLinearSpring.h:177
static chai3d::cColorf s_default_color
Default property - color property.
Definition: CGELLinearSpring.h:193
void addForce(chai3d::cVector3d &a_force)
This method adds a force to this mass particle.
Definition: CGELMassParticle.h:94
Implementation of a mass particle.
cGELLinearSpring(cGELMassParticle *a_node0, cGELMassParticle *a_node1)
Constructor of cGELLinearSpring.
Definition: CGELLinearSpring.cpp:71
bool m_enabled
Is link enabled?
Definition: CGELLinearSpring.h:174
~cGELLinearSpring()
Destructor of cGELLinearSpring.
Definition: CGELLinearSpring.cpp:94
This class implements a linear spring between two mass particles.
Definition: CGELLinearSpring.h:71
chai3d::cVector3d m_pos
Position of particle.
Definition: CGELMassParticle.h:216
double length() const
cVector3d cSub(const cVector3d &a_vector1, const cVector3d &a_vector2)
cVector3d cMul(const double &a_value, const cVector3d &a_vector)
chai3d::cColorf m_color
Color property used for displaying link.
Definition: CGELLinearSpring.h:148
double m_length0
Initial length of link.
Definition: CGELLinearSpring.h:180
void render()
This method graphically renders this spring using OpenGL.
Definition: CGELLinearSpring.h:98
cGELMassParticle * m_node1
Node 1 of current link.
Definition: CGELLinearSpring.h:161
This class implements a simple mass particle point.
Definition: CGELMassParticle.h:69
cGELMassParticle * m_node0
Node 0 of current link.
Definition: CGELLinearSpring.h:158
double m_kSpringElongation
Linear spring constant.
Definition: CGELLinearSpring.h:171
void computeForces()
This method computes the forces that are applied on the mass nodes.
Definition: CGELLinearSpring.h:115
static double s_default_kSpringElongation
Default property - linear stiffness.
Definition: CGELLinearSpring.h:190