void CAnimationInstance::UpdateFrameMatrices( LPD3DXFRAME pFrameBase, LPD3DXMATRIX pTransformMatrix) { //! Make a frame pointer to the base. D3DXFRAME_ANIM * pFrame = (D3DXFRAME_ANIM *)pFrameBase; if( pTransformMatrix != NULL) { //! Multiply the Frame Transformation Matrix with the World Transformation Matrix to get the Combind Transformation Matrix. D3DXMatrixMultiply( &pFrame->CombinedTransformationMatrix, &pFrame->TransformationMatrix, pTransformMatrix); } else { //! We are on the parent matrix. So it's combined is equivalent to it's Transformation Matrix. pFrame->CombinedTransformationMatrix = pFrame->TransformationMatrix; } if( pFrame->pFrameSibling != NULL) { //! If there is a sibling frame update it. UpdateFrameMatrices( pFrame->pFrameSibling, pTransformMatrix); } if( pFrame->pFrameFirstChild != NULL) { UpdateFrameMatrices( pFrame->pFrameFirstChild, &pFrame->CombinedTransformationMatrix); } }
void SkinnedMesh::Update( float dt, D3DXMATRIXA16* matrix ) { /* // 조심해!!! D3DXQUATERNION qRotation; float scaleConstant = 0.2; D3DXVECTOR3 scale = D3DXVECTOR3( scaleConstant, scaleConstant, scaleConstant ); // D3DXVECTOR3 position = D3DXVECTOR3( -m_vObjectCenter.x * scaleConstant, -m_vObjectCenter.y * scaleConstant, -m_vObjectCenter.z * scaleConstant ); D3DXVECTOR3 position = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); D3DXMatrixIdentity( &m_Matrix ); // rotation에서 쿼터니언 생성, yaw ptich roll 은 y, x, z 순서임 D3DXQuaternionRotationYawPitchRoll( &qRotation, D3DXToRadian( 0.0f ), D3DXToRadian( 0.0f ), D3DXToRadian( 0.0f ) ); // matrix를 affine변환이 적용된 형태로 변환 D3DXMatrixTransformation( &m_Matrix, NULL, NULL, &scale, NULL, &qRotation, &position ); */ m_Matrix = *matrix; if ( m_pAnimController != NULL ) m_pAnimController->AdvanceTime( dt, NULL ); // 위에서 부모의 m_Matrix와 자신의 m_Matrix를 누적한 값을 자신의 m_Matrix에 저장해둘 것 // 프레임 내부에 있는 변환 행렬에 월드 좌표계 변환을 추가 // 원래 프레임 안에서는 로컬 좌표계 기준에서의 변환만 존재하는 듯 UpdateFrameMatrices( m_pFrameRoot, &m_Matrix ); }
void MoonSkinmesh::FrameMove(float ftime, D3DXMATRIX matWorld) { if (_pAnimController != NULL) { _pAnimController->AdvanceTime(ftime, NULL); } UpdateFrameMatrices(_pFrameRoot, &matWorld); }
void CDexModelXAni::UpdateFrameMatrices(LPD3DXFRAME pFrameBase, LPD3DXMATRIX pParentMatrix) { stDexFrameEx *pFrame = (stDexFrameEx*)pFrameBase; if (pParentMatrix != NULL) D3DXMatrixMultiply(&pFrame->CombinedTransformationMatrix, &pFrame->TransformationMatrix, pParentMatrix); else pFrame->CombinedTransformationMatrix = pFrame->TransformationMatrix; if (pFrame->pFrameSibling != NULL) { UpdateFrameMatrices(pFrame->pFrameSibling, pParentMatrix); } if (pFrame->pFrameFirstChild != NULL) { UpdateFrameMatrices(pFrame->pFrameFirstChild, &pFrame->CombinedTransformationMatrix); } }
/** * \brief Called to update the frame matrices in the hierarchy to reflect current animation stage * \param frameBase - frame being looked at * \param parentMatrix - the matrix of our parent (if we have one) * \author Keith Ditchburn \date 18 July 2005 */ void CXFileEntity::UpdateFrameMatrices(const D3DXFRAME *frameBase, const D3DXMATRIX *parentMatrix) { D3DXFRAME_EXTENDED *currentFrame = (D3DXFRAME_EXTENDED*)frameBase; // If parent matrix exists multiply our frame matrix by it if (parentMatrix != NULL) D3DXMatrixMultiply(¤tFrame->exCombinedTransformationMatrix, ¤tFrame->TransformationMatrix, parentMatrix); else currentFrame->exCombinedTransformationMatrix = currentFrame->TransformationMatrix; // If we have a sibling recurse if (currentFrame->pFrameSibling != NULL) UpdateFrameMatrices(currentFrame->pFrameSibling, parentMatrix); // If we have a child recurse if (currentFrame->pFrameFirstChild != NULL) UpdateFrameMatrices(currentFrame->pFrameFirstChild, ¤tFrame->exCombinedTransformationMatrix); }
void SkinnedMesh::UpdateFrameMatrices( LPD3DXFRAME pFrameBase, LPD3DXMATRIX pParentMatrix ) { D3DXFRAME_DERIVED* pFrame = (D3DXFRAME_DERIVED*)pFrameBase; if ( pParentMatrix != NULL ) D3DXMatrixMultiply( &pFrame->CombinedTransformationMatrix, &pFrame->TransformationMatrix, pParentMatrix ); else pFrame->CombinedTransformationMatrix = pFrame->TransformationMatrix; if ( pFrame->pFrameSibling != NULL ) { UpdateFrameMatrices( pFrame->pFrameSibling, pParentMatrix ); } if ( pFrame->pFrameFirstChild != NULL ) { UpdateFrameMatrices( pFrame->pFrameFirstChild, &pFrame->CombinedTransformationMatrix ); } }
void CLcXSkinSrc::UpdateFrameMatrices(SFrame* pFrameBase, D3DXMATRIX* pParentMatrix) { SFrame *pFrame = (SFrame*)pFrameBase; if (pParentMatrix != NULL) D3DXMatrixMultiply(&pFrame->tmWorld, &pFrame->tmMatrix, pParentMatrix); else pFrame->tmWorld = pFrame->tmMatrix; if (pFrame->pFrameSibling != NULL) { UpdateFrameMatrices(pFrame->pFrameSibling, pParentMatrix); } if (pFrame->pFrameFirstChild != NULL) { UpdateFrameMatrices(pFrame->pFrameFirstChild, &pFrame->tmWorld); } }
HRESULT CAnimationModel::FrameMove( float fElapsedTime, LPD3DXMATRIX pTM) { HRESULT hr = S_OK; m_pAniController->FrameMove( fElapsedTime ); UpdateFrameMatrices( m_pFrameRoot, pTM ); return hr; }
void XEnitity::UpdateFrameMatrices(const D3DXFRAME *pFrameBase, const D3DXMATRIX *pParentMatrix) { CUSTOM_FRAME* pFrame = (CUSTOM_FRAME*) pFrameBase; if(pParentMatrix != NULL) D3DXMatrixMultiply(&pFrame->exCombTransformationMatrix, &pFrame->TransformationMatrix, pParentMatrix); else pFrame->exCombTransformationMatrix = pFrame->TransformationMatrix; //pass to siblings if(pFrame->pFrameSibling){ UpdateFrameMatrices(pFrame->pFrameSibling, pParentMatrix); } //pass to childern if(pFrame->pFrameFirstChild){ UpdateFrameMatrices(pFrame->pFrameFirstChild, &pFrame->exCombTransformationMatrix); } return; }
void CLcXSkinSrc::Render() { if(m_pAC) { m_pAC->SetTrackPosition(0, 0); m_pAC->AdvanceTime(m_dTimeCur, NULL); } UpdateFrameMatrices(m_pFrameRoot, &m_mtWorld); DrawFrame(m_pFrameRoot); }
void CAnimationInstance::UpdateAnimation(/*D3DXMATRIXA16 * pWorldMatrix,*/ double dElapsedTime) { m_dTimePrev = m_dTimeCurrent; m_dTimeCurrent = m_dTimeCurrent + dElapsedTime; if( m_pAnimationController != NULL) { //! Update the elapsed time for the animation controller so it can interpolate. m_pAnimationController->AdvanceTime( dElapsedTime, NULL); } //! Traverse the Frame Hierarchy recursively to update them. UpdateFrameMatrices( m_pFrameRoot, &m_WorldMatrix); }
void CAnimationModel::UpdateFrameMatrices(LPD3DXFRAME pFrame, const LPD3DXMATRIX pParentMatrix) { CFrame *pFrame_Derived = (CFrame*) pFrame; if( NULL != pParentMatrix ) { D3DXMatrixMultiply( &pFrame_Derived->m_CombinedTransformationMatrix, &pFrame_Derived->TransformationMatrix, pParentMatrix ); } else { pFrame_Derived->m_CombinedTransformationMatrix = pFrame_Derived->TransformationMatrix; } if( NULL != pFrame_Derived->pFrameSibling ) { UpdateFrameMatrices( pFrame_Derived->pFrameSibling, pParentMatrix ); } if( NULL != pFrame_Derived->pFrameFirstChild ) { UpdateFrameMatrices( pFrame_Derived->pFrameFirstChild, &pFrame_Derived->m_CombinedTransformationMatrix ); } }
/** * \brief Called each frame update with the time and the current world matrix * \param elapsedTime - time passed * \param matWorld - current world matrix for the model * \author Keith Ditchburn \date 18 July 2005 */ void SkinnedData::FrameMove(float elapsedTime,const D3DXMATRIX *matWorld) { // Adjust animation speed elapsedTime/=speedAdjust; // Advance the time and set in the controller if (animController != NULL) animController->AdvanceTime(elapsedTime, NULL); currentTime+=elapsedTime; // Now update the model matrices in the hierarchy UpdateFrameMatrices(frameRoot, matWorld); // If the model contains a skinned mesh update the vertices D3DXMESHCONTAINER_EXTENDED* pMesh = firstMesh; if(pMesh && pMesh->pSkinInfo) { unsigned int Bones = pMesh->pSkinInfo->GetNumBones(); // Create the bone matrices that transform each bone from bone space into character space // (via exFrameCombinedMatrixPointer) and also wraps the mesh around the bones using the bone offsets // in exBoneOffsetsArray for (unsigned int i = 0; i < Bones; ++i) D3DXMatrixMultiply(&boneMatrices[i],&pMesh->exBoneOffsets[i], pMesh->exFrameCombinedMatrixPointer[i]); // We need to modify the vertex positions based on the new bone matrices. This is achieved // by locking the vertex buffers and then calling UpdateSkinnedMesh. UpdateSkinnedMesh takes the // original vertex data (in pMesh->MeshData.pMesh), applies the matrices and writes the new vertices // out to skin mesh (pMesh->exSkinMesh). // UpdateSkinnedMesh uses software skinning which is the slowest way of carrying out skinning // but is easiest to describe and works on the majority of graphic devices. // Other methods exist that use hardware to do this skinning - see the notes and the // DirectX SDK skinned mesh sample for more details void *srcPtr=0; pMesh->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&srcPtr); void *destPtr=0; pMesh->exSkinMesh->LockVertexBuffer(0, (void**)&destPtr); // Update the skinned mesh pMesh->pSkinInfo->UpdateSkinnedMesh(boneMatrices, NULL, srcPtr, destPtr); // Unlock the meshes vertex buffers pMesh->exSkinMesh->UnlockVertexBuffer(); pMesh->MeshData.pMesh->UnlockVertexBuffer(); } }
//-------------------------------------------------------------------------------------- // This callback function will be called once at the beginning of every frame. This is the // best location for your application to handle updates to the scene, but is not // intended to contain actual rendering calls, which should instead be placed in the // OnFrameRender callback. //-------------------------------------------------------------------------------------- void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext ) { // Update the camera's position based on user input g_Camera.FrameMove( fElapsedTime ); UpdateLightingEnvironment(); if( g_pAnimController != NULL ) { g_pAnimController->SetTrackSpeed( 0, g_SampleUI.GetSlider( IDC_ANIMATION_SPEED )->GetValue() / 1000.0f ); g_pAnimController->AdvanceTime( fElapsedTime, NULL ); } UpdateFrameMatrices( g_pFrameRoot, g_Camera.GetWorldMatrix() ); }
bool CDexModelXAni::Render(D3DXMATRIX& node_matrix) { UpdateFrameMatrices(m_pFrameRoot, &node_matrix); //DexGameEngine::getEngine()->GetDevice()->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); //DexGameEngine::getEngine()->GetDevice()->SetRenderState(D3DRS_LIGHTING, FALSE); ///evice->SetRenderState(D3DRS_ZENABLE, TRUE); //绘制frame DrawFrame(m_pFrameRoot); //矩阵重置,否则其他的渲染会受影响 D3DXMATRIX translation; D3DXMatrixTranslation(&translation, 0, 0, 0); DexGameEngine::getEngine()->GetDevice()->SetTransform(D3DTS_WORLD, &translation); return true; }
void XEnitity::FrameMove(float ElapsedTime,const D3DXMATRIX *pMatWorld) { //m_pAnimCtrl->ResetTime(); ElapsedTime/=m_SpeedAdjust; m_CurrentTime += ElapsedTime; if(m_pAnimCtrl) m_pAnimCtrl->AdvanceTime(ElapsedTime, NULL); UpdateFrameMatrices(m_pTopFrame, pMatWorld); UpdateSkinnedMesh(m_pTopFrame); return; }