Input.h

00001 #ifndef _INPUT_H_
00002 #define _INPUT_H_
00003 
00004 #include <stdio.h>
00005 #include "renderer.h"
00006 #include "Defines.h"
00007 #include <dinput.h>
00008 
00009 #pragma comment (lib, "dinput8.lib")
00010 
00011 BOOL CALLBACK DIEnumDevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
00012 
00013 namespace zak {
00014 
00015 #define ZAK_MAX_INPUT_DEVICE                                            10
00016 
00017 #define ZAK_INPUT_STATE_NOTHING                                         0
00018 #define ZAK_INPUT_STATE_REACQUIRE                                       1
00019 #define ZAK_INPUT_STATE_UNACQUIRE                                       2
00020 
00021 #define ZAK_INPUT_POS_X                             0
00022 #define ZAK_INPUT_POS_Y                             1
00023 #define ZAK_INPUT_POS_Z                             2
00024 #define ZAK_INPUT_MOUSE_POS_X                       0
00025 #define ZAK_INPUT_MOUSE_POS_Y                       1
00026 #define ZAK_INPUT_MOUSE_POS_Z                       2
00027 #define ZAK_INPUT_MOUSE_BTN_1                       0
00028 #define ZAK_INPUT_MOUSE_BTN_2                       1
00029 #define ZAK_INPUT_MOUSE_BTN_3                       2
00030 
00031 #define ZAK_INPUT_KEY_NONE                                                      0
00032 #define ZAK_INPUT_KEY_DOWN                                                      1
00033 #define ZAK_INPUT_KEY_UP                                                        2
00034 #define ZAK_INPUT_KEY_PRESSED                                           3
00035 
00036 #define KeyUp(n)                                                        (g_input._KeyEvent[n] == ZAK_INPUT_KEY_UP)
00037 #define KeyDown(n)                                                      (g_input._KeyEvent[n] == ZAK_INPUT_KEY_DOWN)
00038 #define KeyPressed(n)                                           (g_input._KeyBuffer[n] & 0x80)
00039 #define KeyEvent(n)                                                     (g_input._KeyEvent[n])
00040 #define MousePress(n)                                           (g_input._MouseData.Button[n] & 0x80)
00041 #define MouseClick(n)                       (g_input._MouseData.ButtonClick[n])
00042 #define MouseScreenPos(n)                   (g_input._MouseData.ScreenPosition[n])
00043 #define MouseScreenPosf(n)                  (float)(g_input._MouseData.ScreenPosition[n])
00044 #define MouseAbsPos(n)                      (g_input._MouseData.AbsPosition[n])
00045 #define MouseAbsPosf(n)                     (float)(g_input._MouseData.AbsPosition[n])
00046 #define MouseRelPos(n)                      (g_input._MouseData.RelPosition[n])
00047 #define MouseRelPosf(n)                     (float)(g_input._MouseData.RelPosition[n])
00048 #define MouseWorldPos(n)                    (g_input._MouseData.TtlPosition[n])
00049 #define MouseWorldPosf(n)                   (float)(g_input._MouseData.TtlPosition[n])
00050 #define JoystickPos(devNum, axis)                       (g_input._joyData[devNum].Pos[axis])
00051 #define JoystickRot(devNum, axis)                       (g_input._joyData[devNum].Rot[axis])
00052 #define JoystickPosf(devNum, axis)                      (float)(g_input._joyData[devNum].Pos[axis])
00053 #define JoystickRotf(devNum, axis)                      (float)(g_input._joyData[devNum].Rot[axis])
00054 #define JoystickButtons(devNum, button)         (g_input._joyData[devNum].Buttons[button] > 0)
00055 #define JoystickCount()                                         (g_input._deviceCount)
00056 
00057 struct InputJoystickData {
00058         long Pos[3];
00059         long Rot[3];
00060         BYTE Buttons[32];
00061 };
00062 
00063 struct InputMouseData {
00064         long TtlPosition[3];
00065         long AbsPosition[3];
00066         long ScreenPosition[3];
00067         long RelPosition[3];
00068         BYTE Button[3];
00069     bool ButtonClick[3];
00070 };
00071 
00179 class ZAKENGINE_API Input {
00180 public:
00181         BYTE                            _KeyBuffer[256];       // keyboard buffer for received data
00182         BYTE                            _KeyPrevBuffer[256];   // keyboard buffer for received data
00183         BYTE                            _KeyEvent[256];        // keyboard buffer for received data
00184         InputMouseData          _MouseData;            // Mouse buffer for received data
00185         DIMOUSESTATE            MouseTaken;
00186         DIJOYSTATE                              JoyTaken[ZAK_MAX_INPUT_DEVICE];
00187         InputJoystickData               _joyData[ZAK_MAX_INPUT_DEVICE];
00188 
00189         // Initialize DirecInput
00190         int  InitializeDirectInput(HINSTANCE hInstance, HWND hWnd);
00191 
00192         // End DirectInput
00193         void EndDirectInput(void);
00194 
00195         // Acquire Keyboard and mouse
00196         void Acquire(void);
00197 
00198         // Clean the input buffer
00199         void CleanBuffer(void);
00200 
00201         // Reacquire the input
00202         void Reacquire(void);
00203 
00204         // Unacquire the input
00205         void Unacquire(void);
00206 
00207         // Get the key events
00208         void GetKeyEvent(void);
00209 
00210         // Set the current input position
00211         void SetPosition(long x, long y, long z);
00212 
00213         // Clean the events
00214         void EventClean(void);
00215 
00216         bool ToggleMouseExclusive(bool mouseExclusive);
00217         bool IsMouseExclusive() { return _mouseExclusive; }
00218 
00219         Input();
00220         ~Input();
00221 
00222         static int                      _deviceCount;
00223         static GUID                     _guid[ZAK_MAX_INPUT_DEVICE];
00224 
00225 private:
00226         LPDIRECTINPUT8          _lpObjectOne;           // Direct Input ( Add )
00227         LPDIRECTINPUT8          _lpObjectTwo;           // Direct Input ( Add )
00228         LPDIRECTINPUT8          _lpObjectThree;         // Direct Input ( Add )
00229         LPDIRECTINPUTDEVICE8    _lpKeyboard;            // Keyboard Device ( Add )
00230         LPDIRECTINPUTDEVICE8    _lpMouse;                       // Mouse Device (Add)
00231         LPDIRECTINPUTDEVICE8    _lpJoystick[ZAK_MAX_INPUT_DEVICE];      // Joystick Device (Add)
00232         bool                    _bButtonState[3];
00233         bool                                    _bMouseLastFrameState[3];
00234         bool                                    _mouseExclusive;
00235 
00236 };
00237 
00238 extern ZAKENGINE_API Input g_input;
00239 
00240 }
00241 
00242 #endif //_INPUT_H_
00243 

Generado el Tue May 29 14:46:14 2007 para Zak Engine v1.1.0 por  doxygen 1.5.1-p1