Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _KEYSTATE_H_
- #define _KEYSTATE_H_
- #include "PaulMath.h"
- #include "GL/glfw.h"
- class KeyState
- {
- public:
- //constructs and destructs,
- KeyState(void) { keys = new BitSet(GLFW_KEY_LAST); keysState = new BitSet(GLFW_KEY_LAST); }
- ~KeyState(void) { delete keys; delete keysState; }
- //call this every frame
- void Update()
- {
- for(int i = 0; i < GLFW_KEY_LAST; ++i)
- {
- //update keys
- if(!(*keysState)[i] && !(*keys)[i])
- {
- if(glfwGetKey(i)) keys->SetBit(i);
- }
- else keys->ClearBit(i);
- //update states
- if(glfwGetKey(i)) keysState->SetBit(i);
- else keysState->ClearBit(i);
- }
- }
- //for getting a key
- bool GetKey(int key){ return (*keys)[key]; }
- private:
- //bitset arrays via pointers (we have to do it this way)
- BitSet * keys;
- BitSet * keysState;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement