int d3d::EnterMsgLoop( bool (*ptr_display)(float timeDelta) )
{
MSG msg;
::ZeroMemory(&msg, sizeof(MSG));
static float lastTime = (float)timeGetTime();
while(msg.message != WM_QUIT)
{
if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
else
{
float currTime = (float)timeGetTime();
float timeDelta = (currTime - lastTime)*0.001f;
ptr_display(timeDelta);
lastTime = currTime;
}
}
return msg.wParam;
}
And here is the use of that function in main.cpp the way it was originally used before I started breaking things into separate classes.
d3d::EnterMsgLoop(Display);
And here is the class function that was spaghetti'ed in before I started to organize things. I think I am supposed to pass it in differently, but I have tried:
myLight.Display(timeGetTime) &directionalLight::Display(timeGetTime)
Here is the function
bool directionalLight::Display(float timeDelta)
{
if( Device )
{
//
// Update the scene: update camera position.
//
static float angle = (3.0f * D3DX_PI) / 2.0f;
static float height = 5.0f;
if( ::GetAsyncKeyState(VK_LEFT) & 0x8000f )
angle -= 0.5f * timeDelta;
if( ::GetAsyncKeyState(VK_RIGHT) & 0x8000f )
angle += 0.5f * timeDelta;
if( ::GetAsyncKeyState(VK_UP) & 0x8000f )
height += 5.0f * timeDelta;
if( ::GetAsyncKeyState(VK_DOWN) & 0x8000f )
height -= 5.0f * timeDelta;
D3DXVECTOR3 position( cosf(angle) * 7.0f, height, sinf(angle) * 7.0f );
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMATRIX V;
D3DXMatrixLookAtLH(&V, &position, &target, &up);
Device->SetTransform(D3DTS_VIEW, &V);
//
// Draw the scene:
//
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
Device->BeginScene();
for(int i = 0; i < 4; i++)
{
// set material and world matrix for ith object, then render
// the ith object.
Device->SetMaterial(&Mtrls[i]);
Device->SetTransform(D3DTS_WORLD, &Worlds[i]);
Objects[i]->DrawSubset(0);
}
Device->EndScene();
Device->Present(0, 0, 0, 0);
}
return true;
}
Any help would be appreciated.

New Topic/Question
Reply




MultiQuote






|