Advertisement
Paul17041993

KeyState.h

Jul 25th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #ifndef _KEYSTATE_H_
  2. #define _KEYSTATE_H_
  3.  
  4. #include "PaulMath.h"
  5. #include "GL/glfw.h"
  6.  
  7. class KeyState
  8. {
  9. public:
  10.     //constructs and destructs,
  11.     KeyState(void)  { keys = new BitSet(GLFW_KEY_LAST); keysState = new BitSet(GLFW_KEY_LAST); }
  12.     ~KeyState(void) { delete keys; delete keysState; }
  13.  
  14.     //call this every frame
  15.     void Update()
  16.     {
  17.         for(int i = 0; i < GLFW_KEY_LAST; ++i)
  18.         {
  19.             //update keys
  20.             if(!(*keysState)[i] && !(*keys)[i])
  21.             {
  22.                 if(glfwGetKey(i))   keys->SetBit(i);
  23.             }
  24.             else    keys->ClearBit(i);
  25.             //update states
  26.             if(glfwGetKey(i))   keysState->SetBit(i);
  27.             else                keysState->ClearBit(i);
  28.         }
  29.     }
  30.     //for getting a key
  31.     bool GetKey(int key){ return (*keys)[key]; }
  32.  
  33. private:
  34.     //bitset arrays via pointers (we have to do it this way)
  35.     BitSet * keys;
  36.     BitSet * keysState;
  37. };
  38.  
  39. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement