00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00025
00026
00027 #ifndef CollidableDynamic_H
00028 #define CollidableDynamic_H
00029
00030
00031 #include "H3DNetworkingUtils/Config.h"
00032 #include "H3DNetworkingUtils/Dynamic.h"
00033 #include "H3DNetworkingUtils/CollisionSphereHierarchy.h"
00034 #include <H3DUtil/Matrix4f.h>
00035 #include <stack>
00036 #include <H3D/SFInt32.h>
00037 #include <H3D/X3DShapeNode.h>
00038 #include <H3D/X3DComposedGeometryNode.h>
00039 #include "H3DNetworkingUtils/CollisionSphere.h"
00040
00041 namespace H3DNetworkingUtils {
00042
00073 class H3D_NETWORKING_UTILS_DLL_SPEC CollidableDynamic : public Dynamic {
00074
00075 public:
00076
00077 class H3D_NETWORKING_UTILS_DLL_SPEC MFCollidableGeometry : public H3D::TypedMFNode< CollisionGeometry > {
00078 public:
00079 virtual void onAdd( Node *n);
00080 virtual void onRemove( Node *n);
00081 };
00082
00084 CollidableDynamic(
00085 H3D::Inst< AddChildren > _addChildren = 0,
00086 H3D::Inst< RemoveChildren > _removeChildren = 0,
00087 H3D::Inst< MFChild > _children = 0,
00088 H3D::Inst< H3D::SFNode > _metadata = 0,
00089 H3D::Inst< SFBound > _bound = 0,
00090 H3D::Inst< H3D::SFVec3f > _bboxCenter = 0,
00091 H3D::Inst< H3D::SFVec3f > _bboxSize = 0,
00092 H3D::Inst< SFTransformedBound > _transformedBound = 0,
00093 H3D::Inst< SFMatrix4f > _matrix = 0,
00094 H3D::Inst< SFMatrix4f > _accumulatedForward = 0,
00095 H3D::Inst< SFMatrix4f > _accumulatedInverse = 0,
00096 H3D::Inst< H3D::SFVec3f > _position = 0,
00097 H3D::Inst< H3D::SFRotation > _orientation = 0,
00098 H3D::Inst< SFVelocity > _velocity = 0,
00099 H3D::Inst< H3D::SFVec3f > _momentum = 0,
00100
00101 H3D::Inst< H3D::SFVec3f > _force = 0,
00102 H3D::Inst< SFAngularVelocity > _angularVelocity = 0,
00103 H3D::Inst< H3D::SFVec3f > _angularMomentum = 0,
00104 H3D::Inst< SFSpin > _spin = 0,
00105 H3D::Inst< H3D::SFVec3f > _torque = 0,
00106 H3D::Inst< H3D::SFFloat > _mass = 0,
00107 H3D::Inst< H3D::SFMatrix3f > _inertiaTensor = 0,
00108 H3D::Inst< SFMotion > _motion = 0,
00109
00110 H3D::Inst<H3D::MFVec3f > _contactForces = 0,
00111 H3D::Inst<H3D::MFVec3f > _contactTorques = 0,
00112 H3D::Inst<SumMFVec3f > _totalContactForce = 0,
00113 H3D::Inst<CalcTorque > _totalContactTorque = 0,
00114 H3D::Inst<SumForces > _externalForces = 0,
00115 H3D::Inst<SumTorques > _externalTorques = 0,
00116 H3D::Inst<H3D::SFVec3f > _freedom = 0,
00117 H3D::Inst<H3D::SFVec3f > _angularFreedom = 0,
00118 H3D::Inst<H3D::SFFloat > _linearDamping = 0,
00119 H3D::Inst<H3D::SFFloat > _rotationalDamping = 0,
00120 H3D::Inst< MFCollidableGeometry > _collisionSpheres = 0,
00121 H3D::Inst< H3D::SFFloat > _collisionStiffness = 0,
00122 H3D::Inst< H3D::SFFloat > _collisionResolution = 0);
00123
00124 static H3D::H3DNodeDatabase database;
00125
00126 virtual void initialize();
00127
00132 auto_ptr< MFCollidableGeometry > collisionSpheres;
00133
00138 auto_ptr< H3D::SFFloat > collisionStiffness;
00139
00145 auto_ptr< H3D::SFFloat> collisionResolution;
00146
00151 auto_ptr< H3D::SFBool> autoGenerateCollisionSpheres;
00152
00158 auto_ptr< H3D::SFInt32> debugCollisionSphereLayer;
00159
00164 auto_ptr< H3D::SFFloat> overlap;
00165
00167 H3D::Matrix4f getGlobalToLocal() const {
00168 return accumulatedInverse->getValue();
00169 }
00171 H3D::Matrix4f getLocalToGlobal() const {
00172 return accumulatedForward->getValue();
00173 }
00174
00175
00176 protected:
00177 virtual void buildSphereHierarchy(const H3D::Matrix4f & trans, X3DGroupingNode * grpP,
00178 CollisionSphere * parent_sphP, u_int layer,
00179 H3D::H3DFloat scale);
00180
00181 virtual void createSpheres(const H3D::Matrix4f & trans,
00182 H3D::X3DShapeNode * shapeP,
00183 CollisionSphere * parent_sphP,
00184 u_int layer, H3D::H3DFloat scale);
00185
00186 virtual void createSpheresOverGeometry(const H3D::Matrix4f & trans,
00187 const H3D::Vec3f & offset_in_geom,
00188 const H3D::Vec3f & size,
00189 CollisionSphere * parent_sphP,
00190 u_int layer, H3D::X3DGeometryNode * geomP,
00191 H3D::H3DFloat scale);
00192
00193 virtual CollisionSphere * createSphere(const H3D::Matrix4f & trans, bool leaf_node, u_int layer,
00194 H3D::H3DFloat dia, const H3D::Vec3f & rel_pos);
00195
00196 virtual bool containsPoints(CollisionSphere * sphP,
00197 H3D::X3DComposedGeometryNode * coord_setP);
00198
00199 private:
00200 u_int max_dim, middle_dim, min_dim;
00201 static const u_int split;
00202 H3D::Matrix4f identity_trans;
00203 };
00204
00205 }
00206
00207 #endif