Skip to main content
gamedev.net
🔒 Locked

How to implement input interface

Started by Roy_Fokker Apr 26, 2004 at 7:09 PM 3 replies 300+ views
Original Post
Roy_Fokker
Roy_Fokker
Hi, I want to know if there are any articles floating about the web that could point me in the right direction with regards to following problem, or if any of you can give me a good idea as to how to solve this problem. I am working on an Engine that use OpenGL and Direct Input. The problem i have is that i don't like how i have Direct Input and OpenGL scene Interfacing. What i currently do is When user press a key or moves the mouse, i change the values of respective variable in my DrawScene Object (Variables are part of DrawScene Object Class). DrawScene then takes these value and appropriately moves the camera. in the WinMain function i have the following
if (pDInput->Update())
{
   if(pDInput->Keypressed(DIK_UP))
      pDScene->Cam1->MoveCamera(SPD);
}
if(pDScene->DrawScene())
   SwapBuffers(pGame->GetHDC());
Where pDInput is DirectInput Object and pDScene is the Rendering Object which renders the OpenGL stuff. Cam1 is Camera Object within DrawScene. Is there a better way of doing this. Something about the way i do this doesn't seem proper. [edited by - Roy_Fokker on April 26, 2004 8:09:41 PM]
oliii
oliii
abstraction layers. Have an abstract base class CInputSystem, which derives into a sub-class DirectXDeviceManager, this will have all the IDirectInput8 dependencies neatly tugged away. Then do the same for the mouse, keyboard, joystick, wheels, for all the IDirectInputDevice8 ....

and you can provide your own keyboard mapping IDs, so you can also hide away all the DIK_##something dependencies from the code. Probably also have a CKeyConfig class, which would take care of the user-defined key configurations, with all the key-to-action mappings, and the joystick/mouse axis mappings, menu keys defined, ect...
Everything is better with Metal.
Roy_Fokker
Roy_Fokker
Action Mapping is not my problem.

I am just wonder if there is a better way to control the camera movement. any other better way in place of the way i am doing it now.

So while action mapping will allow for User side configurablity. I would still be passing values to the the Camera object in following manner

pDScene->Cam1->MoveCamera(value) or pDScene->Cam1->StrafeCamera(value).

oliii
oliii
ah OK. I''d probably let the camera handle it''s movement by itself, with a key config structure stored in there, like for players.


//......

{
pDInput->Update();
pCamera->ProcessInputs(pDInput);
}
//.......


CCamera::ProcessInputs(CInputSystem* pInputs)
{
if (pInputs->KeyDown(m_pKeyConfig->GetLeftKey ())) MoveLeft ();
if (pInputs->KeyDown(m_pKeyConfig->GetRightKey())) MoveRight();
}


also, I''d dissasociate the Camera update, with the rendering all together.


void UpdateScene()
{
BeginUpdate(); // setup timers


pDInput->Update();
pCamera->ProcessInputs(pDInput);
UpdateEntities();

EndUpdate(); // dunno...

}

void RenderScene()
{
BeginScene(); // clear buffers


pCamera->ApplySettings();
RenderEntities();

EndScene(); // swap buffers

}
Everything is better with Metal.
Roy_Fokker
Roy_Fokker
That is helpful thank you

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.