本文整理汇总了C++中SDL_JoystickNumBalls函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_JoystickNumBalls函数的具体用法?C++ SDL_JoystickNumBalls怎么用?C++ SDL_JoystickNumBalls使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_JoystickNumBalls函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: print_joy_info
void print_joy_info() {
printf("Name: %s\n", SDL_JoystickNameForIndex(0));
printf("Number of Axes: %d\n", SDL_JoystickNumAxes(gJoystick));
printf("Number of Buttons: %d\n", SDL_JoystickNumButtons(gJoystick));
if(SDL_JoystickNumBalls(gJoystick) > 0) printf("Number of Balls: %d\n", SDL_JoystickNumBalls(gJoystick));
if(strncmp(SDL_JoystickNameForIndex(0), "PLAYSTATION(R)3 Controller", 25) == 0) {
// PS3 Rumble controller via BT
gControllerType = PS3_CONTROLLER;
}
if(strncmp(SDL_JoystickNameForIndex(0), "Sony PLAYSTATION(R)3 Controller", 30) == 0) {
// PS3 directly connected
gControllerType = PS3_CONTROLLER;
}
map_joy();
}
示例2: close
bool QJoystick::open(int stick)
{
if ( isOpen() )
close();
if(SDL_NumJoysticks() == 0)
return false;
joystick = SDL_JoystickOpen(stick);
if ( joystick ) {
joystickNameSelected = stick + 1;
numAxes = SDL_JoystickNumAxes(joystick);
numButtons = SDL_JoystickNumButtons(joystick);
numHats = SDL_JoystickNumHats(joystick);
numTrackballs = SDL_JoystickNumBalls(joystick);
qWarning("DEBUG: SDL joystick %d opened; axes = %d, buttons = %d, hats = %d, trackballs = %d", stick, numAxes, numButtons, numHats, numTrackballs);
axis_old_values.clear();
for(int i=0; i < numAxes; i++)
axis_old_values.append(0);
emit initJoystick(numAxes, numButtons, numHats, joystickNames.at(stick));
joystickTimer.start(eventTimeout);
return true;
} else {
qWarning("ERROR: couldn't open SDL joystick %d", stick);
return false;
}
}
示例3: print_joystick_info
void print_joystick_info(int joy_idx, SDL_Joystick* joy, SDL_GameController* gamepad)
{
SDL_JoystickGUID guid = SDL_JoystickGetGUID(joy);
char guid_str[1024];
SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str));
printf("Joystick Name: '%s'\n", SDL_JoystickName(joy));
printf("Joystick GUID: %s\n", guid_str);
printf("Joystick Number: %2d\n", joy_idx);
printf("Number of Axes: %2d\n", SDL_JoystickNumAxes(joy));
printf("Number of Buttons: %2d\n", SDL_JoystickNumButtons(joy));
printf("Number of Hats: %2d\n", SDL_JoystickNumHats(joy));
printf("Number of Balls: %2d\n", SDL_JoystickNumBalls(joy));
printf("GameController:\n");
if (!gamepad)
{
printf(" not a gamepad\n");
}
else
{
printf(" Name: '%s'\n", SDL_GameControllerName(gamepad));
printf(" Mapping: '%s'\n", SDL_GameControllerMappingForGUID(guid));
}
printf("\n");
}
示例4: calloc
krad_rc_sdl_joy_t *krad_rc_sdl_joy_create (int joynum) {
krad_rc_sdl_joy_t *krad_rc_sdl_joy = calloc(1, sizeof(krad_rc_sdl_joy_t));
int num_axes, num_buttons, num_balls, num_hats;
krad_rc_sdl_joy->joynum = joynum;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
return NULL;
}
SDL_JoystickEventState (SDL_ENABLE);
krad_rc_sdl_joy->joystick = SDL_JoystickOpen (krad_rc_sdl_joy->joynum);
num_axes = SDL_JoystickNumAxes (krad_rc_sdl_joy->joystick);
num_buttons = SDL_JoystickNumButtons (krad_rc_sdl_joy->joystick);
num_balls = SDL_JoystickNumBalls (krad_rc_sdl_joy->joystick);
num_hats = SDL_JoystickNumHats (krad_rc_sdl_joy->joystick);
printf("%s: %d axes, %d buttons, %d balls, %d hats\n",
SDL_JoystickName(krad_rc_sdl_joy->joynum),
num_axes, num_buttons, num_balls, num_hats);
krad_rc_sdl_joy->run = 1;
pthread_create (&krad_rc_sdl_joy->joy_thread, NULL, krad_rc_sdl_joy_thread, (void *)krad_rc_sdl_joy);
pthread_detach (krad_rc_sdl_joy->joy_thread);
return krad_rc_sdl_joy;
}
示例5: mScreen
//-------------------------------------------------------------------------------------------------------------------//
Application::Application(): mScreen(NULL), mEvent(), mIsItTimeToClose(false), mJoystick(NULL)
{
// On initialise la SDL.
MTest_T_MSG (SDL_Init(SDL_INIT_EVERYTHING) == -1, "SDL Initialization Error : " << SDL_GetError());
// Log pour les Joysticks.
MOut(SDL_NumJoysticks() << " joysticks connected");
for (int i = 0; i < SDL_NumJoysticks() ; ++i)
{
MOut("Joystick_" << i << " : " << SDL_JoystickName(i));
}
if (SDL_NumJoysticks() > 0)
{
// On active la gestion des evenements des Joysticks.
SDL_JoystickEventState(SDL_ENABLE);
// On charge le premier Joystick connecté.
mJoystick = SDL_JoystickOpen(0);
MOut("----> " << SDL_JoystickNumButtons(mJoystick) << " buttons");
MOut("----> " << SDL_JoystickNumAxes(mJoystick) << " axes");
MOut("----> " << SDL_JoystickNumBalls(mJoystick) << " trackballs");
MOut("----> " << SDL_JoystickNumHats(mJoystick) << " hats");
}
}
示例6: controller_joystick_attach
void controller_joystick_attach( Tank *t ) {
JoystickPrivateData *data;
/* Make sure that this is even a joystick to connect to: */
if(SDL_NumJoysticks() == 0) {
/* TODO: exiting isn't all that friendly... we need a better controller API... */
gamelib_debug("No joysticks connected.\n");
exit(1);
}
data = get_object(JoystickPrivateData);
data->joystick = SDL_JoystickOpen(0);
if(data->joystick) {
gamelib_debug("Using Joystick #0:\n");
gamelib_debug(" Name: %s\n", SDL_JoystickName(0));
gamelib_debug(" Axes: %d\n", SDL_JoystickNumAxes(data->joystick));
gamelib_debug(" Buttons: %d\n", SDL_JoystickNumButtons(data->joystick));
gamelib_debug(" Balls: %d\n", SDL_JoystickNumBalls(data->joystick));
} else {
gamelib_debug("Failed to open Joystick #0.\n");
exit(1);
}
tank_set_controller(t, joystick_controller, data);
}
示例7: main
int main(int, char**){
SDL_Init(SDL_INIT_JOYSTICK);
SDL_JoystickEventState(SDL_ENABLE);
atexit(SDL_Quit);
int num_joysticks = SDL_NumJoysticks();
if(num_joysticks == 0) {
std::cout << "No joysticks found! please attach a device and re-run this program" << std::endl;
return 0;
}
js = SDL_JoystickOpen(0);
//ok we've found our joystick!
if (js) {
SDL_JoystickGUID guid = SDL_JoystickGetGUID(js);
char guid_str[1024];
SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str));
const char* name = SDL_JoystickName(js);
int num_axes = SDL_JoystickNumAxes(js);
int num_buttons = SDL_JoystickNumButtons(js);
int num_hats = SDL_JoystickNumHats(js);
int num_balls = SDL_JoystickNumBalls(js);
std:: cout << guid_str << " \\ " << name << " \\ axes: " << num_axes << " buttons: " << num_buttons << " hats: " << num_hats << " balls: " << num_balls << std::endl;
}
//start webserver and bind to socket.
handler handler_;
http_server::options options(handler_);
http_server server(
options.address("0.0.0.0")
.port("1111"));
std::cout << "found joystick! starting server!" << std::endl;
server.run(); //function BLOCKS! see handler struct at top of page!
return 0;
}
示例8: joystick
TGen::Engine::SDLGamepad::SDLGamepad(int id, int internalId)
: TGen::Engine::InputDevice("gamepad", id)
, joystick(NULL)
{
joystick = SDL_JoystickOpen(internalId);
if (!joystick)
throw TGen::RuntimeException("SDLGamepad::SDLGamepad", "failed to open joystick # ") << internalId << "!";
joyName = SDL_JoystickName(internalId);
controls.numAxes = SDL_JoystickNumAxes(joystick);
controls.numButtons = SDL_JoystickNumBalls(joystick);
controls.numBalls = SDL_JoystickNumBalls(joystick);
controls.numHats = SDL_JoystickNumHats(joystick);
}
示例9: Log
INLINE BOOL Input::Initialize()
{
Log(TAG "Initializing...");
BOOL r = this->Reset();
#if defined(WIN32) && defined(DEBUG)
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
#endif
MEMSET(parJoy, '\0', sizeof(parJoy));
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
iJoystickCount = SDL_NumJoysticks();
if (iJoystickCount)
{
SDL_JoystickEventState(SDL_ENABLE);
Log(TAG "Joystick(s): ");
for (u32 i = 0; i < iJoystickCount; i++)
{
parJoy[i] = SDL_JoystickOpen(i);
if (parJoy[i])
{
Log("Opened Joystick %d:", i);
Log(TAG "\tName: %s", SDL_JoystickName(i));
Log(TAG "\t\tAxes: %d", SDL_JoystickNumAxes(parJoy[i]));
Log(TAG "\t\tButtons: %d", SDL_JoystickNumButtons(parJoy[i]));
Log(TAG "\t\tHats: %d", SDL_JoystickNumHats(parJoy[i]));
Log(TAG "\t\tBalls: %d", SDL_JoystickNumBalls(parJoy[i]));
}
}
}
Log(TAG "Initialization completed.");
return r;
}
示例10: init_joy
/* Initialize joysticks */
BOOL init_joy(u16 joyCfg[]) {
int i;
set_joy_keys(default_joypad_cfg);
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1)
{
fprintf(stderr, "Error trying to initialize joystick support: %s\n",
SDL_GetError());
return FALSE;
}
nbr_joy = SDL_NumJoysticks();
printf("Nbr of joysticks: %d\n\n", nbr_joy);
for (i = 0; i < nbr_joy; i++)
{
SDL_Joystick * joy = SDL_JoystickOpen(i);
printf("Joystick %s\n", i, SDL_JoystickName(i));
printf("Axes: %d\n", SDL_JoystickNumAxes(joy));
printf("Buttons: %d\n", SDL_JoystickNumButtons(joy));
printf("Trackballs: %d\n", SDL_JoystickNumBalls(joy));
printf("Hats: %d\n\n", SDL_JoystickNumHats(joy));
}
return TRUE;
}
示例11: OpenStick
bool cJoystick :: OpenStick( unsigned int index )
{
SDL_Joystick *Joystick = SDL_JoystickOpen( index );
if( !Joystick )
{
printf( "Couldn't open joystick %d\n", index );
Opened = 0;
return 0;
}
cur_stick = index;
num_buttons = SDL_JoystickNumButtons( Joystick );
num_axes = SDL_JoystickNumAxes( Joystick );
num_balls = SDL_JoystickNumBalls( Joystick );
if( Debug )
{
printf( "Opened Joystick %d\n", index );
printf( "Name: %s\n", SDL_JoystickName( index ) );
printf( "Number of Axes: %d\n", num_axes );
printf( "Number of Buttons: %d\n", num_buttons );
printf( "Number of Balls: %d\n\n", num_balls );
}
Opened = 1;
return 1;
}
示例12: joy_get_ball
static PyObject*
joy_get_ball (PyObject* self, PyObject* args)
{
int joy_id = PyJoystick_AsID (self);
SDL_Joystick* joy = joystick_stickdata[joy_id];
int _index, dx, dy;
Uint32 value;
if (!PyArg_ParseTuple (args, "i", &_index)) {
return NULL;
}
JOYSTICK_INIT_CHECK ();
if (!joy) {
return RAISE (PyExc_SDLError, "Joystick not initialized");
}
value = SDL_JoystickNumBalls (joy);
#ifdef DEBUG
/*printf("SDL_JoystickNumBalls value:%d:\n", value);*/
#endif
if (_index < 0 || _index >= value) {
return RAISE (PyExc_SDLError, "Invalid joystick trackball");
}
SDL_JoystickGetBall (joy, _index, &dx, &dy);
return Py_BuildValue ("(ii)", dx, dy);
}
示例13: joystick_use
/**
* @brief Makes the game use a joystick by index.
*
* @param indjoystick Index of the joystick to use.
* @return 0 on success.
*/
int joystick_use( int indjoystick )
{
/* Check to see if it exists. */
if ((indjoystick < 0) || (indjoystick >= SDL_NumJoysticks())) {
WARN("Joystick of index number %d does not existing, switching to default 0",
indjoystick);
indjoystick = 0;
}
/* Close if already open. */
if (joystick != NULL) {
SDL_JoystickClose(joystick);
joystick = NULL;
}
/* Start using joystick. */
joystick = SDL_JoystickOpen(indjoystick);
if (joystick == NULL) {
WARN("Error opening joystick %d [%s]", indjoystick, SDL_JoystickName(indjoystick));
return -1;
}
LOG("Using joystick %d - %s", indjoystick, SDL_JoystickName(indjoystick));
DEBUG(" with %d axes, %d buttons, %d balls and %d hats",
SDL_JoystickNumAxes(joystick), SDL_JoystickNumButtons(joystick),
SDL_JoystickNumBalls(joystick), SDL_JoystickNumHats(joystick));
/* Initialize the haptic if possible. */
joystick_initHaptic();
/* For style purposes. */
DEBUG();
return 0;
}
示例14: gui_init_sdl
int gui_init_sdl()
{
if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) == -1 )
{
fprintf(stderr, "Couldn’t initialize SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
int joystick = 0, x = 0;
joystick = SDL_NumJoysticks();
printf("Joysticks spotted : %d\n", joystick);
for (x = 0; x < joystick; x++)
{
SDL_Joystick * joy = SDL_JoystickOpen(x);
printf("Joystick %i: %s\n", x, SDL_JoystickName(x));
printf("Axes: %d\n", SDL_JoystickNumAxes(joy));
printf("Boutons: %d\n", SDL_JoystickNumButtons(joy));
printf("Trackballs: %d\n", SDL_JoystickNumBalls(joy));
printf("Hats: %d\n\n", SDL_JoystickNumHats(joy));
}
myscreen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
if( myscreen == NULL )
{
fprintf(stderr, "Couldn’t initialize VideoMode: %s\n", SDL_GetError());
return 0;
}
if( TTF_Init() == -1 )
{
printf("TTF_Init() failed : %s\n", SDL_GetError());
return 0;
}
font = TTF_OpenFont( "data/font.ttf", 16);
if( font == NULL )
{
printf("TTF_OpenFont failed : %s\n", SDL_GetError());
return 0;
}
font_big = TTF_OpenFont( "data/font.ttf", 20);
if( font == NULL )
{
printf("TTF_OpenFont failed : %s\n", SDL_GetError());
return 0;
}
#ifndef PANDORA
SDL_ShowCursor(SDL_ENABLE);
#else
SDL_ShowCursor(SDL_DISABLE);
#endif
return 1;
}
示例15: Java_at_wisch_joystick_Joystick_getNoOfBalls
JNIEXPORT jint JNICALL Java_at_wisch_joystick_Joystick_getNoOfBalls (JNIEnv *env, jclass, jint joystickIndex){
int num = SDL_JoystickNumBalls(joysticks[joystickIndex]);
if (num < 0) {
throwException(env, SDL_GetError());
return -10;
}
return num;
}