• Advertisement


This topic is now archived and is closed to further replies.

Tell me what im doing wrong plz

This topic is 5806 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

Im trying to make a local axis for my object. I dont know if the code i wrote is completly wrong or i did some small mistake well i made a look,up,right & pos vectors for my object i can move the object while rotating fine but when i pitch or yaw everything gets screwed up well heres the code. struct Object { D3DXVECTOR3 vLook; D3DXVECTOR3 vUp; D3DXVECTOR3 vRight; D3DXVECTOR3 vPos; FLOAT fYaw, fPitch, fRoll; D3DMATRIX matLocal; D3DMATERIAL8 mtrl; // material data CD3DMesh* mesh; // mesh data }; OneTimeInit() // Fighter object m_oFighter.vPos = D3DXVECTOR3( 0.0f, 0.0f, 0.0f); m_oFighter.vLook = D3DXVECTOR3( 0.0f, 0.0f,-1.0f); m_oFighter.vUp = D3DXVECTOR3( 0.0f, 1.0f, 0.0f); m_oFighter.vRight = D3DXVECTOR3(-1.0f, 0.0f, 0.0f); m_oFighter.fYaw = 0.0f; m_oFighter.fPitch = 0.0f; m_oFighter.fRoll = 0.0f; Frame Move() const cTimeScale = 5; // elapsed time m_fTimeElapsed=(m_fTime-m_fStartTimeKey) * cTimeScale; // store last time m_fStartTimeKey=m_fTime; FLOAT fspeed= 3.0f * m_fTimeElapsed; // 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); //Matrices for pitch and Roll D3DXMATRIX matPitch,matYaw,matRoll,matTemp; D3DXMatrixRotationAxis(&matPitch,&m_oFighter.vRight,m_oFighter.fPitch); D3DXMatrixRotationAxis(&matYaw,&m_oFighter.vUp,m_oFighter.fYaw); D3DXMatrixRotationAxis(&matRoll,&m_oFighter.vLook,m_oFighter.fRoll); //Rotate the LOOK & Right vectors on the UP vector D3DXVec3TransformCoord(&m_oFighter.vLook,&m_oFighter.vLook,&matYaw); D3DXVec3TransformCoord(&m_oFighter.vRight,&m_oFighter.vRight,&matYaw); //Rotate the LOOK & Up vectors on the Right vector D3DXVec3TransformCoord(&m_oFighter.vLook,&m_oFighter.vLook,&matPitch); D3DXVec3TransformCoord(&m_oFighter.vUp,&m_oFighter.vUp,&matPitch); //Rotate the Right & Up vectors on the Look vector D3DXVec3TransformCoord(&m_oFighter.vRight,&m_oFighter.vRight,&matRoll); D3DXVec3TransformCoord(&m_oFighter.vUp,&m_oFighter.vUp,&matRoll); //********************************************************** // Fighter object //********************************************************** if (m_bKey[''D'']) m_oFighter.fRoll -= 2.0f*m_fTimeElapsed; //rotate right if (m_bKey[''A'']) m_oFighter.fRoll += 2.0f*m_fTimeElapsed; //rotate left if (m_bKey[''Q'']) m_oFighter.fPitch -= 2.0f*m_fTimeElapsed; //pitch down if (m_bKey[''E'']) m_oFighter.fPitch += 2.0f*m_fTimeElapsed; // pitch up if (m_bKey[''R'']) m_oFighter.fYaw -= 2.0f*m_fTimeElapsed; // Slide Left if (m_bKey[''F'']) m_oFighter.fYaw += 2.0f*m_fTimeElapsed; // Slide Right if (m_bKey[''W'']) // Forward { m_oFighter.vPos+=fspeed*m_oFighter.vLook; } // camera back if (m_bKey[''S'']) // Back { m_oFighter.vPos-=fspeed*m_oFighter.vLook; } D3DXMATRIX matWorld; D3DXMatrixTranslation(&matWorld, m_oFighter.vPos.x, m_oFighter.vPos.y, m_oFighter.vPos.z); D3DXMatrixMultiply( &matTemp, &matYaw, &matPitch ); D3DXMatrixMultiply( &matTemp, &matRoll, &matTemp ); D3DXMatrixMultiply( &matWorld, &matTemp, &matWorld ); m_oFighter.matLocal = matWorld; i would appreciate any help thxs

Share this post

Link to post
Share on other sites

  • Advertisement