#1. Engine System
+ WinMain - EngineSystem
+ EngineCore
+ EngineError
+ MainNode
#2. FrameWork
+ Grahpics
+ Image - SpriteData
+ Layer
+ Input (현재 글)
+ Game
+ Manager
+ Game Interface
+ Utility
#3. Testing Module
+ 2D Image Test
+ 2D Animation Test
+ Game UI Test
-----------------------------------------------------------------------
이번글에서 설명 할 내용은 Input Class 입니다.
Input 클래스는 엔진에서의 모든 키입력 처리에 대한 것을 담당하는 클래스입니다.
일반적인 키보드 입력, 마우스 입력 부터 XBox Pad의 입력에 대한 처리를 담당합니다.
먼저 헤더에서의 주요 내용들을 살펴보도록 하겠습니다.
헤더에서 다룰 내용 목록은 다음과 같습니다.
1. 키 입력을 위한 주요 변수들
2. Input 클래스의 주요 함수 목록
본 글에서는 자세한 게임패드 입력처리에 대한 설명은 하지 않습니다.
게임패드 입력처리에 대한 자세한 내용은 다음에 기회가 되면 다루도록 하겠습니다.
(#include <XInput>제목으로 별도의 포스팅을 통해 다룰 예정입니다.)
1. 먼저 Input.h 의 상단에 위치한 내용들을 보도록 하겠습니다.
#pragma once | |
#ifndef _INPUT_H // Prevent multiple definitions if this | |
#define _INPUT_H // file is included in more than one place | |
#define WIN32_LEAN_AND_MEAN | |
class Input; | |
#include <windows.h> | |
#include <WindowsX.h> | |
#include <string> | |
#include <XInput.h> | |
#include "constants.h" | |
#include "gameError.h" | |
// for high-definition mouse | |
#ifndef HID_USAGE_PAGE_GENERIC | |
#define HID_USAGE_PAGE_GENERIC ((USHORT) 0x01) | |
#endif | |
#ifndef HID_USAGE_GENERIC_MOUSE | |
#define HID_USAGE_GENERIC_MOUSE ((USHORT) 0x02) | |
#endif | |
//-------------------------- | |
namespace inputNS | |
{ | |
const int KEYS_ARRAY_LEN = 256; // size of key arrays | |
// what values for clear(), bit flag | |
const UCHAR KEYS_DOWN = 1; | |
const UCHAR KEYS_PRESSED = 2; | |
const UCHAR MOUSE = 4; | |
const UCHAR TEXT_IN = 8; | |
const UCHAR KEYS_MOUSE_TEXT = KEYS_DOWN + KEYS_PRESSED + MOUSE + TEXT_IN; | |
} | |
const DWORD GAMEPAD_THUMBSTICK_DEADZONE = (DWORD)(0.20f * 0X7FFF); // default to 20% of range as deadzone | |
const DWORD GAMEPAD_TRIGGER_DEADZONE = 30; // trigger range 0-255 | |
const DWORD MAX_CONTROLLERS = 4; // Maximum number of controllers supported by XInput | |
// Bit corresponding to gamepad button in state.Gamepad.wButtons | |
const DWORD GAMEPAD_DPAD_UP = 0x0001; | |
const DWORD GAMEPAD_DPAD_DOWN = 0x0002; | |
const DWORD GAMEPAD_DPAD_LEFT = 0x0004; | |
const DWORD GAMEPAD_DPAD_RIGHT = 0x0008; | |
const DWORD GAMEPAD_START_BUTTON = 0x0010; | |
const DWORD GAMEPAD_BACK_BUTTON = 0x0020; | |
const DWORD GAMEPAD_LEFT_THUMB = 0x0040; | |
const DWORD GAMEPAD_RIGHT_THUMB = 0x0080; | |
const DWORD GAMEPAD_LEFT_SHOULDER = 0x0100; | |
const DWORD GAMEPAD_RIGHT_SHOULDER = 0x0200; | |
const DWORD GAMEPAD_A = 0x1000; | |
const DWORD GAMEPAD_B = 0x2000; | |
const DWORD GAMEPAD_X = 0x4000; | |
const DWORD GAMEPAD_Y = 0x8000; | |
struct ControllerState | |
{ | |
XINPUT_STATE state; | |
XINPUT_VIBRATION vibration; | |
float vibrateTimeLeft; // mSec | |
float vibrateTimeRight; // mSec | |
bool connected; | |
}; |
(1) namespace inputNS를 보시면 사용 될 모든 키들에 대한 값들을 위해 KEYS_ARRAY_LEN이 있습니다. 사용 할 키들의 사이즈 크기라 보시면 됩니다. (즉, 256 개의 키를 지원)
(2) 다음 키다운 이나 눌러졌다를 판단할 용도의 KEYS_DOWN / KEYS_PRESSED 플래그
(3) 마우스에 대한 플래그 값 MOUSE와 텍스트 입력에 대한 플래그 값 TEXT_IN 플래그
(4) 모든 키들을 Clear시킬 용도로 각 플래그 값들을 합친 KEYS_MOUSE_TEXT 플래그
그리고 그 아래에는 게임 패드를 사용하는 것들에 대한 키 플래그값들이 나열되어 있습니다.
게임패드에 대한 입력을 처리할 목적으로 선언되어 있으나 패드를 지원하는 게임을 만들 게 아니라면 딱히 사용할 일은 없습니다.
게임 패드에 대한 선언은 본 글에서는 생략하고 추후 XInput에 대한 것을 다룰 때 다시 설명하도록 하겠습니다.
다음, Input 클래스에서 키 입력 처리를 위해 사용 되어지는 주요 변수들 입니다.
class Input | |
{ | |
private: | |
bool keysDown[inputNS::KEYS_ARRAY_LEN]; // true if specified key is down | |
bool keysPressed[inputNS::KEYS_ARRAY_LEN]; // true if specified key was pressed | |
bool mouseWheelRoll; // true if mouseWheel rolling | |
bool mouseWheelRollUp; // true if mouseWheel zDelta > 0 | |
bool mouseWheelRollDown; // true if mouseWheel zDelta < 0 | |
std::string textIn; // user entered text | |
char charIn; // last character entered | |
bool newLine; // true on start of new line | |
int mouseX, mouseY; // mouse screen coordinates | |
int mouseRawX, mouseRawY; // high-definition mouse data | |
RAWINPUTDEVICE Rid[1]; // for high-definition mouse | |
bool mouseCaptured; // true if mouse captured | |
bool mouseLButton; // true if left mouse button down | |
bool mouseMButton; // true if middle mouse button down | |
bool mouseRButton; // true if right mouse button down | |
bool mouseX1Button; // true if X1 mouse button down | |
bool mouseX2Button; // true if X2 mouse button down | |
ControllerState controllers[MAX_CONTROLLERS]; // state of controllers | |
} |
(private: 접근한정자 안에 선언 된 주요 변수들을 먼저 코드로 올렸습니다. 실제 전체 코드는 public: 영역도 포함하여 최 하단에 업로드 되어있습니다.)
(1) keysDown[KEYS_ARRAY_LEN] / keysPressed[KEYS_ARRAY_LEN] (키 입력 여부를 판단할 목적의 bool 변수)
(2) bool mouseWheelRoll / Rollup/ RollDown (마우스 휠을 굴렸을 때의 이벤트 판단목적)
(3) std::string textIn (텍스트 입력값들을 저장할 목적)
(4) char charIn (텍스트 입력 시 한 글자 값들을 저장)
(5) bool newLine (줄바꿈 여부를 판단할 목적)
(6) int mouseX / Y (현재 마우스 커서의 x,y 위치)
(7) int mouseRawX / Y (현재 마우스커서의 고감도 x, y 위치)
(8) RAWINPUTDEVICE Rid[1] (고감도 마우스 지원 여부 판단 목적의 변수)
(9) bool mouseCaptured (마우스 위치 캡쳐 목적의 플래그 값)
(10) bool mouseL/M/RButton (마우스 좌/우/중앙 키 입력 플래그 값)
(11) bool mouseX1/X2Button (마우스 특수버튼 1,2 키 플래그 값)
(12) ControllerState controllers[MAX_CONTROLLERS] (게임 패드 이용 시 사용하는 플래그 값)
들로 주요 변수들이 이루어져 있습니다.
일반적인 게임 키처리에 대한 변수들과 동일한 구조 형태라 아마 이름만봐도 아 저변수가 무슨용도구나 하고 이해하시는데는 불편함이 없을거라 생각합니다.
그럼 마지막으로 각 키입력에 대한 함수들의 구조를 보겠습니다.
2. 주요 함수 목록
class Input | |
{ | |
public: | |
// Constructor | |
Input(); | |
// Destructor | |
virtual ~Input(); | |
// Initialize mouse and controller input. | |
// Throws GameError | |
// Pre: hwnd = window handle | |
// capture = true to capture mouse. | |
void initialize(HWND hwnd, bool capture); | |
// Save key down state | |
void keyDown(WPARAM); | |
// Save key up state | |
void keyUp(WPARAM); | |
// Save the char just entered in textIn string | |
void keyIn(WPARAM); | |
// Returns true if the specified VIRTUAL KEY is down, otherwise false. | |
bool isKeyDown(UCHAR vkey) const; | |
// Return true if the specified VIRTUAL KEY has been pressed in the most recent frame. | |
// Key presses are erased at the end of each frame. | |
bool wasKeyPressed(UCHAR vkey) const; | |
// Return true if any key was pressed in the most recent frame. | |
// Key presses are erased at the end of each frame. | |
bool anyKeyPressed() const; | |
// Clear the specified key press | |
void clearKeyPress(UCHAR vkey); | |
void mouseWheelIn(int zDelta); | |
bool isMouseWheelUp(); | |
bool isMouseWheelDown(); | |
// Clear specified input buffers where what is any combination of | |
// KEYS_DOWN, KEYS_PRESSED, MOUSE, TEXT_IN or KEYS_MOUSE_TEXT. | |
// Use OR '|' operator to combine parmeters. | |
void clear(UCHAR what); | |
// Clears key, mouse and text input data | |
void clearAll() {clear(inputNS::KEYS_MOUSE_TEXT);} | |
// Clear text input buffer | |
void clearTextIn() {textIn.clear();} | |
// Return text input as a string | |
std::string getTextIn() {return textIn;} | |
// Return last character entered | |
char getCharIn() {return charIn;} | |
// Reads mouse screen position into mouseX, mouseY | |
void mouseIn(LPARAM); | |
// Reads raw mouse data into mouseRawX, mouseRawY | |
// This routine is compatible with a high-definition mouse | |
void mouseRawIn(LPARAM); | |
// Save state of mouse button | |
void setMouseLButton(bool b) { mouseLButton = b; } | |
// Save state of mouse button | |
void setMouseMButton(bool b) { mouseMButton = b; } | |
// Save state of mouse button | |
void setMouseRButton(bool b) { mouseRButton = b; } | |
// Save state of mouse button | |
void setMouseXButton(WPARAM wParam) {mouseX1Button = (wParam & MK_XBUTTON1) ? true:false; | |
mouseX2Button = (wParam & MK_XBUTTON2) ? true:false;} | |
// Return mouse X position | |
int getMouseX() const { return mouseX; } | |
// Return mouse Y position | |
int getMouseY() const { return mouseY; } | |
// Return raw mouse X movement. Left is <0, Right is >0 | |
// Compatible with high-definition mouse. | |
int getMouseRawX() const { return mouseRawX; } | |
// Return raw mouse Y movement. Up is <0, Down is >0 | |
// Compatible with high-definition mouse. | |
int getMouseRawY() const { return mouseRawY; } | |
// Return state of left mouse button. | |
bool getMouseLButton() const { return mouseLButton; } | |
// Return state of middle mouse button. | |
bool getMouseMButton() const { return mouseMButton; } | |
// Return state of right mouse button. | |
bool getMouseRButton() const { return mouseRButton; } | |
// Return state of X1 mouse button. | |
bool getMouseX1Button() const { return mouseX1Button; } | |
// Return state of X2 mouse button. | |
bool getMouseX2Button() const { return mouseX2Button; } | |
} |
지금 위에 언급된 함수 외에도 게임패드관련 함수가 상당히 많이 있습니다만, 분량이 너무 길어지는 관계로 위 코드에는 올리지 않았습니다. 최하단 전체 코드에는 게임패드 관련 함수도 같이 들어있습니다.
헤더에서 함수가 뭐 이렇게 많아!? 하고 겁먹으실 필요는 없습니다.
어짜피 엔진을 쓰면서 사용하게 될 함수는 8~90% isKeyDown / wasKeyPressed 밖에 없으니까요. 게임패드 관련 함수를 뺏음에도 상당히 부담이 가신다면 아래와 같이 간단히 이런 게 있다 라고만 보시면 될 것 같습니다.
(1) 생성자 / 소멸자
(2) KeyDown / Up / In (키입력에 대한 판단 함수)
(3) isKeyDown (키가 눌러졌냐~? 라고 물어보는 함수)
(4) wasKeyPressed (최근 프레임 1~2사이에 키가 눌려졌냐~? 라고 물어보는 함수)
(5) anyKeyPressed (아무키나 눌러졌었냐~? 라고 물어보는 함수)
(6) clearKeyPressed (눌려진적이 있는 키를 다시 false로 초기화 하는 함수)
(7) mouseWheel In / Up / Down (마우스 휠이 굴려졌을때 위로굴렸냐 아래로 굴렸냐 체크하는 함수)
(8) clear / clearAll / clearTextIn 각각 키 입력에 대한 Clear 함수
(9) getTextIn / getCharIn (문장 / 한 글자 입력 시 내용 받아오는 함수)
(10) set/ get Mouse L/M/R/X Button (마우스 키 입력 또는 받아오는 함수)
(11) getMouseX / Y , getMouseRawX /Y (마우스 좌표 받아오는 함수)
키 입력에 대한 처리를 하는 함수들은 위와 같이 11가지가 있습니다.
결과적으로는 모두 다 사용하는 함수들이기 때문에 대충 어떤목적에 사용한다 라는 것만 알고 넘어간 뒤 엔진을 사용하면서 쓰다보면 자연스레 본인이 쓰고 있는 모습을 볼 수 있습니다.
자세한 각 함수들에 구현 내용은 .cpp로 이어서 적도록 하겠습니다.
아래는 전체 헤더파일 내용입니다.
#pragma once | |
#ifndef _INPUT_H // Prevent multiple definitions if this | |
#define _INPUT_H // file is included in more than one place | |
#define WIN32_LEAN_AND_MEAN | |
class Input; | |
#include <windows.h> | |
#include <WindowsX.h> | |
#include <string> | |
#include <XInput.h> | |
#include "constants.h" | |
#include "gameError.h" | |
// for high-definition mouse | |
#ifndef HID_USAGE_PAGE_GENERIC | |
#define HID_USAGE_PAGE_GENERIC ((USHORT) 0x01) | |
#endif | |
#ifndef HID_USAGE_GENERIC_MOUSE | |
#define HID_USAGE_GENERIC_MOUSE ((USHORT) 0x02) | |
#endif | |
//-------------------------- | |
namespace inputNS | |
{ | |
const int KEYS_ARRAY_LEN = 256; // size of key arrays | |
// what values for clear(), bit flag | |
const UCHAR KEYS_DOWN = 1; | |
const UCHAR KEYS_PRESSED = 2; | |
const UCHAR MOUSE = 4; | |
const UCHAR TEXT_IN = 8; | |
const UCHAR KEYS_MOUSE_TEXT = KEYS_DOWN + KEYS_PRESSED + MOUSE + TEXT_IN; | |
} | |
const DWORD GAMEPAD_THUMBSTICK_DEADZONE = (DWORD)(0.20f * 0X7FFF); // default to 20% of range as deadzone | |
const DWORD GAMEPAD_TRIGGER_DEADZONE = 30; // trigger range 0-255 | |
const DWORD MAX_CONTROLLERS = 4; // Maximum number of controllers supported by XInput | |
// Bit corresponding to gamepad button in state.Gamepad.wButtons | |
const DWORD GAMEPAD_DPAD_UP = 0x0001; | |
const DWORD GAMEPAD_DPAD_DOWN = 0x0002; | |
const DWORD GAMEPAD_DPAD_LEFT = 0x0004; | |
const DWORD GAMEPAD_DPAD_RIGHT = 0x0008; | |
const DWORD GAMEPAD_START_BUTTON = 0x0010; | |
const DWORD GAMEPAD_BACK_BUTTON = 0x0020; | |
const DWORD GAMEPAD_LEFT_THUMB = 0x0040; | |
const DWORD GAMEPAD_RIGHT_THUMB = 0x0080; | |
const DWORD GAMEPAD_LEFT_SHOULDER = 0x0100; | |
const DWORD GAMEPAD_RIGHT_SHOULDER = 0x0200; | |
const DWORD GAMEPAD_A = 0x1000; | |
const DWORD GAMEPAD_B = 0x2000; | |
const DWORD GAMEPAD_X = 0x4000; | |
const DWORD GAMEPAD_Y = 0x8000; | |
struct ControllerState | |
{ | |
XINPUT_STATE state; | |
XINPUT_VIBRATION vibration; | |
float vibrateTimeLeft; // mSec | |
float vibrateTimeRight; // mSec | |
bool connected; | |
}; | |
class Input | |
{ | |
private: | |
bool keysDown[inputNS::KEYS_ARRAY_LEN]; // true if specified key is down | |
bool keysPressed[inputNS::KEYS_ARRAY_LEN]; // true if specified key was pressed | |
bool mouseWheelRoll; // true if mouseWheel rolling | |
bool mouseWheelRollUp; // true if mouseWheel zDelta > 0 | |
bool mouseWheelRollDown; // true if mouseWheel zDelta < 0 | |
std::string textIn; // user entered text | |
char charIn; // last character entered | |
bool newLine; // true on start of new line | |
int mouseX, mouseY; // mouse screen coordinates | |
int mouseRawX, mouseRawY; // high-definition mouse data | |
RAWINPUTDEVICE Rid[1]; // for high-definition mouse | |
bool mouseCaptured; // true if mouse captured | |
bool mouseLButton; // true if left mouse button down | |
bool mouseMButton; // true if middle mouse button down | |
bool mouseRButton; // true if right mouse button down | |
bool mouseX1Button; // true if X1 mouse button down | |
bool mouseX2Button; // true if X2 mouse button down | |
ControllerState controllers[MAX_CONTROLLERS]; // state of controllers | |
public: | |
// Constructor | |
Input(); | |
// Destructor | |
virtual ~Input(); | |
// Initialize mouse and controller input. | |
// Throws GameError | |
// Pre: hwnd = window handle | |
// capture = true to capture mouse. | |
void initialize(HWND hwnd, bool capture); | |
// Save key down state | |
void keyDown(WPARAM); | |
// Save key up state | |
void keyUp(WPARAM); | |
// Save the char just entered in textIn string | |
void keyIn(WPARAM); | |
// Returns true if the specified VIRTUAL KEY is down, otherwise false. | |
bool isKeyDown(UCHAR vkey) const; | |
// Return true if the specified VIRTUAL KEY has been pressed in the most recent frame. | |
// Key presses are erased at the end of each frame. | |
bool wasKeyPressed(UCHAR vkey) const; | |
// Return true if any key was pressed in the most recent frame. | |
// Key presses are erased at the end of each frame. | |
bool anyKeyPressed() const; | |
// Clear the specified key press | |
void clearKeyPress(UCHAR vkey); | |
void mouseWheelIn(int zDelta); | |
bool isMouseWheelUp(); | |
bool isMouseWheelDown(); | |
// Clear specified input buffers where what is any combination of | |
// KEYS_DOWN, KEYS_PRESSED, MOUSE, TEXT_IN or KEYS_MOUSE_TEXT. | |
// Use OR '|' operator to combine parmeters. | |
void clear(UCHAR what); | |
// Clears key, mouse and text input data | |
void clearAll() {clear(inputNS::KEYS_MOUSE_TEXT);} | |
// Clear text input buffer | |
void clearTextIn() {textIn.clear();} | |
// Return text input as a string | |
std::string getTextIn() {return textIn;} | |
// Return last character entered | |
char getCharIn() {return charIn;} | |
// Reads mouse screen position into mouseX, mouseY | |
void mouseIn(LPARAM); | |
// Reads raw mouse data into mouseRawX, mouseRawY | |
// This routine is compatible with a high-definition mouse | |
void mouseRawIn(LPARAM); | |
// Save state of mouse button | |
void setMouseLButton(bool b) { mouseLButton = b; } | |
// Save state of mouse button | |
void setMouseMButton(bool b) { mouseMButton = b; } | |
// Save state of mouse button | |
void setMouseRButton(bool b) { mouseRButton = b; } | |
// Save state of mouse button | |
void setMouseXButton(WPARAM wParam) {mouseX1Button = (wParam & MK_XBUTTON1) ? true:false; | |
mouseX2Button = (wParam & MK_XBUTTON2) ? true:false;} | |
// Return mouse X position | |
int getMouseX() const { return mouseX; } | |
// Return mouse Y position | |
int getMouseY() const { return mouseY; } | |
// Return raw mouse X movement. Left is <0, Right is >0 | |
// Compatible with high-definition mouse. | |
int getMouseRawX() const { return mouseRawX; } | |
// Return raw mouse Y movement. Up is <0, Down is >0 | |
// Compatible with high-definition mouse. | |
int getMouseRawY() const { return mouseRawY; } | |
// Return state of left mouse button. | |
bool getMouseLButton() const { return mouseLButton; } | |
// Return state of middle mouse button. | |
bool getMouseMButton() const { return mouseMButton; } | |
// Return state of right mouse button. | |
bool getMouseRButton() const { return mouseRButton; } | |
// Return state of X1 mouse button. | |
bool getMouseX1Button() const { return mouseX1Button; } | |
// Return state of X2 mouse button. | |
bool getMouseX2Button() const { return mouseX2Button; } | |
// Update connection status of game controllers. | |
void checkControllers(); | |
// Save input from connected game controllers. | |
void readControllers(); | |
// Return state of specified game controller. | |
const ControllerState* getControllerState(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return &controllers[n]; | |
} | |
// Return state of controller n buttons. | |
const WORD getGamepadButtons(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return controllers[n].state.Gamepad.wButtons; | |
} | |
// Return state of controller n D-pad Up | |
bool getGamepadDPadUp(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return ((controllers[n].state.Gamepad.wButtons&GAMEPAD_DPAD_UP) != 0); | |
} | |
// Return state of controller n D-pad Down. | |
bool getGamepadDPadDown(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return ((controllers[n].state.Gamepad.wButtons&GAMEPAD_DPAD_DOWN) != 0); | |
} | |
// Return state of controller n D-pad Left. | |
bool getGamepadDPadLeft(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return ((controllers[n].state.Gamepad.wButtons&GAMEPAD_DPAD_LEFT) != 0); | |
} | |
// Return state of controller n D-pad Right. | |
bool getGamepadDPadRight(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return bool((controllers[n].state.Gamepad.wButtons&GAMEPAD_DPAD_RIGHT) != 0); | |
} | |
// Return state of controller n Start button. | |
bool getGamepadStart(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return bool((controllers[n].state.Gamepad.wButtons&GAMEPAD_START_BUTTON) != 0); | |
} | |
// Return state of controller n Back button. | |
bool getGamepadBack(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return bool((controllers[n].state.Gamepad.wButtons&GAMEPAD_BACK_BUTTON) != 0); | |
} | |
// Return state of controller n Left Thumb button. | |
bool getGamepadLeftThumb(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return bool((controllers[n].state.Gamepad.wButtons&GAMEPAD_LEFT_THUMB) != 0); | |
} | |
// Return state of controller n Right Thumb button. | |
bool getGamepadRightThumb(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return bool((controllers[n].state.Gamepad.wButtons&GAMEPAD_RIGHT_THUMB) != 0); | |
} | |
// Return state of controller n Left Shoulder button. | |
bool getGamepadLeftShoulder(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return bool((controllers[n].state.Gamepad.wButtons&GAMEPAD_LEFT_SHOULDER) != 0); | |
} | |
// Return state of controller n Right Shoulder button. | |
bool getGamepadRightShoulder(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return bool((controllers[n].state.Gamepad.wButtons&GAMEPAD_RIGHT_SHOULDER) != 0); | |
} | |
// Return state of controller n A button. | |
bool getGamepadA(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return bool((controllers[n].state.Gamepad.wButtons&GAMEPAD_A) != 0); | |
} | |
// Return state of controller n B button. | |
bool getGamepadB(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return bool((controllers[n].state.Gamepad.wButtons&GAMEPAD_B) != 0); | |
} | |
// Return state of controller n X button. | |
bool getGamepadX(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return bool((controllers[n].state.Gamepad.wButtons&GAMEPAD_X) != 0); | |
} | |
// Return state of controller n Y button. | |
bool getGamepadY(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return bool((controllers[n].state.Gamepad.wButtons&GAMEPAD_Y) != 0); | |
} | |
// Return value of controller n Left Trigger. | |
BYTE getGamepadLeftTrigger(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return (controllers[n].state.Gamepad.bLeftTrigger); | |
} | |
// Return value of controller n Right Trigger. | |
BYTE getGamepadRightTrigger(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return (controllers[n].state.Gamepad.bRightTrigger); | |
} | |
// Return value of controller n Left Thumbstick X. | |
SHORT getGamepadThumbLX(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return (controllers[n].state.Gamepad.sThumbLX); | |
} | |
// Return value of controller n Left Thumbstick Y. | |
SHORT getGamepadThumbLY(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return (controllers[n].state.Gamepad.sThumbLY); | |
} | |
// Return value of controller n Right Thumbstick X. | |
SHORT getGamepadThumbRX(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return (controllers[n].state.Gamepad.sThumbRX); | |
} | |
// Return value of controller n Right Thumbstick Y. | |
SHORT getGamepadThumbRY(UINT n) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
return (controllers[n].state.Gamepad.sThumbRY); | |
} | |
// Vibrate controller n left motor. | |
// Left is low frequency vibration. | |
// speed 0=off, 65536=100 percent | |
// sec is time to vibrate in seconds | |
void gamePadVibrateLeft(UINT n, WORD speed, float sec) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
controllers[n].vibration.wLeftMotorSpeed = speed; | |
controllers[n].vibrateTimeLeft = sec; | |
} | |
// Vibrate controller n right motor. | |
// Right is high frequency vibration. | |
// speed 0=off, 65536=100 percent | |
// sec is time to vibrate in seconds | |
void gamePadVibrateRight(UINT n, WORD speed, float sec) | |
{ | |
if(n > MAX_CONTROLLERS-1) | |
n=MAX_CONTROLLERS-1; | |
controllers[n].vibration.wRightMotorSpeed = speed; | |
controllers[n].vibrateTimeRight = sec; | |
} | |
// Vibrates the connected controllers for the desired time. | |
void vibrateControllers(float frameTime); | |
}; | |
#endif | |
'MyProject > SephyEngine' 카테고리의 다른 글
June_Engine #3_LayerManager Class .cpp (0) | 2017.04.21 |
---|---|
June_Engine #3_LayerManager Class .h (0) | 2017.04.21 |
June_Engine #3_Layer Class (0) | 2017.04.21 |
June_Engine #3_Image Class .cpp (2) (0) | 2017.04.20 |
June_Engine #3_Image Class .cpp (1) (0) | 2017.04.19 |