当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_JoystickNumAxes函数代码示例

本文整理汇总了C++中SDL_JoystickNumAxes函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_JoystickNumAxes函数的具体用法?C++ SDL_JoystickNumAxes怎么用?C++ SDL_JoystickNumAxes使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_JoystickNumAxes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SetupInput

void SetupInput()
{
	for (int port=0;port<4;port++)
	{
		kcode[port]=0xFFFF;
		rt[port]=0;
		lt[port]=0;
	}

	// Open joystick device
	int numjoys = SDL_NumJoysticks();
	printf("Number of Joysticks found = %i\n", numjoys);
	if (numjoys > 0)
		JoySDL = SDL_JoystickOpen(0);
	printf("Joystick openned\n");	
	if(JoySDL)
	{
		int AxisCount,ButtonCount;
		const char* Name;

		AxisCount   = 0;
		ButtonCount = 0;
//		Name[0]     = '\0';

		AxisCount = SDL_JoystickNumAxes(JoySDL);
		ButtonCount = SDL_JoystickNumButtons(JoySDL);
		Name = SDL_JoystickName(0);
		
		printf("SDL: Found '%s' joystick with %d axis and %d buttons\n",Name,AxisCount,ButtonCount);

		if (strcmp(Name,"Microsoft X-Box 360 pad")==0)
		{
			JMapBtn=JMapBtn_360;
			JMapAxis=JMapAxis_360;
			printf("Using Xbox 360 map\n");
		}
	} else printf("SDL: No Joystick Found\n");	
	SDL_ShowCursor( 0 );
}
开发者ID:mork2020,项目名称:reicast-emulator,代码行数:39,代码来源:sdlinput.cpp

示例2: read_joy

static void read_joy (unsigned int nr)
{
    unsigned int num, i, axes, axis;
    SDL_Joystick *joy;

    if (currprefs.input_selected_setting == 0) {
	if (jsem_isjoy (0, &currprefs) != (int)nr && jsem_isjoy (1, &currprefs) != (int)nr)
	    return;
    }
    joy = joys[nr].joy;
    axes = SDL_JoystickNumAxes (joy);
    for (i = 0; i < axes; i++) {
	axis = SDL_JoystickGetAxis (joy, i);
	setjoystickstate (nr, i, axis, 32767);
    }

    num = SDL_JoystickNumButtons (joy);
    for (i = 0; i < num; i++) {
	int bs = SDL_JoystickGetButton (joy, i) ? 1 : 0;
	setjoybuttonstate (nr, i, bs);
    }
}
开发者ID:threader,项目名称:e-uae-ppc-jit-nix,代码行数:22,代码来源:joystick.c

示例3: SDL_JoystickOpen

static struct device *open_device(int joystick_index) {
	// If the device is already open, just up its count and return it
	for (struct slist *iter = device_list; iter; iter = iter->next) {
		struct device *d = iter->data;
		if (d->joystick_index == joystick_index) {
			d->open_count++;
			return d;
		}
	}
	// Otherwise open and throw it on the list
	SDL_Joystick *j = SDL_JoystickOpen(joystick_index);
	if (!j)
		return NULL;
	struct device *d = xmalloc(sizeof(*d));
	d->joystick_index = joystick_index;
	d->joystick = j;
	d->num_axes = SDL_JoystickNumAxes(j);
	d->num_buttons = SDL_JoystickNumButtons(j);
	d->open_count = 1;
	device_list = slist_prepend(device_list, d);
	return d;
}
开发者ID:jedie,项目名称:XRoar,代码行数:22,代码来源:joystick_sdl.c

示例4: memcpy

void Input::updateGamepadState(SDL_Joystick* joystick, GamepadState& state)
{
	//save old state
	int prev_direction = state.direction;
	char prev_button[16];
	memcpy(prev_button, state.button, 16);

	//set all to 0
	memset(&state, 0, sizeof(GamepadState));

	if (joystick == NULL)
		return;

	state.num_axis = SDL_JoystickNumAxes((::SDL_Joystick*) joystick);
	state.num_buttons = SDL_JoystickNumButtons((::SDL_Joystick*)joystick);

	if (state.num_axis > 8) state.num_axis = 8;
	if (state.num_buttons > 16) state.num_buttons = 16;

	for (int i = 0; i < state.num_axis; ++i) //axis
		state.axis[i] = SDL_JoystickGetAxis((::SDL_Joystick*) joystick, i) / 32768.0f; //range -32768 to 32768
	for (int i = 0; i < state.num_buttons; ++i) //buttons
		state.button[i] = SDL_JoystickGetButton((::SDL_Joystick*) joystick, i);
	state.hat = (HATState)(SDL_JoystickGetHat((::SDL_Joystick*) joystick, 0) - SDL_HAT_CENTERED); //one hat is enough
	memcpy(state.prev_button, prev_button, 16); //copy prev buttons state

	Vector2 axis_direction(state.axis[LEFT_ANALOG_X], state.axis[LEFT_ANALOG_Y]);
	state.prev_direction = prev_direction;
	state.direction = 0;
	float limit = 0.6;
	if (axis_direction.x < -limit)
		state.direction |= PAD_LEFT;
	else if (axis_direction.x > limit)
		state.direction |= PAD_RIGHT;
	if (axis_direction.y < -limit)
		state.direction |= PAD_UP;
	else if (axis_direction.y > limit)
		state.direction |= PAD_DOWN;
}
开发者ID:joanmassana,项目名称:UPF_JocsElectronics,代码行数:39,代码来源:input.cpp

