My Project
Loading...
Searching...
No Matches
CGELSkeletonLink.h
Go to the documentation of this file.
1//===========================================================================
2/*
3 Software License Agreement (BSD License)
4 Copyright (c) 2003-2024, 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 1.0.0
41*/
42//===========================================================================
43
44//---------------------------------------------------------------------------
45#ifndef CGELSkeletonLinkH
46#define CGELSkeletonLinkH
47//---------------------------------------------------------------------------
48#include "chai3d.h"
49#include "CGELSkeletonNode.h"
50//---------------------------------------------------------------------------
51
52//===========================================================================
60//===========================================================================
61
62//===========================================================================
70//===========================================================================
72{
73 //-----------------------------------------------------------------------
74 // CONSTRUCTOR & DESTRUCTOR:
75 //-----------------------------------------------------------------------
76
77public:
78
81
84
85
86 //-----------------------------------------------------------------------
87 // METHODS:
88 //-----------------------------------------------------------------------
89
90public:
91
92 //-----------------------------------------------------------------------
97 //-----------------------------------------------------------------------
98 inline void render()
99 {
100#ifdef C_USE_OPENGL
101
102 // render link
103 glColor4fv( (const float *)&m_color);
104 glBegin(GL_LINES);
105 glVertex3dv( (const double *)&m_node0->m_pos);
106 glVertex3dv( (const double *)&m_node1->m_pos);
107 glEnd();
108
109#endif
110 }
111
112
113 //-----------------------------------------------------------------------
119 //-----------------------------------------------------------------------
120 inline void computeForces()
121 {
122 // update basic parameters of current link
124 m_wLink10 = cMul(-1, m_wLink01);
126
129
130 //-------------------------------------------------------------
131 // ELONGATION:
132 //-------------------------------------------------------------
133 // if distance too small, no forces are applied
134 if (m_length < 0.000001) { return; }
135
136 // elongation compute force
137 double f = m_kSpringElongation * (m_length - m_length0);
138
139 // apply force
140 if (m_length > 0.000001)
141 {
142 chai3d::cVector3d force = cMul(f/m_length, m_wLink01);
143 m_node0->addForce(force);
144 chai3d::cVector3d tmpfrc = cMul(-1, force);
145 m_node1->addForce(tmpfrc);
146 }
147
148 //-------------------------------------------------------------
149 // FLEXION:
150 //-------------------------------------------------------------
151 // compute flexion forces and torques
152 chai3d::cVector3d torqueDir0 = cCross(m_wzLink01, m_wLink01);
153 chai3d::cVector3d torqueDir1 = cCross(m_wzLink10, m_wLink10);
154 double angle0 = cAngle(m_wzLink01, m_wLink01);
155 double angle1 = cAngle(m_wzLink10, m_wLink10);
156 double torqueMag0 = angle0 * m_kSpringFlexion;
157 double torqueMag1 = angle1 * m_kSpringFlexion;
158
159 if ((m_length > 0.000001) && (m_enabled))
160 {
161 if (torqueMag0 > 0.0001)
162 {
163 chai3d::cVector3d torque0 = cMul(torqueMag0, cNormalize(torqueDir0));
164 m_node0->addTorque(torque0);
165 chai3d::cVector3d force1 = cMul((torqueMag0/m_length), cNormalize(cCross(m_wLink01, torque0)));
166 m_node1->addForce(force1);
167 chai3d::cVector3d tmpfrc = cMul(-1,force1);
168 m_node0->addForce(tmpfrc);
169 }
170
171 if (torqueMag1 > 0.0001)
172 {
173 chai3d::cVector3d torque1 = cMul(torqueMag1, cNormalize(torqueDir1));
174 m_node1->addTorque(torque1);
175 chai3d::cVector3d force0 = cMul((torqueMag1/m_length), cNormalize(cCross(m_wLink10, torque1)));
176 m_node0->addForce(force0);
177 chai3d::cVector3d tmpfrc = cMul(-1,force0);
178 m_node1->addForce(tmpfrc);
179 }
180 }
181
182 //-----------------------------------------------------------------------
183 // TORSION:
184 //-----------------------------------------------------------------------
185
186 if (m_enabled)
187 {
188 // update frame vectors in world coordinates.
192
193 // compute torsional angle and torque
194 chai3d::cVector3d v0, v1;
197 v0.normalize();
198 v1.normalize();
199
200 chai3d::cVector3d torque;
203
204 m_node0->addTorque(torque);
205 chai3d::cVector3d tmptrq = -1.0 * torque;
206 m_node1->addTorque(tmptrq);
207 }
208 }
209
210
211 //-----------------------------------------------------------------------
212 // PUBLIC MEMBERS - MASS NODES:
213 //-----------------------------------------------------------------------
214
215public:
216
219
222
223
224 //-----------------------------------------------------------------------
225 // PUBLIC MEMBERS - GRAPHICAL PROPERTIES:
226 //-----------------------------------------------------------------------
227
228public:
229
232
233
234 //-----------------------------------------------------------------------
235 // PUBLIC MEMBERS - PHYSICAL PROPERTIES:
236 //-----------------------------------------------------------------------
237
238public:
239
242
245
248
251
253 //double m_kDamperElongation;
254
256 //double m_kDamperFlexion;
257
259 //double m_kDamperTorsion;
260
261
262 //-----------------------------------------------------------------------
263 // PUBLIC MEMBERS:
264 //-----------------------------------------------------------------------
265
266public:
267
270
273
276
279
282
285
288
291
294
297
300
303
306
308 double m_length0;
309
311 double m_length;
312
313
314 //-----------------------------------------------------------------------
315 // STATIC MEMBERS - DEFAULT SETTINGS:
316 //-----------------------------------------------------------------------
317
318public:
319
321 static double s_default_kSpringElongation; // [N/m]
322
324 static double s_default_kSpringFlexion; // [Nm/RAD]
325
327 static double s_default_kSpringTorsion; // [Nm/RAD]
328
331};
332
333//---------------------------------------------------------------------------
334#endif
335//---------------------------------------------------------------------------
Implementation of a skeleton mass node.
This class implements a mass node with mass and inertia properties.
Definition CGELSkeletonNode.h:70
void addTorque(chai3d::cVector3d &a_torque)
This method adds a torque to the node.
Definition CGELSkeletonNode.h:100
chai3d::cMatrix3d m_rot
Rotation computed.
Definition CGELSkeletonNode.h:289
chai3d::cVector3d m_pos
Position computed.
Definition CGELSkeletonNode.h:286
void addForce(chai3d::cVector3d &a_force)
This method adds a force to the node.
Definition CGELSkeletonNode.h:94
void mulr(const double &a_scalar, cMatrix3d &a_result) const
void mulr(const double &a_scalar, cVector3d &a_result) const
void crossr(const cVector3d &a_vector, cVector3d &a_result) const
double length() const