// m_vLiikMaara is the amount of Movement // m_vPyorMaar is the amount of Rotation // m_matrix is objects transform matrix void Impulse(float seconds,D3DXVECTOR3 *pF,D3DXVECTOR3 *pPos) { D3DXVECTOR3 R,F,M; // Impulse the amount of movement m_vLiikMaara += *pF * seconds; // Transform the ForceDir to local space D3DXVec3TransformNormal( &F, pF, D3DXMatrixInverse(&D3DXMATRIX(),NULL,&m_matrix) ); // Transform the ForcePos to local space D3DXVec3TransformCoord( &R, pPos, D3DXMatrixInverse(&D3DXMATRIX(),NULL,&m_matrix) ); // calc momentum D3DXVec3Cross(&M, &R, &F); // Impulse the amount of rotation m_vPyorMaara += M * seconds; } D3DXVECTOR3 GetForce(float seconds,D3DXVECTOR3 *pPos,D3DXVECTOR3 *pDir) { D3DXVECTOR3 R,F,M; // Transform the Pos to local space D3DXVec3TransformCoord( &R, pPos, D3DXMatrixInverse(&D3DXMATRIX(),NULL,&m_matrix) ); // calc the moment M = m_vPyorMaara / seconds; // calc the Force by M and R D3DXVec3Cross(&F, &M, &R); // Transform Force to world space D3DXVec3TransformNormal(&F,&F,&m_matrix); // Now F is the Force by rotation // add the force by movement F += m_vLiikMaara / seconds; // Project the Force to pDir return *pDir * D3DXVec3Dot(pDir,&F) / D3DXVec3Dot(pDir,pDir); } |