示例5: SDL_JoystickOpen

static struct joy *find_joy(int joy_num) {
	SDL_Joystick *j;
	int i;
	if (joy_num >= num_sdl_joysticks)
		return NULL;
	for (i = 0; i < num_joys; i++) {
		if (joy[i].joy_num == joy_num)
			return &joy[i];
	}
	i = num_joys;
	num_joys++;
	j = joy[i].device = SDL_JoystickOpen(joy_num);
	if (j == NULL)
		return NULL;
	joy[i].joy_num = joy_num;
	joy[i].num_axes = SDL_JoystickNumAxes(j);
	joy[i].num_buttons = SDL_JoystickNumButtons(j);
	LOG_DEBUG(1,"\t%s\n", SDL_JoystickName(joy_num));
	LOG_DEBUG(2,"\tNumber of Axes: %d\n", joy[i].num_axes);
	LOG_DEBUG(2,"\tNumber of Buttons: %d\n", joy[i].num_buttons);
	return &joy[i];
}
开发者ID:CrashSerious,项目名称:PS3Roar,代码行数:22,代码来源:joystick_sdl.c

示例6: Stick_Open

bool cJoystick :: Stick_Open( unsigned int index )
{
	// if a joystick is already opened close it first
	if( m_joystick_open )
	{
		Stick_Close();
	}

	m_joystick = SDL_JoystickOpen( index );

	if( !m_joystick )
	{
		printf( "Couldn't open joystick %d\n", index );
		m_joystick_open = 0;
		return 0;
	}

	m_current_joystick = index;

	m_num_buttons = SDL_JoystickNumButtons( m_joystick );
	m_num_axes = SDL_JoystickNumAxes( m_joystick );
	m_num_balls = SDL_JoystickNumBalls( m_joystick );

	// setup available buttons
	m_buttons.assign( m_num_buttons, 0 );

	if( m_debug )
	{
		printf( "Opened Joystick %d\n", m_current_joystick );
		printf( "Name: %s\n", Get_Name().c_str() );
		printf( "Number of Buttons: %d\n", m_num_buttons );
		printf( "Number of Axes: %d\n", m_num_axes );
		printf( "Number of Balls: %d\n\n", m_num_balls );
	}

	m_joystick_open = 1;
	return 1;
}
开发者ID:sKabYY,项目名称:SMC,代码行数:38,代码来源:joystick.cpp

示例7: 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");
}
开发者ID:intervigilium,项目名称:android-opentyrian,代码行数:39,代码来源:joystick.c

示例8: joy_get_caps

void joy_get_caps (int max)
{
	SDL_Joystick *joy;
	int j;

	for (j=0; j < JOY_NUM_AXES; j++)
		joystick.axis_valid[j] = 0;

	for (j=JOYSTICKID1; j<JOYSTICKID1+max; j++) {
		joy = SDL_JoystickOpen (j);
		if (joy)
		{
			nprintf (("JOYSTICK", "Joystick #%d: %s\n", j - JOYSTICKID1 + 1, SDL_JoystickName(SDL_JoystickOpen(j))));
			if (j == Cur_joystick) {
				for (int i = 0; i < SDL_JoystickNumAxes(joy); i++)
				{
					joystick.axis_valid[i] = 1;
				}
			}
			SDL_JoystickClose (joy);
		}
	}
}
开发者ID:derek-yeung,项目名称:fs2open.github.com,代码行数:23,代码来源:joy-unix.cpp

示例9: 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;
}
开发者ID:arturo182,项目名称:BattleTanks,代码行数:23,代码来源:gamepad.cpp

示例10: mem_zero

CControls::CControls()
{
	mem_zero(&m_LastData, sizeof(m_LastData));
	m_LastDummy = 0;
	m_OtherFire = 0;

#if !defined(__ANDROID__)
	if (g_Config.m_InpJoystick)
#endif
	{
		SDL_Init(SDL_INIT_JOYSTICK);
		m_Joystick = SDL_JoystickOpen(0);
		if( m_Joystick && SDL_JoystickNumAxes(m_Joystick) < NUM_JOYSTICK_AXES )
		{
			SDL_JoystickClose(m_Joystick);
			m_Joystick = NULL;
		}

		m_Gamepad = SDL_JoystickOpen(2);

		SDL_JoystickEventState(SDL_QUERY);

		m_UsingGamepad = false;
#if defined(CONF_FAMILY_UNIX)
		if( getenv("OUYA") )
			m_UsingGamepad = true;
#endif
	}
#if !defined(__ANDROID__)
	else
	{
		m_Joystick = NULL;
		m_Gamepad = NULL;
		m_UsingGamepad = false;
	}
#endif
}
开发者ID:Laxa,项目名称:ddnet,代码行数:37,代码来源:controls.cpp

