TAILIEUCHUNG - Character Animation with Direct3D- P9

Character Animation with Direct3D- P9:This book is primarily aimed at teaching indie and hobby game developers how to create character animation with Direct3D. Also, the seasoned professional game developer may find some interesting things in this book. You will need a solid understanding of the C++ programming language as well as general object-oriented programming skills. | 146 Character Animation with Direct3D Create Rigid Body btRigidBody body new btRigidBody mass ms cs localInertia Add the new body to the dynamics world pDynamicsWorld- addRigidBody body Then to run the simulation all you need to do is call the stepSimulation function each frame like this pDynamicsWorld- stepSimulation deltaTime That s it The rigid body you have now created will be simulated each frame colliding with other rigid bodies etc. However you still won t see anything on the screen because the box is nothing but a logical representation. You need to hook up the current motion state of the rigid body to a mesh. In the next example I create a rigid body for the Oriented Bounding Box OBB class that was covered in the previous chapter. So each frame the rigid body is updated using the Bullet physics library and then rendered using DirectX like this void OBB Render Get Motion state from rigid body btMotionState ms m_pBody- getMotionState if ms NULL return Convert the motion state to a DX matrix and use it to set the world transform pEffect- SetMatrix matW BT2DX_MATRIX ms Render the mesh as usual using whichever lighting technique D3DXHANDLE hTech pEffect- GetTechniqueByName Lighting pEffect- SetTechnique hTech pEffect- Begin NULL NULL pEffect- BeginPass 0 m_pMesh- DrawSubset 0 pEffect- EndPass pEffect- End You ll find the source code for the first example using the Bullet physics engine in Example . lease purchase PDF Split-Merge on to remove this watermark. Chapter 7 Ragdoll Simulation 147 Constraints After that little detour of getting to know the Bullet physics library it is time to get back to what I was trying to achieve in this chapter ragdoll animation You need to choose some of the major bones of the character and create a physical representation for them that can be simulated in the physics engine. Then as the ragdoll is simulated the position and orientation are updated for the bones using the transforms taken from the rigid bodies .