Original Post
When i start the 3d engine, all objects have a different direction, but they're all spawned at the origin, and they don't move... The drawing code works fine, or at least it was before when i had 4 objects (not in a vector) and had them turn like clockwork (using timeGetTime as rotation). [Edited by - kVandaele on October 15, 2004 12:57:30 AM]
// code called in main program
// m_pFlightShips is a vector of pointers, pointing to a CFlightShip object
for(DWORD i=0; i<m_pFlightShips.size(); i++){
m_pFlightShips.at(i)->UpdatePos(m_dwTimePassed);
m_pFlightShips.at(i)->GetMatrix(&matObject);
m_pGfx->GetDevice()->SetTransform(D3DTS_WORLD, &matObject);
m_pShipMeshes.at(m_pFlightShips.at(i)->GetType())->Render();
}
void CFlightShip::GetMatrix(D3DXMATRIX* mat){
// Advanced 3D GAME Programming with DirectX 9.0
// page 166 - 167 'black box'
//... except, NOT!
// Note: I don't quite know what above comments mean (even if i did make them myself)
D3DXMATRIX matRot1;
D3DXMATRIX matRot2;
D3DXMATRIX matMove;
D3DXMatrixIdentity(mat);
D3DXMatrixTranslation(&matMove, m_Dir.x, m_Dir.y, m_Dir.z);
D3DXMatrixRotationX(&matRot1, atan2f(m_Dir.y, m_Dir.z));
D3DXMatrixRotationY(&matRot2, atan2f(m_Dir.z, m_Dir.x));
D3DXMatrixMultiply(mat, &matRot1, &matRot2);
D3DXMatrixRotationAxis(&matRot1, &m_Dir, atan2f(m_Dir.y, m_Dir.x));
D3DXMatrixMultiply(mat, &matRot1, mat);
// D3DXMatrixMultiply(mat, &matMove, mat);
// D3DXMatrixMultiply(mat, mat, &matRot1);
// D3DXMatrixMultiply(mat, mat, &matMove);
// Note: i've been struggling with this for a while, so i think two of the 4 don't need to be commented
}
void CFlightShip::UpdatePos(DWORD dwTimeElapsed){
// New position = old position + (direction * distance moved)
m_Pos = m_Pos + m_Dir * ((float)dwTimeElapsed/1000.0f * m_fVel);
}