Small problem

Started by
4 comments, last by EagleWarrior 22 years ago
when i rotate my object it keeps rotating even when i stop pressing the key but when i translate it moves fine only the rotate. have no idea y it does that if any of u have any ideas plz tell me
Advertisement
Do you only perform the matrix multiplication in response to keypresses, or do you perform it every iteration of the process loop? If the latter, are you resetting your matrix to identity?

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
i perfomr it every iteration of the process and no im not resetting my matrix to identity
If you are seting the object rotation veloscity, then dont forget to have a ''slower-downer'', somthing that decreses the veloscety every frame. If not then no idea

[ my engine ][ my game ][ my email ]
SPAM
Rate me up.
quote:Original post by EagleWarrior
i perfomr it every iteration of the process and no im not resetting my matrix to identity


Are you concetrating your current transformation matrix with the new one?

[ my engine ][ my game ][ my email ]
SPAM
Rate me up.
yes
// Normalizing Axis
D3DXVec3Normalize(&m_oFighter.vLook,&m_oFighter.vLook);
D3DXVec3Cross(&m_oFighter.vRight,&m_oFighter.vUp,&m_oFighter.vLook);
D3DXVec3Normalize(&m_oFighter.vRight,&m_oFighter.vRight);
D3DXVec3Cross(&m_oFighter.vUp,&m_oFighter.vLook,&m_oFighter.vRight);
D3DXVec3Normalize(&m_oFighter.vUp,&m_oFighter.vUp);

//**********************************************************
// Fighter object
//**********************************************************
if (m_bKey['D']) m_oFighter.fRoll -= 3.0f*m_fTimeElapsed/5000; //rotate right
if (m_bKey['A']) m_oFighter.fRoll += 3.0f*m_fTimeElapsed/5000; //rotate left
if (m_bKey['Q']) m_oFighter.fPitch -= 2.0f*m_fTimeElapsed/1000; //pitch down
if (m_bKey['E']) m_oFighter.fPitch += 2.0f*m_fTimeElapsed/1000; // pitch up
if (m_bKey['R']) m_oFighter.fYaw -= 2.0f*m_fTimeElapsed/1000; // YAW left
if (m_bKey['F']) m_oFighter.fYaw += 2.0f*m_fTimeElapsed/1000; // YAW right




D3DXMATRIX matRoll,matYaw,matPitch,matWorld,matTrans,matRot1;
D3DXMatrixIdentity(&matWorld);

D3DXMatrixRotationAxis(&matRoll,&m_oFighter.vLook,m_oFighter.fRoll);
//Rotate the Right & Up vectors on the Look vector ROLL
D3DXVec3TransformCoord(&m_oFighter.vRight,&m_oFighter.vRight,&matRoll);
D3DXVec3TransformCoord(&m_oFighter.vUp,&m_oFighter.vUp,&matRoll);

D3DXMatrixRotationAxis(&matYaw,&m_oFighter.vUp,m_oFighter.fYaw);
//Rotate the LOOK & Right vectors on the UP vector YAW
D3DXVec3TransformCoord(&m_oFighter.vLook,&m_oFighter.vLook,&matYaw);
D3DXVec3TransformCoord(&m_oFighter.vRight,&m_oFighter.vRight,&matYaw);


D3DXMatrixRotationAxis(&matPitch,&m_oFighter.vRight,m_oFighter.fPitch);
//Rotate the LOOK & Up vectors on the Right vector PITCH
D3DXVec3TransformCoord(&m_oFighter.vLook,&m_oFighter.vLook,&matPitch);
D3DXVec3TransformCoord(&m_oFighter.vUp,&m_oFighter.vUp,&matPitch);

if (m_bKey['S']) // Back
{
m_oFighter.vPos.x+=fspeed*m_oFighter.vLook.x;
m_oFighter.vPos.y+=fspeed*m_oFighter.vLook.y;
m_oFighter.vPos.z+=fspeed*m_oFighter.vLook.z;
}


if (m_bKey['W']) // Forward
{
m_oFighter.vPos.x-=fspeed*m_oFighter.vLook.x;
m_oFighter.vPos.y-=fspeed*m_oFighter.vLook.y;
m_oFighter.vPos.z-=fspeed*m_oFighter.vLook.z;
}


D3DXMatrixTranslation(&matTrans, m_oFighter.vPos.x, m_oFighter.vPos.y, m_oFighter.vPos.z);
D3DXMatrixLookAtLH(&matRot1, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &m_oFighter.vLook, &m_oFighter.vUp);
D3DXMatrixInverse(&matRot1, NULL, &matRot1);
matWorld=matRot1*matTrans;

m_oFighter.matLocal = matWorld;

i divided it by 5000 cause when i press any button it rotates to dam fast

[edited by - EagleWarrior on March 21, 2002 4:33:46 PM]

This topic is closed to new replies.

Advertisement