示例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;
}
开发者ID:yoyofr,项目名称:iNEOGEO,代码行数:37,代码来源:event.c

示例12: Kernel

void CInput::Init()
{
	m_pGraphics = Kernel()->RequestInterface<IEngineGraphics>();
	m_pConsole = Kernel()->RequestInterface<IConsole>();
	// FIXME: unicode handling: use SDL_StartTextInput/SDL_StopTextInput on inputs

	MouseModeRelative();

	if(!SDL_WasInit(SDL_INIT_JOYSTICK))
	{
		if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
		{
			dbg_msg("joystick", "unable to init SDL joystick: %s", SDL_GetError());
			return;
		}
	}

	if(SDL_NumJoysticks() > 0)
	{
		m_pJoystick = SDL_JoystickOpen(0);

		if(!m_pJoystick) {
			dbg_msg("joystick", "Could not open 0th joystick: %s", SDL_GetError());
			return;
		}

		dbg_msg("joystick", "Opened Joystick 0");
		dbg_msg("joystick", "Name: %s", SDL_JoystickNameForIndex(0));
		dbg_msg("joystick", "Number of Axes: %d", SDL_JoystickNumAxes(m_pJoystick));
		dbg_msg("joystick", "Number of Buttons: %d", SDL_JoystickNumButtons(m_pJoystick));
		dbg_msg("joystick", "Number of Balls: %d", SDL_JoystickNumBalls(m_pJoystick));
	}
	else
	{
		dbg_msg("joystick", "No joysticks found");
	}
}
开发者ID:BotoX,项目名称:teeworlds,代码行数:37,代码来源:input.cpp

示例13: initJoystick

static void initJoystick(int i, bool isTemp) {
	assert(i == 0 || i == 1);
	if(!bJoystickSupport) return;

	if(joys[i] == NULL && SDL_NumJoysticks() > i && !SDL_JoystickOpened(i)) {
		notes << "opening joystick " << i << endl;
		notes << " (\"" << SDL_JoystickName(i) << "\")" << endl;
		joys[i] = SDL_JoystickOpen(i);
		if(joys[i]) {
			notes << "  Number of Axes: " << SDL_JoystickNumAxes(joys[i]) << endl;
			notes << "  Number of Buttons: " << SDL_JoystickNumButtons(joys[i]) << endl;
			notes << "  Number of Balls: " << SDL_JoystickNumBalls(joys[i]) << endl;
			if(isTemp) joysticks_inited_temp[i] = true;
		} else
			warnings << "Could not open joystick" << endl;
	}

	// Save the initial axis values
	SDL_Delay(40); // Small hack: this little delay is needed here for the joysticks to initialize correctly (bug in SDL?)
	SDL_JoystickUpdate();
	updateAxisStates();

	if(!isTemp) joysticks_inited_temp[i] = false;
}
开发者ID:iamnilay3,项目名称:openlierox,代码行数:24,代码来源:CInput.cpp

示例14: assert

void InputManager::addJoystickByDeviceIndex(int id)
{
    assert(id >= 0 && id < SDL_NumJoysticks());

    // open joystick & add to our list
    SDL_Joystick* joy = SDL_JoystickOpen(id);
    assert(joy);

    // add it to our list so we can close it again later
    SDL_JoystickID joyId = SDL_JoystickInstanceID(joy);
    mJoysticks[joyId] = joy;

    char guid[65];
    SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), guid, 65);

    // create the InputConfig
    mInputConfigs[joyId] = new InputConfig(joyId, SDL_JoystickName(joy), guid);
    if(!loadInputConfig(mInputConfigs[joyId]))
    {
        LOG(LogInfo) << "Added unconfigured joystick " << SDL_JoystickName(joy)
                     << " (GUID: " << guid << ", instance ID: " << joyId
                     << ", device index: " << id << ").";
    }
    else
    {
        LOG(LogInfo) << "Added known joystick " << SDL_JoystickName(joy)
                     << " (instance ID: " << joyId << ", device index: " << id
                     << ")";
    }

    // set up the prevAxisValues
    int numAxes = SDL_JoystickNumAxes(joy);
    mPrevAxisValues[joyId] = new int[numAxes];
    std::fill(mPrevAxisValues[joyId], mPrevAxisValues[joyId] + numAxes,
              0); // initialize array to 0
}
开发者ID:arthurlutz,项目名称:InputStation,代码行数:36,代码来源:InputManager.cpp

示例15: 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;
}
开发者ID:xquiet,项目名称:sdlbasic,代码行数:25,代码来源:joystick.c


注:本文中的SDL_JoystickNumAxes函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。