Original Post
Hey guys, I recently moved to DirectX and I've been putting together a little component-based framework to make a prototype with, but I'm having what seems like a bizarre problem. Basically, I'm rendering a box to the screen, and each frame I want to be able to move it forward, left, back or right using the 'w', 'a', 's' and 'd' keys respectively. At the minute my code is very simple. If any of these buttons are pressed, the appropriate x, y, z variable is set, and afterwards a D3DXMATRIX for movement is created, set with D3DXMatrixIdentity, and then set again with D3DXMatrixTranslation. After this, the movement matrix is added to the position matrix for the box, and this matrix is used when setting the WVP matrix. The problem is, the speed of the objects movement in any direction seems to decrease rapidly the more each button is pressed, and if no button is pressed, the box slowly moves back toward the (0, 0, 0) position. Can anyone help me understand why this is happening? Apologies if this isn't DirectX related. [Edited by - Exomoto on January 16, 2010 2:37:55 PM]
D3DXMATRIX boxPosition;
void App::Init()
{
//Other code
D3DXMatrixIdentity(&boxPosition);
//More code
}
void App::Update(float dt)
{
float x = 0.0f, y = 0.0f, z = 0.0f;
if(GetAsyncKeyState('A') & 0x8000) x = -1000.0f * dt;
if(GetAsyncKeyState('D') & 0x8000) x = 1000.0f * dt;
if(GetAsyncKeyState('W') & 0x8000) z = 1000.0f * dt;
if(GetAsyncKeyState('S') & 0x8000) z = -1000.0f * dt;
D3DXMATRIX temp;
D3DXMatrixIdentity(&temp);
D3DXMatrixTranslation(&temp, x, y, z);
boxPosition += temp;
//More code
}
void App::Draw()
{
//More code
pass->Apply(0);
mWVP = boxPosition * mView * mProj;
mfxWVPVar->SetMatrix((float*)&mWVP);
//Render box
mPlayer->Draw();
//More code
}