hkaRagdollInstance.h
上传用户:yisoukefu
上传日期:2020-08-09
资源大小:39506k
文件大小:10k
源码类别:

其他游戏

开发平台:

Visual C++

  1. /* 
  2.  * 
  3.  * Confidential Information of Telekinesys Research Limited (t/a Havok). Not for disclosure or distribution without Havok's
  4.  * prior written consent. This software contains code, techniques and know-how which is confidential and proprietary to Havok.
  5.  * Level 2 and Level 3 source code contains trade secrets of Havok. Havok Software (C) Copyright 1999-2009 Telekinesys Research Limited t/a Havok. All Rights Reserved. Use of this software is subject to the terms of an end user license agreement.
  6.  * 
  7.  */
  8. #ifndef INC_HKRAGDOLL_INSTANCE
  9. #define INC_HKRAGDOLL_INSTANCE
  10. #include <Common/Base/hkBase.h>
  11. #include <Physics/Dynamics/Entity/hkpRigidBody.h>
  12. #include <Physics/Dynamics/Constraint/hkpConstraintInstance.h>
  13. #include <Physics/Dynamics/World/hkpPhysicsSystem.h>
  14. #include <Animation/Animation/Rig/hkaSkeleton.h>
  15. #include <Animation/Animation/Rig/hkaSkeletonUtils.h>
  16. extern const hkClass hkaRagdollInstanceClass;
  17. /// An hkaRagdollInstance encapsulates the rigid bodies, constraints and associated skeleton for a physical ragdoll.
  18. /// It also provides utilities to get / set poses, add and remove from world, cloning, and handling rigid body transforms.
  19. class hkaRagdollInstance : public hkReferencedObject
  20. {
  21. public:
  22. HK_DECLARE_REFLECTION();
  23. HK_DECLARE_CLASS_ALLOCATOR(HK_MEMORY_CLASS_ANIMATION);
  24. /// Constructor, requires a properly ordered set of rigid bodies and constraints.
  25. /// The must represent a tree (n rigid bodies, n-1 constraints), and the local
  26. /// transformation of the rigid bodies must match the pivot of the bone they represent.
  27. /// You can use hkaRagdollUtils::prepareSystemForRagdoll() in order to ensure this.
  28. /// The skeleton contains information about hierarchy, bone names, initial pose and bone constraints.
  29. /// You can generate an hkaSkeleton from a physics system by using the utility hkaRagdollUtils::constructSkeletonFromRagdoll().
  30. hkaRagdollInstance ( const hkArray<hkpRigidBody*>& rigidBodies, const hkArray<hkpConstraintInstance*>& constraints, const hkaSkeleton* skeleton );
  31. /// Same as the above constructor, but the extra bone-to-rigidbody map allows the ragdoll skeleton to have extra bones
  32. hkaRagdollInstance ( const hkArray<hkpRigidBody*>& rigidBodies, const hkArray<hkpConstraintInstance*>& constraints, const hkaSkeleton* skeleton , const hkArray<int>& boneToRigidBody);
  33. /// Destructor.
  34. virtual ~hkaRagdollInstance ();
  35. /// Cloning - it returns a new hkaRagdollInstance cloned from this one.
  36. ///
  37. /// When using the hkConstraintInstane::CLONE_DATAS_WITH_MOTORS mode
  38. /// this method clones 'powered' hkConstraintDatas, therefore it also 
  39. /// clones motors, what lets you set their targets independently of those of 
  40. /// the original ragdoll's.
  41. virtual hkaRagdollInstance* clone(hkpConstraintInstance::CloningMode mode = hkpConstraintInstance::CLONE_INSTANCES_ONLY) const;
  42. //
  43. // Accessors
  44. //
  45. /// Number of bones.
  46. inline int getNumBones () const;
  47. /// Access the rigid body associated with the i-th bone.
  48. inline hkpRigidBody* getRigidBodyOfBone (int i) const;
  49. /// Get the bone index of the rigid body, or -1 if it is not a body in the ragdoll.
  50. inline int getBoneIndexOfRigidBody (hkpRigidBody* rb) const;
  51. /// Access the constraint associated with the i-th bone. The constraint associated with a bone is the constraint that links that bone with its parent.
  52. /// Notice, therefore, that getConstraint(0) returns HK_NULL. 
  53. inline hkpConstraintInstance* getConstraintOfBone (int i) const;
  54. /// Access the associated skeleton
  55. inline const hkaSkeleton* getSkeleton () const;
  56. /// Retrieves the ID of the parent of a bone. -1 for the root (bone 0).
  57. inline int getParentOfBone (int i) const;
  58. /// Returns a (const) array of rigid bodies representing the bones
  59. inline const hkArray<hkpRigidBody*>& getRigidBodyArray() const;
  60. /// Returns a (const) array of constraint representing the joints. Notice that, since the root (bone 0) has no parent, 
  61. /// the size of this array is n-1, where n is the number of bones.
  62. inline const hkArray<hkpConstraintInstance*>& getConstraintArray() const;
  63. /// Returns true if the ragdoll instance has more bones than rigid bodies. From 4.6, Ragdolls can have extra terminals bones,
  64. /// which can be useful in order to perform some operations.
  65. inline hkBool hasNonRigidBodyBones () const;
  66. //
  67. // Get/Set pose methods
  68. //
  69. /// Gets the current pose of the rag doll in world space.
  70. void getPoseWorldSpace (hkQsTransform* poseWorldSpaceOut) const;
  71. /// Gets the current pose of the rag doll in world space
  72. /// The user may optionally specify a local space pose for unmapped bones.  If NULL, these bones are filled in with the reference pose.
  73. void getPoseWorldSpace (hkQsTransform* poseWorldSpaceOut, const hkQsTransform& worldFromModel, const hkQsTransform* localSpacePoseForUnmappedBonesOptional = HK_NULL ) const;
  74. /// Sets the current pose of the rag doll using a pose in world space  - WARNING: This is for 'posing' the ragdoll and should not be called every frame - use controllers to drive a ragdoll. 
  75. void setPoseWorldSpace (const hkQsTransform* poseModelSpaceIn);
  76. /// Gets the current pose of the rag doll in model space
  77. /// This is similar to getPoseWorldSpace but it uses the worldFromModel transform to transform the result to model space
  78. void getPoseModelSpace (hkQsTransform* poseModelSpaceOut, const hkQsTransform& worldFromModel) const;
  79. /// Sets the current pose of the rag doll using a pose in model space - WARNING: This is for 'posing' the ragdoll and should not be called every frame - use controllers to drive a ragdoll. 
  80. void setPoseModelSpace (const hkQsTransform* poseModelSpaceIn, const hkQsTransform& worldFromModel);
  81. /// Sets the current pose and velocities of the rag doll using two poses in model space, separated by a given timestep.
  82. /// The rigid bodies are set to the positions and orientations of poseModelSpaceB, and the velocities are set to those
  83. /// that would have been required to bring the rigid bodies from poseModelSpaceA to poseModelSpaceB
  84. void setPoseAndVelocitiesModelSpace ( const hkQsTransform* poseModelSpaceA, const hkQsTransform& worldFromModelA, 
  85. const hkQsTransform* poseModelSpaceB, const hkQsTransform& worldFromModelB, hkReal timestep);
  86. //
  87. // World add remove methods
  88. //
  89. /// Add to world; returns failure if the ragdoll is already in the world.
  90. /// The 'updateFilter' parameter can be used to force a filter update after both the bodies *and the constraints* have been added.
  91. /// This will only be necessary if the user has implemented filter logic (their own custom filter) based on the addition
  92. /// of constraints in the world - it will not be necessary for the supplied Havok filters: 
  93. /// hkpGroupFilter, hkpCollisionFilterList, hkpNullCollisionFilter, hkpPairCollisionFilter, hkpPairwiseCollisionFilter - because they don't depend on constraints 
  94. /// hkpConstrainedSystemFilter - because it uses listeners to update on constraint addition
  95. hkResult addToWorld (hkpWorld* world, hkBool updateFilter) const;
  96. /// Removes from world; returns failure if the ragdoll wasn't part of a world.
  97. hkResult removeFromWorld () const;
  98. /// Returns the world where the ragdoll has been added to (HK_NULL if none).
  99. inline hkpWorld* getWorld() const;
  100. //
  101. // Utility methods
  102. //
  103. /// Returns the current transform (worldFromBone) of the i-th bone (rigid body).
  104. /// Position and orientation are taken from the rb, scale is taken from the reference pose of the skeleton
  105. void getWorldFromBoneTransform (int i, hkQsTransform& worldFromBoneOut) const;
  106. /// Returns the current transform (bone-to-world) of the i-th bone (rigid body).
  107. /// Position and orientation are taken from the rb, scale is taken from the reference pose of the skeleton
  108. /// This method uses hkpRigidBody::approxTransformAt and is useful if you are stepping animation and physics independently.
  109. void getApproxWorldFromBoneTransformAt (int i, hkReal time, hkQsTransform& worldFromBoneOut) const;
  110. public:
  111. /// The rigid bodies associated with this rag doll.
  112. /*const*/ hkArray<hkpRigidBody*> m_rigidBodies;
  113. /// The constraints associated with this rag doll 
  114. /*const*/ hkArray<hkpConstraintInstance*> m_constraints;
  115. /// For ragdolls with non-rigid-body bones, we need this map
  116. /*const*/ hkArray<int> m_boneToRigidBodyMap; // HKA-773
  117. /// The skeleton associated with this rag doll.
  118. const hkaSkeleton* m_skeleton;
  119. public:
  120. hkaRagdollInstance( hkFinishLoadedObjectFlag f ) :
  121. hkReferencedObject(f), m_rigidBodies(f), m_constraints(f), m_boneToRigidBodyMap(f) { } 
  122. private:
  123. void commonInit (const hkArray<hkpRigidBody*>& rigidBodies, const hkArray<hkpConstraintInstance*>& constraints, const hkaSkeleton* skeleton);
  124. };
  125. #include <Animation/Ragdoll/Instance/hkaRagdollInstance.inl>
  126. #endif //INC_HKRAGDOLL_INSTANCE
  127. /*
  128. * Havok SDK - NO SOURCE PC DOWNLOAD, BUILD(#20090216)
  129. * Confidential Information of Havok.  (C) Copyright 1999-2009
  130. * Telekinesys Research Limited t/a Havok. All Rights Reserved. The Havok
  131. * Logo, and the Havok buzzsaw logo are trademarks of Havok.  Title, ownership
  132. * rights, and intellectual property rights in the Havok software remain in
  133. * Havok and/or its suppliers.
  134. * Use of this software for evaluation purposes is subject to and indicates
  135. * acceptance of the End User licence Agreement for this product. A copy of
  136. * the license is included with this software and is also available at www.havok.com/tryhavok.
  137. */