My work-in-progress Direct3D engine now has the option for each rendered object to have a velocity vector. I calculate the change in position right before rendering, and the timer stops and starts before and after the calculation:
Code:
//Calc new object positions
Timer.Stop();
NewPositions();
Timer.Start();
//Render objects
vector<CRenderObject *>::iterator i;
for (i=Objects.begin();i!=Objects.end();i++)
{
Device->SetRenderState(D3DRS_FILLMODE,FillMode);
(*i)->Render(mWorld);
}
Code:
void DrawClass::NewPositions(void)
{
vector<CRenderObject *>::iterator i;
float Elapsed=(float)Timer.Elapsed();
for (i=Objects.begin();i!=Objects.end();i++)
{
(*i)->x+=Elapsed*(*i)->vx;
(*i)->y+=Elapsed*(*i)->vy;
(*i)->z+=Elapsed*(*i)->vz;
}
}
However, it does not work. Upon execution, each object travels only for a short period of time, eg less than one second, and then stops. If the window is manipulated, ie, moved or resized, the object moves for a little bit more. I guess that implies that the problem is related to the message loop. Here it is:
Code:
while (msg.message!=WM_QUIT)
{
dc->Render();
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
As far as I can tell, it should be continually rendering, and thus updating the object positions. Is there anything that appears incorrectly coded?