Sign in to follow this  

AnimationController Question

This topic is 2550 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a peculiar controller problem.
Having just cloned the animation controller, I found my individual objects start and stop animating altogether. The mesh is loaded from a single source and dished out to individual character objects... Just don't know what to do. Here is some source code:

In my create submodule

for (int i = 0; i < 5; i++)
{
D3DXVECTOR3 pos;
pos.x = m_operatorLoc[i].mat._41;
pos.y = m_operatorLoc[i].mat._43;
pos.z = m_operatorLoc[i].mat._42;
m_CharInfo[i].vStartPos = pos;
m_CharInfo[i].fSpeed = fRandomSpeed.GetRandomNumber();

OperatorObj[i].Create(m_pDevice, &OperatorMesh);
OperatorObj[i].SetSize(fRandomSize.GetRandomNumber());
OperatorObj[i].SetPos(m_CharInfo[i].vStartPos);
OperatorObj[i].ChangeAnimation(0);

}






Each instances:

bool CObjects::Create(LPDIRECT3DDEVICE9 pDevice, CMesh *pMesh, float fAnimSpeed)
{
if(pMesh == NULL)
return false;

m_pDevice = pDevice;
m_pMesh = pMesh;
SetWalking(false);

if(m_pMesh->GetAnimController() != NULL)
{
DWORD dwNumAnimSet = m_pMesh->GetAnimController()->GetMaxNumAnimationSets();

// create a copy of the animation controller
if(FAILED(m_pMesh->GetAnimController()->CloneAnimationController(
m_pMesh->GetAnimController()->GetMaxNumMatrices(),
dwNumAnimSet,
// use max animation sets instead
dwNumAnimSet > 1 ? dwNumAnimSet : 2,
m_pMesh->GetAnimController()->GetMaxNumEvents(),
&m_pAnimController)))
return false;

/////..... blah blah







Updating individual objects

for(int i = 0; i < 5; i++)
{
// move point light with player
m_CharInfo[i].fDist = paths[i].size();
static int P = 0;
if(P < paths[i].size()-1 && m_bFinishedPathFind[i] || m_CharInfo[i].fS < 1.0f)//m_CharInfo[i].fDist && m_bFinishedPathFind[i])
{
m_CharInfo[i].fS += ((m_CharInfo[i].fSpeed / m_CharInfo[i].fDist) * m_fElapsedTime);

vecPosMan.x = paths[i][(int)P].x;
vecPosMan.y = m_CharInfo[i].vStartPos.y;
//vecPosMan.z = paths[i][paths[i].size()-1].y;
vecPosMan.z = paths[i][(int)P++].y;


OperatorObj[i].SetPos(vecPosMan);
float xT = OperatorObj[i+1].GetPos().x - OperatorObj[i].GetPos().x;
float zT = OperatorObj[i+1].GetPos().z - OperatorObj[i].GetPos().z;
float fDir = atan2f(-xT,-zT);
OperatorObj[i].SetRot(D3DXVECTOR3(fDir,0,0));


}








then update transformations

if(m_vRot.x != 0.0f || m_vRot.y != 0.0f || m_vRot.z != 0.0f)
{
D3DXQuaternionRotationYawPitchRoll(&m_quatRot, m_vRot.x, m_vRot.y, m_vRot.z);
D3DXMatrixTransformation(&m_matWorld, &m_vScaleCenter, NULL, &m_vScale,
&m_vRotCenter, &m_quatRot, &m_vPos);
}
else
D3DXMatrixTransformation(&m_matWorld, &m_vScaleCenter, NULL, &m_vScale,
NULL, NULL, &m_vPos);

// check if current object is attach to other object
if(m_pCombineFrameMatrix != NULL)
m_matWorld *= *m_pCombineFrameMatrix;

if(m_pAnimController != NULL && m_bWalking)
{
// check if loop animation is enable and queue is empty
if(m_pTrackArray[m_dwCurrentTrack].bLoop && m_TrackQueue.empty())
m_pAnimController->SetTime(m_pAnimController->GetTime() + dt);

else // execute first the track waiting on the queue
{
double dTime = m_pAnimController->GetTime() + dt;
// if the current track is not yet done
if(m_pTrackArray[m_dwCurrentTrack].dPeriod > dTime * m_pTrackArray[m_dwCurrentTrack].TrackDesc.Speed)
m_pAnimController->SetTime(m_pAnimController->GetTime() + dt);

else // the track is done, check the queue
{
// if there's animation waiting in the queue
if(!m_TrackQueue.empty())
{
m_dwLastTrack = m_dwCurrentTrack;
//m_dwCurrentTrack = m_TrackQueue.front();
m_pTrackArray[m_dwCurrentTrack].bLoop = false;
m_pAnimController->SetTime(0.0f);
TransitionAnimation(m_dwCurrentTrack);
m_TrackQueue.pop();
}
else // there's none left
{
m_pAnimController->SetTime(m_pAnimController->GetTime());
ChangeAnimation(m_dwDefaultTrack);
}

}
}

}
UpdateFrame(m_pMesh->GetFrameRoot(), &m_matWorld);


}







and render

for (int i = 0; i < 5; i++)
{
OperatorObj[i].Update(fElapsedTime);
OperatorObj[i].Render();

}







Does anyone spot any bugs in my code?
The thing that baffles me is I initially set m_bWalking to false to all instances, then set it to true when pathfinding finishes, I can see
each m_bWalking for each object is different, but when the animation controller is not updating, that character is still moving. While I set m_bWalking to false
5 objects stop instantly.
only
Thanks
Jack

Share this post


Link to post
Share on other sites
It appears you're using a very old version of DirectX (pre-2005?) so there may not be anyone who can help you. There is some documentation on the web for some of the old calls you have in your code but there may not be anyone that knows much about them. You should consider upgrading to a newer version of DirectX and looking at the multi-animation instancing example there.

Share this post


Link to post
Share on other sites

This topic is 2550 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this