My Project
Loading...
Searching...
No Matches
CGELSkeletonNode.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 CGELSkeletonNodeH
46#define CGELSkeletonNodeH
47//---------------------------------------------------------------------------
48#include "chai3d.h"
49//---------------------------------------------------------------------------
50
51//===========================================================================
58//===========================================================================
59
60//===========================================================================
68//===========================================================================
70{
71 //-----------------------------------------------------------------------
72 // CONSTRUCTOR & DESTRUCTOR:
73 //-----------------------------------------------------------------------
74
75public:
76
79
82
83
84 //-----------------------------------------------------------------------
85 // PUBLIC METHODS:
86 //-----------------------------------------------------------------------
87
88public:
89
91 void setMass(double a_mass);
92
94 inline void addForce(chai3d::cVector3d &a_force)
95 {
96 m_force.add(a_force);
97 }
98
100 inline void addTorque(chai3d::cVector3d &a_torque)
101 {
102 m_torque.add(a_torque);
103 }
104
107 {
108 m_externalForce = a_force;
109 }
110
113 {
114 m_externalTorque = a_torque;
115 }
116
118 inline void computeNextPose(double a_timeInterval)
119 {
120 if (!m_fixed)
121 {
122 // Euler double integration for position
123 chai3d::cVector3d damping;
124 m_vel.mulr(-m_kDampingPos * m_mass, damping);
125 m_force.add(damping);
126 m_acc = cDiv(m_mass, cAdd(m_force, m_externalForce));
127 m_vel = cAdd(m_vel, cMul(a_timeInterval, m_acc));
128 m_nextPos = cAdd(m_pos, cMul(a_timeInterval, m_vel));
129 }
130 else
131 {
133 }
134
135 // Euler double integration for rotation
136 chai3d::cVector3d dampingAng;
137 m_angVel.mulr(-m_kDampingRot * m_mass, dampingAng);
138 m_torque.add(dampingAng);
139 m_angAcc = cMul((1/m_inertia), m_torque);
140 m_angVel = cAdd(m_angVel, cMul(a_timeInterval, m_angAcc));
141
142 double normAngVel = m_angVel.length();
143 if (normAngVel < 0.000001)
144 {
146 }
147 else
148 {
150 m_nextRot.rotateAboutGlobalAxisRad(m_angVel, a_timeInterval * normAngVel);
151 }
152 }
153
155 inline void applyNextPose()
156 {
159 }
160
162 inline void clearForces()
163 {
164 if (m_useGravity)
165 {
168 }
169 else
170 {
171 m_force.zero();
172 }
173 m_torque.zero();
174 }
175
178 {
179 m_externalForce.zero();
180 m_externalTorque.zero();
181 }
182
184 inline void render()
185 {
186#ifdef C_USE_OPENGL
187
188 // set pose
190 mat.set(m_pos, m_rot);
191 glPushMatrix();
192 glMultMatrixd( (const double *)mat.getData() );
193
194 // draw node
195 m_color.render();
197
198 // draw frame
199 if (s_default_showFrame == true)
200 {
201 double frameScale = 3.0 * m_radius;
202 chai3d::cDrawFrame(frameScale);
203 }
204
205 // pop OpenGL matrix
206 glPopMatrix();
207
208 // render external forces
209 glColor4fv( (const float *)&m_color);
210 chai3d::cVector3d v = cAdd(m_pos, cMul(1.0/50.0, m_externalForce));
211 glBegin(GL_LINES);
212 glVertex3dv( (const double *)&m_pos);
213 glVertex3dv( (const double *)&v);
214 glEnd();
215
216#endif
217 }
218
219
220 //-----------------------------------------------------------------------
221 // PUBLIC MEMBERS - GRAPHICAL PROPERTIES:
222 //-----------------------------------------------------------------------
223
224public:
225
228
229
230 //-----------------------------------------------------------------------
231 // PUBLIC MEMBERS - PHYSICAL PROPERTIES:
232 //-----------------------------------------------------------------------
233
234public:
235
237 double m_radius;
238
240 double m_mass;
241
244
247
250
253
256
259
262
265
267 double m_inertia;
268
271
274
277
278
279 //-----------------------------------------------------------------------
280 // PUBLIC MEMBERS - POSITION & ORIENTATION:
281 //-----------------------------------------------------------------------
282
283public:
284
287
290
293
296
297
298 //-----------------------------------------------------------------------
299 // PRIVATE MEMBERS - EXTERNAL FORCES:
300 //-----------------------------------------------------------------------
301
302private:
303
305 chai3d::cVector3d m_externalForce;
306
308 chai3d::cVector3d m_externalTorque;
309
310
311 //-----------------------------------------------------------------------
312 // STATIC MEMBERS - DEFAULT SETTINGS:
313 //-----------------------------------------------------------------------
314
315public:
316
318 static double s_default_radius;
319
322
325
327 static double s_default_mass;
328
331
334
337
340};
341
342//---------------------------------------------------------------------------
343#endif
344//---------------------------------------------------------------------------
345
346
This class implements a mass node with mass and inertia properties.
Definition CGELSkeletonNode.h:70
static double s_default_kDampingRot
Default value for revolute damping.
Definition CGELSkeletonNode.h:324
void clearExternalForces()
This method clears the external forces and torques.
Definition CGELSkeletonNode.h:177
void addTorque(chai3d::cVector3d &a_torque)
This method adds a torque to the node.
Definition CGELSkeletonNode.h:100
bool m_useGravity
If true, then gravity is enabled.
Definition CGELSkeletonNode.h:273
chai3d::cMatrix3d m_nextRot
Next rotation computed.
Definition CGELSkeletonNode.h:295
static bool s_default_showFrame
Default value - Is the node reference frame displayed?
Definition CGELSkeletonNode.h:336
double m_kDampingPos
Linear damping.
Definition CGELSkeletonNode.h:261
chai3d::cColorf m_color
Color used to display nodes.
Definition CGELSkeletonNode.h:227
chai3d::cVector3d m_nextPos
Next position computed.
Definition CGELSkeletonNode.h:292
static bool s_default_useGravity
Default value - Is gravity field enabled?
Definition CGELSkeletonNode.h:330
bool m_fixed
If true, then mass is fixed in space and can not move.
Definition CGELSkeletonNode.h:270
chai3d::cMatrix3d m_rot
Rotation computed.
Definition CGELSkeletonNode.h:289
double m_mass
Mass property.
Definition CGELSkeletonNode.h:240
chai3d::cVector3d m_angAcc
Instant angular acceleration at node.
Definition CGELSkeletonNode.h:252
~cGELSkeletonNode()
Destructor of cGELSkeletonNode.
Definition CGELSkeletonNode.cpp:101
void applyNextPose()
This method updates the position and orientation of this node with the latest computed values.
Definition CGELSkeletonNode.h:155
void setExternalForce(chai3d::cVector3d &a_force)
This method sets an external force to the node.
Definition CGELSkeletonNode.h:106
chai3d::cVector3d m_pos
Position computed.
Definition CGELSkeletonNode.h:286
cGELSkeletonNode()
Constructor of cGELSkeletonNode.
Definition CGELSkeletonNode.cpp:74
double m_kDampingRot
Angular damping.
Definition CGELSkeletonNode.h:264
static double s_default_mass
Default value for node mass.
Definition CGELSkeletonNode.h:327
static chai3d::cVector3d s_default_gravity
Default value - Gravity field magnitude and direction.
Definition CGELSkeletonNode.h:333
void setMass(double a_mass)
This method sets the mass of the node.
Definition CGELSkeletonNode.cpp:114
chai3d::cVector3d m_gravity
Gravity field.
Definition CGELSkeletonNode.h:276
chai3d::cVector3d m_angVel
Instant angular velocity at node.
Definition CGELSkeletonNode.h:258
double m_radius
Radius of mass node.
Definition CGELSkeletonNode.h:237
void computeNextPose(double a_timeInterval)
This method update the position of the node over a time interval.
Definition CGELSkeletonNode.h:118
static chai3d::cColorf s_default_color
Default color used to render the node.
Definition CGELSkeletonNode.h:339
static double s_default_radius
Default value for node radius.
Definition CGELSkeletonNode.h:318
void addForce(chai3d::cVector3d &a_force)
This method adds a force to the node.
Definition CGELSkeletonNode.h:94
chai3d::cVector3d m_vel
Instant velocity at node.
Definition CGELSkeletonNode.h:255
double m_inertia
Inertia (to be completed).
Definition CGELSkeletonNode.h:267
void setExternalTorque(chai3d::cVector3d &a_torque)
This method sets an external torque to the node.
Definition CGELSkeletonNode.h:112
void clearForces()
This method clears the current forces and torques.
Definition CGELSkeletonNode.h:162
void render()
This method renders this node in OpenGL.
Definition CGELSkeletonNode.h:184
chai3d::cVector3d m_torque
Current torque applies on node.
Definition CGELSkeletonNode.h:246
chai3d::cVector3d m_acc
Instant acceleration at node.
Definition CGELSkeletonNode.h:249
static double s_default_kDampingPos
Default value for linear damping.
Definition CGELSkeletonNode.h:321
chai3d::cVector3d m_force
Current force applied on node.
Definition CGELSkeletonNode.h:243
void cDrawFrame(const double &a_scale=1.0)
void cDrawSphere(const double &a_radius, const unsigned int a_numSlices=10, const unsigned int a_numStacks=10)
void render() const
bool rotateAboutGlobalAxisRad(const cVector3d &a_axis, const double &a_angleRad)
void set(const cVector3d &a_pos, const cMatrix3d &a_rot)
double * getData()
void mulr(const double &a_scalar, cVector3d &a_result) const
void add(const cVector3d &a_vector)
double length() const
void mul(const double &a_scalar)