00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00027
00029 #ifndef __DYNAMICTRANSFORM_H__
00030 #define __DYNAMICTRANSFORM_H__
00031
00032 #include "MatrixTransform.h"
00033 #include "PeriodicUpdate.h"
00034 #include "RK4.h"
00035 #include "SFMatrix3f.h"
00036 #include "SFQuaternion.h"
00037
00038 namespace H3D {
00039
00046 class H3DAPI_API DynamicTransform : public MatrixTransform {
00047 public:
00048
00053 class H3DAPI_API SFMotion:
00054 public TypedField< H3D::SFVec3f, Types< SFTime > > {
00055 public:
00056
00057 SFMotion(): last_t( 0 ) {
00058 }
00059
00060 H3DTime last_t;
00061 protected:
00063 virtual void update();
00064
00065 virtual void updateState( LMState &state, H3DTime dt );
00066 };
00067
00073 class H3DAPI_API SFMatrix4f:
00074 public TypedField< H3D::SFMatrix4f,
00075 Types< SFRotation, SFVec3f > >{
00076 protected:
00077
00079 virtual void update();
00080 };
00081
00087 class H3DAPI_API SFVelocity: public TypedField< SFVec3f,
00088 Types< SFFloat,
00089 SFVec3f > > {
00090 virtual void update() {
00091 H3DFloat mass =
00092 static_cast< SFFloat * >( routes_in[0] )->getValue();
00093 const Vec3f &momentum =
00094 static_cast< SFVec3f * >( routes_in[1] )->getValue();
00095 value = momentum / mass;
00096 }
00097 };
00098
00103 class H3DAPI_API SFSpin: public TypedField< SFQuaternion,
00104 Types< SFVec3f,
00105 SFRotation > > {
00106 virtual void update() {
00107 const Vec3f & ang_vel =
00108 static_cast< SFVec3f * >( routes_in[0] )->getValue();
00109 const Rotation &orn =
00110 static_cast< SFRotation * >( routes_in[1] )->getValue();
00111 value = 0.5 * Quaternion(ang_vel.x, ang_vel.y, ang_vel.z, 0) * (Quaternion)orn;
00112 }
00113 };
00114
00120 class H3DAPI_API SFAngularVelocity: public TypedField< SFVec3f,
00121 Types< SFMatrix3f,
00122 SFVec3f > > {
00123 virtual void update() {
00124 const Matrix3f &inertia_tensor =
00125 static_cast< SFMatrix3f * >( routes_in[0] )->getValue();
00126 const Vec3f &ang_momentum =
00127 static_cast< SFVec3f * >( routes_in[1] )->getValue();
00128 value = inertia_tensor.inverse() * ang_momentum;
00129 }
00130 };
00131
00133 DynamicTransform( Inst< MFChild > _addChildren = 0,
00134 Inst< MFChild > _removeChildren = 0,
00135 Inst< MFChild > _children = 0,
00136 Inst< SFNode > _metadata = 0,
00137 Inst< SFBound > _bound = 0,
00138 Inst< SFVec3f > _bboxCenter = 0,
00139 Inst< SFVec3f > _bboxSize = 0,
00140 Inst< SFTransformedBound > _transformedBound = 0,
00141 Inst< SFMatrix4f > _matrix = 0,
00142 Inst< SFMatrix4f > _accumulatedForward = 0,
00143 Inst< SFMatrix4f > _accumulatedInverse = 0,
00144 Inst< SFVec3f > _position = 0,
00145 Inst< SFRotation > _orientation = 0,
00146 Inst< SFVelocity > _velocity = 0,
00147 Inst< SFVec3f > _momentum = 0,
00148 Inst< SFVec3f > _force = 0,
00149 Inst< SFAngularVelocity > _angularVelocity = 0,
00150 Inst< SFVec3f > _angularMomentum = 0,
00151 Inst< SFSpin > _spin = 0,
00152 Inst< SFVec3f > _torque = 0,
00153 Inst< SFFloat > _mass = 0,
00154 Inst< SFMatrix3f > _inertiaTensor = 0,
00155 Inst< SFMotion > _motion = 0 );
00156
00161 auto_ptr< SFVec3f > position;
00162
00167 auto_ptr< SFRotation > orientation;
00168
00172 auto_ptr< SFVec3f > velocity;
00173
00178 auto_ptr< SFVec3f > momentum;
00179
00184 auto_ptr< SFVec3f > force;
00185
00189 auto_ptr< SFVec3f > angularVelocity;
00190
00195 auto_ptr< SFVec3f > angularMomentum;
00196
00200 auto_ptr< SFSpin > spin;
00201
00206 auto_ptr< SFVec3f > torque;
00207
00212 auto_ptr< SFFloat > mass;
00213
00218 auto_ptr< SFMatrix3f > inertiaTensor;
00219
00221 auto_ptr< SFMotion > motion;
00222
00224 static H3DNodeDatabase database;
00225 };
00226 }
00227
00228 #endif