Hi,
I am writing a small demo, I've got a First Person Camera for the moment that I use to look around,I took it from a Book (introduction to DirectX by Frank Luna). The thing is that this class use DirectInput and to be honest if I had a US keyboard I would have not notice that DirectInput is not good enough to input. But I did, and this is my problem.
So I created a class to handle input:
class CInputHandler
{
public:
CInputHandler(void);
public:
virtual ~CInputHandler(void);
virtual void inputDetected(SEvent& in) ;
virtual bool isKeyDown(char c ) ;
virtual bool isKeyDown(Keycode key) ;
private:
SEvent mState ;
};
extern CInputHandler* gInputHandler ;
The inputDetected() function works fine, I get to know which key is pressed. I use it in my message handler as fallow:
case WM_KEYDOWN:
{
e.type = EventType::KEYBOARD_INPUT ;
e.keyInput.code = (Keycode)wParam ;
e.keyInput.keyPressed = true ;
WORD KeyAsc=0;
GetKeyboardState(keyboard);
ToAscii(wParam,lParam,keyboard,&KeyAsc,0);
e.keyInput.ascii = KeyAsc ;
gInputHandler->inputDetected(e) ;
return 0;
}
case WM_KEYUP:
{
e.type = EventType::KEYBOARD_INPUT ;
e.keyInput.code = (Keycode)wParam ;
e.keyInput.keyPressed = false ;
WORD KeyAsc=0;
GetKeyboardState(keyboard);
ToAscii(wParam,lParam,keyboard,&KeyAsc,0);
e.keyInput.ascii = KeyAsc ;
gInputHandler->inputDetected(e) ;
return 0;
}
Then I use the keyDown() method to see what's going on:
bool CInputHandler::isKeyDown(char c )
{
if ( (mState.type == EventType::KEYBOARD_INPUT) &&
mState.keyInput.keyPressed && (c == mState.keyInput.ascii) )
{
mState.keyInput.ascii = 0 ;
return true ;
}
return false ;
}
bool CInputHandler::isKeyDown(Keycode key )
{
if ( (mState.type == EventType::KEYBOARD_INPUT) &&
mState.keyInput.keyPressed && (key == mState.keyInput.code) )
{
mState.keyInput.code = (Keycode)0x00 ;
return true ;
}
return false ;
}
In my framework I have two method, onFrame(float dt) and onRender().
These two are executed when no Window Message has to be processed, the Camera is updated in the method onFrame().
How should I do for the Camera to be updated to move smoothly? Should I create a kind of event system which notify every classes requiring input?But If I do that do I still need my onFrame() method?
I know that my questions are a bit shabby so feel free to ask me precisions I just don't know now how to be clearer, for now. [depressed]
Thanks