;One of the things that ID3DXAllocateHierarchy does when we ;load a skinmesh is build an array of pointers to the 'inverse ;transformation matrices' of each of the Bones. ;Once you have a bone's inverse transformation matrix, you can ;iterate through each vertex that is attached to the bone. ;What you're going to do is transform those vertices using ;the bone's inverse transformation. Using the coordinates of ;these newly transformed vertices, you can compute the extents ;of your bounding box (which will eventually enclose each vertex ;and bone-to-bone connection point for the current bone). ;The GetBoneBoundingBoxSize method calculates this boundingbox. ;The function takes a pointer to a FRAME structure (which represents the bone) ;and also a pointer to a MeshContainer structure (which represents the mesh) .data MINIMUM_BONE_SIZE REAL4 1.0f .code ;This struct describes the Physics state ;of a Bone, its BoundingBox, etc RagDollBoneState struct m_vecPosition Vec3 <> ; Position m_quatOrientation D3DXQUATERNION <> ; Orientation m_matOrientation D3DXMATRIX <> ; Orientation m_vecAngularMomentum Vec3 <> ; Angular momentum m_vecLinearVelocity Vec3 <> ; Linear velocity m_vecAngularVelocity Vec3 <> ; Angular velocity ; Transformed points, including connection-to-parent ; position and parent-to-bone offset m_vecPoints Vec3 10 dup (<>) ; Body's inverse world moment of inertia tensor matrix m_matInvWorldInertiaTensor D3DXMATRIX <> RagDollBoneState ends ;Consider this as an Extension of the FRAME struct. ;We'll attach one of these to each BoneFrame :) ;It contains per-bone data for RagDoll physics state. RagDollBone struct ; Frame that this bone is connected to m_Frame dd ? ; Mass and 1/Mass (one-over-mass) m_Mass REAL4 ? ; Coefficient of restitution value ; 0 = no bounce ; 1 = 'super' bounce ; >1 = gain power in bounce m_Coefficient REAL4 ? m_ParentBone dd ?;Pointer to parent bone CRagDollBone ; Connection-to-parent offset and parent-to-bone offset m_vecJointOffset Vec3 <> m_vecParentOffset Vec3 <> m_vecBBSize Vec3 <> ; Linear force and angular momentum m_vecForce Vec3 <> m_vecTorque Vec3 <> ; Original orientation of bone m_quatOrientation D3DXQUATERNION <> ; Rate of resolution (0-1) to resolve slerp interpolation ; This is used to make bones return to their initial ; orientation relative to its parent. m_ResolutionRate REAL4 ? ; Body's inverse moment of inertia tensor matrix m_matInvInertiaTensor D3DXMATRIX <> ; Points (in body space) that form bounding box ; and connection-to-parent offset position m_vecPoints Vec3 9 dup (<>) ; Bone state m_State RagDollBoneState <> RagDollBone ends CRagDollID equ 39495 Object CRagDoll,CRagDollID,CModel StaticMethod ExtendFrame,Pointer StaticMethod BoneIndexFromBoneFrame,Pointer StaticMethod GetBoneBoundingBoxSize,Pointer ObjectEnd ;Extend a Bone's FRAME struct for RagDoll Physics ;Noe that ID3DXAllocateHierarchy now cleans up this resource Method CRagDoll.ExtendFrame,uses esi,pBoneFrame mov ebx,pBoneFrame mov [ebx].FRAME.pRagDollBone,$MemAlloc(sizeof RagDollBone,MEM_INIT_ZERO) MethodEnd ;Search for a Bone whose Name matches that of the given Frame ;Returns: index of matching Bone, or -1 for failure Method CRagDoll.BoneIndexFromBoneFrame,uses esi,pBoneFrame LOCAL pSkin LOCAL numBones LOCAL BoneNum SetObject esi .if [esi].m_pFirstMesh==0 DbgWarning "NULL m_pFirstMesh","CRagDoll.BoneIndexFromBoneFrame" invoke ExitProcess,0 .endif mov ebx,[esi].m_pFirstMesh m2m pSkin, [ebx].MESHCONTAINER.Base.pSkinInfo ; Search for a bone with same name as frame mov numBones,$ICall (pSkin::ID3DXSkinInfo.GetNumBones) mov BoneNum , -1 xor ecx,ecx .while ecx