Najpierw klawiatura:
class CKeyboard
{
private:
bool m_Key[512]; // true - wciśnięty, false - nie
public:
CKeyboard()
{
Clear();
}
~CKeyboard()
{
Clear();
}
void Update(int Key, bool Action = true)
{
m_Key[Key] = Action;
}
void Clear()
{
memset(m_Key,0,512*sizeof(bool));
}
bool IsKeyDown(int Key)
{
return m_Key[Key];
}
bool IsKeyUp(int Key)
{
return !(m_Key[Key]);
}
bool operator [] (int Key)
{
return m_Key[Key];
}
};
Teraz klasa myszy:
class CMouse
{
private:
struct{
int x;
int y;
int z;
int dx;
int dy;
int dz;
unsigned int button;
} m_MouseState;
GraphicsCore::ImagePtr m_ImageCursor;
bool m_IsCursorVisible;
protected:
public:
enum EButton{NONE,LEFT, RIGHT, MIDDLE};
CMouse()
{
Clear();
m_IsCursorVisible = true;
}
~CMouse()
{
Clear();
m_IsCursorVisible = true;
al_show_mouse_cursor(al_get_current_display());
}
void Clear()
{
memset(&m_MouseState,0,sizeof(m_MouseState));
}
void Update(ALLEGRO_EVENT& Event)
{
switch (Event.type)
{
case ALLEGRO_EVENT_MOUSE_AXES:
m_MouseState.x = Event.mouse.x;
m_MouseState.y = Event.mouse.y;
m_MouseState.z = Event.mouse.z;
m_MouseState.dx = Event.mouse.dx;
m_MouseState.dy = Event.mouse.dy;
m_MouseState.dz = Event.mouse.dz;
break;
case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
m_MouseState.x = Event.mouse.x;
m_MouseState.y = Event.mouse.y;
m_MouseState.z = Event.mouse.z;
m_MouseState.button = Event.mouse.button;
break;
case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
m_MouseState.x = Event.mouse.x;
m_MouseState.y = Event.mouse.y;
m_MouseState.z = Event.mouse.z;
m_MouseState.button = 0;
}
}
unsigned int GetButton()
{
return m_MouseState.button;
}
void GetXY(int* x, int* y)
{
*x = m_MouseState.x;
*y = m_MouseState.y;
}
void GetZ(int* z)
{
*z = m_MouseState.z;
}
void GetDXDY(int* dx, int* dy)
{
*dx = m_MouseState.dx;
*dy = m_MouseState.dy;
}
void GetDZ(int* dz)
{
*dz = m_MouseState.dz;
}
void VisibleSystemCursor(bool Visible)
{
if (Visible == true)
al_show_mouse_cursor(al_get_current_display());
else al_hide_mouse_cursor(al_get_current_display());
m_IsCursorVisible = Visible;
}
void DrawCursor()
{
m_ImageCursor->Draw(m_MouseState.x,m_MouseState.y);
}
void SetCursorImage(GraphicsCore::ImagePtr& CursorImage)
{
m_ImageCursor = CursorImage;
}
};
W przyszłości będzie oczywiście gamepad oraz obsługa w stylu PS Move(z zastosowaniem kamerki internetowej)
Takie pytanko po co jest oś z ?
OdpowiedzUsuńOś "Z" to odchylenie kółka myszki
OdpowiedzUsuń