H3D API  2.4.1
DynamicTransform.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __DYNAMICTRANSFORM_H__
30 #define __DYNAMICTRANSFORM_H__
31 
32 #include <H3D/MatrixTransform.h>
33 #include <H3D/PeriodicUpdate.h>
34 #include <H3D/RK4.h>
35 #include <H3D/SFMatrix3f.h>
36 #include <H3D/SFQuaternion.h>
37 
38 namespace H3D {
39 
53  class H3DAPI_API DynamicTransform : public MatrixTransform {
54  public:
55 
60  class H3DAPI_API SFMotion:
61  public TypedField< H3D::SFVec3f, Types< SFTime > > {
62  public:
63 
64  SFMotion(): last_t( 0 ) {
65  }
66 
67  H3DTime last_t;
68  protected:
70  virtual void update();
71 
72  virtual void updateState( LMState &state, H3DTime dt );
73  };
74 
80  class H3DAPI_API SFMatrix4f:
81  public TypedField< H3D::SFMatrix4f,
82  Types< SFRotation, SFVec3f > >{
83  protected:
84 
86  virtual void update();
87  };
88 
94  class H3DAPI_API SFVelocity: public TypedField< SFVec3f,
95  Types< SFFloat,
96  SFVec3f > > {
97  virtual void update() {
98  H3DFloat _mass =
99  static_cast< SFFloat * >( routes_in[0] )->getValue();
100  const Vec3f &_momentum =
101  static_cast< SFVec3f * >( routes_in[1] )->getValue();
102  value = _momentum / _mass;
103  }
104  };
105 
110  class H3DAPI_API SFSpin: public TypedField< SFQuaternion,
111  Types< SFVec3f,
112  SFRotation > > {
113  virtual void update() {
114  const Vec3f & ang_vel =
115  static_cast< SFVec3f * >( routes_in[0] )->getValue();
116  const Rotation &orn =
117  static_cast< SFRotation * >( routes_in[1] )->getValue();
118  value = 0.5 * Quaternion(ang_vel.x, ang_vel.y, ang_vel.z, 0) * (Quaternion)orn;
119  }
120  };
121 
127  class H3DAPI_API SFAngularVelocity: public TypedField< SFVec3f,
128  Types< SFMatrix3f,
129  SFVec3f > > {
130  virtual void update() {
131  const Matrix3f &inertia_tensor =
132  static_cast< SFMatrix3f * >( routes_in[0] )->getValue();
133  const Vec3f &ang_momentum =
134  static_cast< SFVec3f * >( routes_in[1] )->getValue();
135  value = inertia_tensor.inverse() * ang_momentum;
136  }
137  };
138 
140  DynamicTransform( Inst< AddChildren > _addChildren = 0,
141  Inst< RemoveChildren > _removeChildren = 0,
142  Inst< MFChild > _children = 0,
143  Inst< SFNode > _metadata = 0,
144  Inst< SFBound > _bound = 0,
145  Inst< SFVec3f > _bboxCenter = 0,
146  Inst< SFVec3f > _bboxSize = 0,
147  Inst< SFTransformedBound > _transformedBound = 0,
148  Inst< SFMatrix4f > _matrix = 0,
149  Inst< SFMatrix4f > _accumulatedForward = 0,
150  Inst< SFMatrix4f > _accumulatedInverse = 0,
151  Inst< SFVec3f > _position = 0,
152  Inst< SFRotation > _orientation = 0,
153  Inst< SFVelocity > _velocity = 0,
154  Inst< SFVec3f > _momentum = 0,
155  Inst< SFVec3f > _force = 0,
156  Inst< SFAngularVelocity > _angularVelocity = 0,
157  Inst< SFVec3f > _angularMomentum = 0,
158  Inst< SFSpin > _spin = 0,
159  Inst< SFVec3f > _torque = 0,
160  Inst< SFFloat > _mass = 0,
161  Inst< SFMatrix3f > _inertiaTensor = 0,
162  Inst< SFMotion > _motion = 0 );
163 
170  H3DUniquePtr< SFVec3f > position;
171 
178  H3DUniquePtr< SFRotation > orientation;
179 
185  H3DUniquePtr< SFVec3f > velocity;
186 
193  H3DUniquePtr< SFVec3f > momentum;
194 
201  H3DUniquePtr< SFVec3f > force;
202 
208  H3DUniquePtr< SFVec3f > angularVelocity;
209 
216  H3DUniquePtr< SFVec3f > angularMomentum;
217 
223  H3DUniquePtr< SFSpin > spin;
224 
231  H3DUniquePtr< SFVec3f > torque;
232 
239  H3DUniquePtr< SFFloat > mass;
240 
247  H3DUniquePtr< SFMatrix3f > inertiaTensor;
248 
250  H3DUniquePtr< SFMotion > motion;
251 
254  };
255 }
256 
257 #endif
Header file for MatrixTransform, X3D scene-graph node.
Header file for PeriodicUpdate, template field modifier.
Contains fourth-order Runge Kutta integration functions.
Contains the SFMatrix3f field class.
Contains the SFQuaternion field class.
Calculates the angular velocity based on the inertia tensor and angular momentum.
Definition: DynamicTransform.h:129
Specialize the SFMatrix4f to update the matrix from the fields in the Transform node.
Definition: DynamicTransform.h:82
Time dependant field to perform the RK4 integration for determining the motion of the dynamic transfo...
Definition: DynamicTransform.h:61
Calculates the spin (time derivative of the orientation)
Definition: DynamicTransform.h:112
Calculates the velocity based on the mass and momentum.
Definition: DynamicTransform.h:96
The DynamicTransform node is a Shape container that has basic properties for defining rigid body moti...
Definition: DynamicTransform.h:53
H3DUniquePtr< SFVec3f > velocity
Specifies the velocity in m/s.
Definition: DynamicTransform.h:185
H3DUniquePtr< SFFloat > mass
Specifies the mass, in kg.
Definition: DynamicTransform.h:239
H3DUniquePtr< SFVec3f > angularVelocity
Specifies the angular velocity of the dynamic.
Definition: DynamicTransform.h:208
H3DUniquePtr< SFVec3f > force
Specifies the force currently acting on the dynamic.
Definition: DynamicTransform.h:201
H3DUniquePtr< SFMatrix3f > inertiaTensor
Specifies the inertia tensor.
Definition: DynamicTransform.h:247
H3DUniquePtr< SFRotation > orientation
Specifies the orientation of the shape.
Definition: DynamicTransform.h:178
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: DynamicTransform.h:253
H3DUniquePtr< SFVec3f > torque
Specifies the torque force currently acting on the dynamic.
Definition: DynamicTransform.h:231
H3DUniquePtr< SFSpin > spin
Specifies the spin of the dynamic.
Definition: DynamicTransform.h:223
H3DUniquePtr< SFVec3f > angularMomentum
Specifies the angular momentum of the dynamic.
Definition: DynamicTransform.h:216
H3DUniquePtr< SFVec3f > momentum
Specifies the momentum.
Definition: DynamicTransform.h:193
H3DUniquePtr< SFVec3f > position
Specifies the position of the shape.
Definition: DynamicTransform.h:170
H3DUniquePtr< SFMotion > motion
Dynamic update algorithm. Only accessable in C++.
Definition: DynamicTransform.h:250
The MatrixTransform node is a grouping node that defines a coordinate system for its children that is...
Definition: MatrixTransform.h:64
The SFFloat field contains one single-precision floating point number.
Definition: SFFloat.h:41
The SFMatrix3f field contains a Matrix3f.
Definition: SFMatrix3f.h:41
The SFRotation field contains one arbitrary Rotation.
Definition: SFRotation.h:41
The SFVec3f field contains a Vec3f.
Definition: SFVec3f.h:41
A template modifier class for adding type checking on the routes to any Field class.
Definition: TypedField.h:84
Rotation()
float H3DFloat
double H3DTime
Type getValue(const char *s, const char *&rest)
Function that reads characters from a char * and converts them to a given type.
Definition: X3DFieldConversion.h:134
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194