本文整理汇总了C++中SDL_JoystickNumHats函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_JoystickNumHats函数的具体用法?C++ SDL_JoystickNumHats怎么用?C++ SDL_JoystickNumHats使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_JoystickNumHats函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pollJoystick
void pollJoystick(SDL_Joystick *joystick, GamepadBuffer& gamepad)
{
int axes = SDL_JoystickNumAxes(joystick),
hats = SDL_JoystickNumHats(joystick),
buttons = std::min<int>(gpNumPerGamepad - 4, SDL_JoystickNumButtons(joystick));
for (int axis = 0; axis < axes; ++axis) {
Sint16 value = SDL_JoystickGetAxis(joystick, axis);
if (value < -DEAD_ZONE) {
if (axis % 2 == 0)
gamepad[gpLeft - gpRangeBegin] = true;
else
gamepad[gpUp - gpRangeBegin] = true;
}
else if (value > +DEAD_ZONE) {
if (axis % 2 == 0)
gamepad[gpRight - gpRangeBegin] = true;
else
gamepad[gpDown - gpRangeBegin] = true;
}
}
for (int hat = 0; hat < hats; ++hat) {
Uint8 value = SDL_JoystickGetHat(joystick, hat);
if (value & SDL_HAT_LEFT)
gamepad[gpLeft - gpRangeBegin] = true;
if (value & SDL_HAT_RIGHT)
gamepad[gpRight - gpRangeBegin] = true;
if (value & SDL_HAT_UP)
gamepad[gpUp - gpRangeBegin] = true;
if (value & SDL_HAT_DOWN)
gamepad[gpDown - gpRangeBegin] = true;
}
for (int button = 0; button < buttons; ++button) {
if (SDL_JoystickGetButton(joystick, button)) {
gamepad[gpButton0 + button - gpRangeBegin] = true;
}
}
}
示例2: mActive
//
// ISDL12JoystickInputDevice::ISDL12JoystickInputDevice
//
ISDL12JoystickInputDevice::ISDL12JoystickInputDevice(int id) :
mActive(false), mJoystickId(id), mJoystick(NULL),
mNumHats(0), mHatStates(NULL)
{
assert(SDL_WasInit(SDL_INIT_JOYSTICK));
assert(mJoystickId >= 0 && mJoystickId < SDL_NumJoysticks());
mJoystick = SDL_JoystickOpen(mJoystickId);
if (mJoystick == NULL)
return;
mNumHats = SDL_JoystickNumHats(mJoystick);
mHatStates = new int[mNumHats];
// This turns on automatic event polling for joysticks so that the state
// of each button and axis doesn't need to be manually queried each tick. -- Hyper_Eye
SDL_JoystickEventState(SDL_ENABLE);
resume();
}
示例3: defined
//! Activate any joysticks, and generate events for them.
bool CIrrDeviceSDL::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
{
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
joystickInfo.clear();
// we can name up to 256 different joysticks
const int numJoysticks = core::min_(SDL_NumJoysticks(), 256);
Joysticks.reallocate(numJoysticks);
joystickInfo.reallocate(numJoysticks);
int joystick = 0;
for (; joystick<numJoysticks; ++joystick)
{
Joysticks.push_back(SDL_JoystickOpen(joystick));
SJoystickInfo info;
info.Joystick = joystick;
info.Axes = SDL_JoystickNumAxes(Joysticks[joystick]);
info.Buttons = SDL_JoystickNumButtons(Joysticks[joystick]);
info.Name = SDL_JoystickName(joystick);
info.PovHat = (SDL_JoystickNumHats(Joysticks[joystick]) > 0)
? SJoystickInfo::POV_HAT_PRESENT : SJoystickInfo::POV_HAT_ABSENT;
joystickInfo.push_back(info);
}
for(joystick = 0; joystick < (int)joystickInfo.size(); ++joystick)
{
char logString[256];
(void)sprintf(logString, "Found joystick %d, %d axes, %d buttons '%s'",
joystick, joystickInfo[joystick].Axes,
joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str());
os::Printer::log(logString, ELL_INFORMATION);
}
return true;
#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
return false;
}
示例4: vaprint
void ESInputPlatform::Initialize (ESInput::InputDeviceList& aDevices, ESInput::InputDeviceList& aSubDevices, uint32_t aESKeyIndex[14])
{
for(int i = 0; i != SDL_NumJoysticks(); i ++)
{
Joysticks.push_back(SDL_JoystickOpen(i));
aDevices.push_back(ESInput::InputDevice());
for(int j = 0; j != SDL_JoystickNumAxes(Joysticks[i]); j ++)
{
aDevices[i].push_back(ESInput_Button(FetchAxisLow, i, j, 0, vaprint("Joy %d Axis %d Low", i, j)));
aDevices[i].push_back(ESInput_Button(FetchAxisHigh, i, j, 0, vaprint("Joy %d Axis %d High", i, j)));
}
for(int j = 0; j != SDL_JoystickNumHats(Joysticks[i]); j ++)
{
aDevices[i].push_back(ESInput_Button(FetchHat, i, j, SDL_HAT_UP, vaprint("Joy %d Hat %d Up", i, j)));
aDevices[i].push_back(ESInput_Button(FetchHat, i, j, SDL_HAT_DOWN, vaprint("Joy %d Hat %d Down", i, j)));
aDevices[i].push_back(ESInput_Button(FetchHat, i, j, SDL_HAT_LEFT, vaprint("Joy %d Hat %d Left", i, j)));
aDevices[i].push_back(ESInput_Button(FetchHat, i, j, SDL_HAT_RIGHT, vaprint("Joy %d Hat %d Right", i, j)));
}
for(int j = 0; j != SDL_JoystickNumButtons(Joysticks[i]); j ++)
{
aDevices[i].push_back(ESInput_Button(FetchButton, i, j, 0, vaprint("Joy %d Button %d", i, j)));
}
}
//Add a keyboard subdevice
aSubDevices.push_back(ESInput::InputDevice());
int numkeys;
SDL_GetKeyState(&numkeys);
for(int j = 0; j != numkeys; j ++)
{
aSubDevices[0].push_back(ESInput_Button(FetchKey, j, 0, 0, vaprint("KEY %s", SDL_GetKeyName((SDLKey)j))));
}
//Load ES Keys
SDLInputConfig::Load(aESKeyIndex);
}
示例5: joy_get_hat
static PyObject*
joy_get_hat (PyObject* self, PyObject* args)
{
int joy_id = PyJoystick_AsID (self);
SDL_Joystick* joy = joystick_stickdata[joy_id];
int _index, px, py;
Uint32 value;
if (!PyArg_ParseTuple (args, "i", &_index)) {
return NULL;
}
JOYSTICK_INIT_CHECK ();
if (!joy) {
return RAISE (PyExc_SDLError, "Joystick not initialized");
}
if (_index < 0 || _index >= SDL_JoystickNumHats (joy)) {
return RAISE(PyExc_SDLError, "Invalid joystick hat");
}
px = py = 0;
value = SDL_JoystickGetHat (joy, _index);
#ifdef DEBUG
/*printf("SDL_JoystickGetHat value:%d:\n", value);*/
#endif
if (value & SDL_HAT_UP) {
py = 1;
}
else if (value & SDL_HAT_DOWN) {
py = -1;
}
if (value & SDL_HAT_RIGHT) {
px = 1;
}
else if (value & SDL_HAT_LEFT) {
px = -1;
}
return Py_BuildValue ("(ii)", px, py);
}
示例6: IN_Startup
///////////////////////////////////////////////////////////////////////////
//
// IN_Startup() - Starts up the Input Mgr
//
///////////////////////////////////////////////////////////////////////////
void
IN_Startup(void)
{
if (IN_Started)
return;
IN_ClearKeysDown();
if(param_joystickindex >= 0 && param_joystickindex < SDL_NumJoysticks())
{
Joystick = SDL_JoystickOpen(param_joystickindex);
if(Joystick)
{
JoyNumButtons = SDL_JoystickNumButtons(Joystick);
if(JoyNumButtons > 32) JoyNumButtons = 32; // only up to 32 buttons are supported
JoyNumHats = SDL_JoystickNumHats(Joystick);
if(param_joystickhat < -1 || param_joystickhat >= JoyNumHats)
Quit("The joystickhat param must be between 0 and %i!", JoyNumHats - 1);
}
}
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
if(fullscreen || forcegrabmouse)
{
GrabInput = true;
SDL_WM_GrabInput(SDL_GRAB_ON);
}
// I didn't find a way to ask libSDL whether a mouse is present, yet...
#if defined(GP2X)
MousePresent = false;
#elif defined(_arch_dreamcast)
MousePresent = DC_MousePresent();
#else
MousePresent = true;
#endif
IN_Started = true;
}
示例7: InitJoystick
void InitJoystick()
{
int i, buttons, axes, balls, hats;
int joys = SDL_NumJoysticks();
for (i = 0; i < joys; ++i)
{
if (i >= JOY_LAST)
{
perr << "Additional joysticks detected. Cannot initialize more than "
<< JOY_LAST << "." << std::endl;
break;
}
joy[i] = 0;
if(! SDL_JoystickOpened(i))
{
joy[i] = SDL_JoystickOpen(i);
if (joy[i])
{
buttons = SDL_JoystickNumButtons(joy[i]);
axes = SDL_JoystickNumAxes(joy[i]);
balls = SDL_JoystickNumBalls(joy[i]);
hats = SDL_JoystickNumHats(joy[i]);
pout << "Initialized joystick " << i + 1 << "." << std::endl;
pout << "\tButtons: " << buttons << std::endl;
pout << "\tAxes: " << axes << std::endl;
pout << "\tBalls: " << balls << std::endl;
pout << "\tHats: " << hats << std::endl;
}
else
{
perr << "Error while initializing joystick " << i + 1 << "."
<< std::endl;
}
}
}
}
示例8: SDL_JoystickOpen
JoyDevice::JoyDevice (unsigned int device_num)
{
enabled = false;
axis = NULL;
filedes = NULL;
mode = JOY_MODE_INDIVIDUAL;
if ((int) device_num >= SDL_NumJoysticks ())
return;
filedes = SDL_JoystickOpen (device_num);
if (!filedes)
return;
enabled = true;
num_axes = SDL_JoystickNumAxes (filedes);
num_hats = SDL_JoystickNumHats (filedes);
axis = (int *) malloc (sizeof (int) * num_axes);
hat = (int *) malloc (sizeof (int) * num_hats);
calibration = (Calibration *) malloc (sizeof (Calibration) * num_axes);
for (int i = 0; i < num_axes; i++)
{
calibration[i].min = -32767;
calibration[i].max = 32767;
calibration[i].center = 0;
}
printf ("Joystick %d, %s:\n %d axes, %d buttons, %d hats\n",
device_num + 1,
SDL_JoystickName (filedes),
SDL_JoystickNumButtons (filedes),
num_axes,
num_hats);
memset (axis, 0, sizeof (int) * num_axes);
}
示例9: init_joysticks
// initializes SDL joystick system and loads assignments for joysticks found
void init_joysticks( void )
{
if (ignore_joystick)
return;
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK))
{
fprintf(stderr, "warning: failed to initialize joystick system: %s\n", SDL_GetError());
ignore_joystick = true;
return;
}
SDL_JoystickEventState(SDL_IGNORE);
joysticks = SDL_NumJoysticks();
joystick = malloc(joysticks * sizeof(*joystick));
for (int j = 0; j < joysticks; j++)
{
memset(&joystick[j], 0, sizeof(*joystick));
joystick[j].handle = SDL_JoystickOpen(j);
if (joystick[j].handle != NULL)
{
printf("joystick detected: %s ", SDL_JoystickName(j));
printf("(%d axes, %d buttons, %d hats)\n",
SDL_JoystickNumAxes(joystick[j].handle),
SDL_JoystickNumButtons(joystick[j].handle),
SDL_JoystickNumHats(joystick[j].handle));
if (!load_joystick_assignments(j))
reset_joystick_assignments(j);
}
}
if (joysticks == 0)
printf("no joysticks detected\n");
}
示例10: SDL_JoystickOpen
bool Gamepad::otworz(){
this->urzadzenie = SDL_JoystickOpen(0);
if(this->urzadzenie == 0)
return false;
this->iloscPrzyciskow = SDL_JoystickNumButtons(this->urzadzenie);
this->iloscNawigatorow = SDL_JoystickNumHats(this->urzadzenie);
this->iloscDzojstikow = SDL_JoystickNumAxes(this->urzadzenie);
this->przyciskiPolozenie = new bool[this->iloscPrzyciskow];
this->przyciskiWcisniete = new bool[this->iloscPrzyciskow];
this->nawigatoryPolozenie = new int[this->iloscNawigatorow];
this->nawigatoryWcisniete = new int[this->iloscNawigatorow];
this->dzojstiki = new short int[this->iloscDzojstikow];
for(int i = 0; i < this->iloscPrzyciskow; i++)
this->przyciskiPolozenie[i] = this->przyciskiWcisniete[i] = false;
for(int i = 0; i < this->iloscNawigatorow; i++)
this->nawigatoryPolozenie[i] = this->nawigatoryWcisniete[i] = 0;
return true;
}
示例11: init_event
bool init_event(void) {
int i;
// printf("sizeof joymap=%d nb_joy=%d\n",sizeof(JOYMAP),conf.nb_joy);
jmap=calloc(sizeof(JOYMAP),1);
#ifdef WII
conf.nb_joy = 4;
#else
conf.nb_joy = SDL_NumJoysticks();
#endif
if( conf.nb_joy>0) {
if (conf.joy!=NULL) free(conf.joy);
conf.joy=calloc(sizeof(SDL_Joystick*),conf.nb_joy);
SDL_JoystickEventState(SDL_ENABLE);
jmap->jbutton=calloc(conf.nb_joy,sizeof(struct BUT_MAP*));
jmap->jaxe= calloc(conf.nb_joy,sizeof(struct BUT_MAPJAXIS*));
jmap->jhat= calloc(conf.nb_joy,sizeof(struct BUT_MAP*));
/* Open all the available joystick */
for (i=0;i<conf.nb_joy;i++) {
conf.joy[i]=SDL_JoystickOpen(i);
/* printf("joy \"%s\", axe:%d, button:%d\n",
SDL_JoystickName(i),
SDL_JoystickNumAxes(conf.joy[i])+ (SDL_JoystickNumHats(conf.joy[i]) * 2),
SDL_JoystickNumButtons(conf.joy[i]));*/
jmap->jbutton[i]=calloc(SDL_JoystickNumButtons(conf.joy[i]),sizeof(struct BUT_MAP));
jmap->jaxe[i]=calloc(SDL_JoystickNumAxes(conf.joy[i]),sizeof(struct BUT_MAPJAXIS));
jmap->jhat[i]=calloc(SDL_JoystickNumHats(conf.joy[i]),sizeof(struct BUT_MAP));
}
}
create_joymap_from_string(1,CF_STR(cf_get_item_by_name("p1control")));
create_joymap_from_string(2,CF_STR(cf_get_item_by_name("p2control")));
return true;
}
示例12: FindUncenteredHat
static int FindUncenteredHat(int *axis_invert)
{
SDL_Joystick *joystick;
int i, hatval;
joystick = all_joysticks[joystick_index];
for (i = 0; i < SDL_JoystickNumHats(joystick); ++i)
{
hatval = SDL_JoystickGetHat(joystick, i);
switch (hatval)
{
case SDL_HAT_LEFT:
case SDL_HAT_RIGHT:
*axis_invert = hatval != SDL_HAT_LEFT;
return CREATE_HAT_AXIS(i, HAT_AXIS_HORIZONTAL);
case SDL_HAT_UP:
case SDL_HAT_DOWN:
*axis_invert = hatval != SDL_HAT_UP;
return CREATE_HAT_AXIS(i, HAT_AXIS_VERTICAL);
// If the hat is centered, or is not pointing in a
// definite direction, then ignore it. We don't accept
// the hat being pointed to the upper-left for example,
// because it's ambiguous.
case SDL_HAT_CENTERED:
default:
break;
}
}
// None found.
return -1;
}
示例13: joy
//joy : return joystick boolean coordinate
int joy(int index)
{
int ret,tmp;
if (index>=SDL_NumJoysticks())return -1;
SDL_JoystickUpdate();
ret=0;
if (SDLjoy[index] && SDL_JoystickNumAxes(SDLjoy[index])>=2 ){
tmp= SDL_JoystickGetAxis(SDLjoy[index],0);
if (tmp<0)
ret+=1;
if (tmp>0)
ret+=2;
tmp= SDL_JoystickGetAxis(SDLjoy[index],1);
if (tmp<0)
ret+=4;
if (tmp>0)
ret+=8;
}
if (SDLjoy[index] && SDL_JoystickNumHats(SDLjoy[index])>0 ){
ret+=SDL_JoystickGetHat(SDLjoy[index],0);
}
if (autotimer()!=0)return -1;
return ret;
}
示例14: IN_JoyMove
static void IN_JoyMove(void)
{
unsigned int axes = 0;
unsigned int hats = 0;
int total = 0;
int i = 0;
if (!stick)
{
return;
}
SDL_JoystickUpdate();
// update the ball state.
total = SDL_JoystickNumBalls(stick);
if (total > 0)
{
int balldx = 0;
int balldy = 0;
int dx;
int dy;
for (i = 0; i < total; i++)
{
dx = 0;
dy = 0;
SDL_JoystickGetBall(stick, i, &dx, &dy);
balldx += dx;
balldy += dy;
}
if (balldx || balldy)
{
// !!! FIXME: is this good for stick balls, or just mice?
// Scale like the mouse input...
if (abs(balldx) > 1)
{
balldx *= 2;
}
if (abs(balldy) > 1)
{
balldy *= 2;
}
Com_QueueEvent(0, SE_MOUSE, balldx, balldy, 0, NULL);
}
}
// now query the stick buttons...
total = SDL_JoystickNumButtons(stick);
if (total > 0)
{
if (total > ARRAY_LEN(stick_state.buttons))
{
total = ARRAY_LEN(stick_state.buttons);
}
for (i = 0; i < total; i++)
{
qboolean pressed = (SDL_JoystickGetButton(stick, i) != 0);
if (pressed != stick_state.buttons[i])
{
Com_QueueEvent(0, SE_KEY, K_JOY1 + i, pressed, 0, NULL);
stick_state.buttons[i] = pressed;
}
}
}
// look at the hats...
total = SDL_JoystickNumHats(stick);
if (total > 0)
{
if (total > 4)
{
total = 4;
}
for (i = 0; i < total; i++)
{
((Uint8 *)&hats)[i] = SDL_JoystickGetHat(stick, i);
}
}
// update hat state
if (hats != stick_state.oldhats)
{
for (i = 0; i < 4; i++)
{
if (((Uint8 *)&hats)[i] != ((Uint8 *)&stick_state.oldhats)[i])
{
// release event
switch (((Uint8 *)&stick_state.oldhats)[i])
{
case SDL_HAT_UP:
Com_QueueEvent(0, SE_KEY, hat_keys[4 * i + 0], qfalse, 0, NULL);
break;
case SDL_HAT_RIGHT:
Com_QueueEvent(0, SE_KEY, hat_keys[4 * i + 1], qfalse, 0, NULL);
break;
case SDL_HAT_DOWN:
Com_QueueEvent(0, SE_KEY, hat_keys[4 * i + 2], qfalse, 0, NULL);
//.........这里部分代码省略.........
示例15: IN_InitJoystick
static void IN_InitJoystick(void)
{
int i = 0;
int total = 0;
char buf[16384] = "";
if (stick != NULL)
{
SDL_JoystickClose(stick);
}
stick = NULL;
memset(&stick_state, '\0', sizeof(stick_state));
if (!SDL_WasInit(SDL_INIT_JOYSTICK))
{
Com_Printf("Initializing joystick devices\n");
if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
{
Com_Printf("SDL_Init(SDL_INIT_JOYSTICK) failed: %s\n", SDL_GetError());
return;
}
Com_Printf("...joysticks initialized\n");
}
total = SDL_NumJoysticks();
Com_Printf("...available joysticks: %d\n", total);
// Print list and build cvar to allow ui to select joystick.
for (i = 0; i < total; i++)
{
Q_strcat(buf, sizeof(buf), SDL_JoystickNameForIndex(i));
Q_strcat(buf, sizeof(buf), "\n");
}
Cvar_Get("in_availableJoysticks", buf, CVAR_ROM);
if (!in_joystick->integer)
{
Com_Printf("...no active joystick set\n");
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
return;
}
in_joystickNo = Cvar_Get("in_joystickNo", "0", CVAR_ARCHIVE);
if (in_joystickNo->integer < 0 || in_joystickNo->integer >= total)
{
Cvar_Set("in_joystickNo", "0");
}
in_joystickUseAnalog = Cvar_Get("in_joystickUseAnalog", "0", CVAR_ARCHIVE);
stick = SDL_JoystickOpen(in_joystickNo->integer);
if (stick == NULL)
{
Com_Printf("No joystick opened.\n");
return;
}
Com_DPrintf("Joystick %d opened\n", in_joystickNo->integer);
Com_DPrintf("Name: %s\n", SDL_JoystickNameForIndex(in_joystickNo->integer));
Com_DPrintf("Axes: %d\n", SDL_JoystickNumAxes(stick));
Com_DPrintf("Hats: %d\n", SDL_JoystickNumHats(stick));
Com_DPrintf("Buttons: %d\n", SDL_JoystickNumButtons(stick));
Com_DPrintf("Balls: %d\n", SDL_JoystickNumBalls(stick));
Com_DPrintf("Use Analog: %s\n", in_joystickUseAnalog->integer ? "Yes" : "No");
SDL_JoystickEventState(SDL_QUERY);
}