Пример #1
0
void I_UpdateJoystick(void)
{
    if (joystick != NULL)
    {
        event_t ev;

        ev.type = ev_joystick;
        ev.data1 = GetButtonState();
        ev.data2 = GetAxisState(joystick_x_axis, joystick_x_invert);
        ev.data3 = GetAxisState(joystick_y_axis, joystick_y_invert);
        ev.data4 = GetAxisState(joystick_strafe_axis, joystick_strafe_invert);

        D_PostEvent(&ev);
    }
}
Пример #2
0
bool JoystickInfo::PollAxes(u32 &pkey)
{
    for (int i = 0; i < GetNumAxes(); ++i)
    {
        // Sixaxis, dualshock3 hack
        u32 found_hack = devname.find(string("PLAYSTATION(R)3"));
        if (found_hack != string::npos) {
            // The analog mode of the hat button is quite erratic. Values can be in half- axis
            // or full axis... So better keep them as button for the moment -- gregory
            if (i >= 8 && i <= 11 && (conf->pad_options[pad].sixaxis_usb))
                continue;
            // Disable accelerometer
            if ((i >= 4 && i <= 6))
                continue;
        }

        s32 value = SDL_JoystickGetAxis(GetJoy(), i);
        s32 old_value = GetAxisState(i);

        if (abs(value - old_value) < 0x1000)
            continue;

        if (value != old_value)
        {
            PAD_LOG("Change in joystick %d: %d.\n", i, value);
            // There are several kinds of axes
            // Half+: 0 (release) -> 32768
            // Half-: 0 (release) -> -32768
            // Full (like dualshock 3): -32768 (release) ->32768
            const s32 full_axis_ceil = -0x6FFF;
            const s32 half_axis_ceil = 0x1FFF;

            // Normally, old_value contains the release state so it can be used to detect the types of axis.
            bool is_full_axis = (old_value < full_axis_ceil) ? true : false;

            if ((!is_full_axis && abs(value) <= half_axis_ceil)
                    || (is_full_axis && value <= full_axis_ceil))  // we don't want this
            {
                continue;
            }

            if ((!is_full_axis && abs(value) > half_axis_ceil)
                    || (is_full_axis && value > full_axis_ceil))
            {
                bool sign = (value < 0);
                pkey = axis_to_key(is_full_axis, sign, i);

                return true;
            }
        }
    }

    return false;
}
Пример #3
0
/**
@brief	ジョイスティックにある全てのアナログスティックの入力状態を取得するサンプル。
*/
void Joystick_Axis()
{
	// Altseedを初期化する。
	asd::Engine::Initialize(asd::ToAString("Joystick_Axis").c_str(), 640, 480, asd::EngineOption());

	// ジョイスティックの状態を表示するテキストを生成する。
	auto font = asd::Engine::GetGraphics()->CreateDynamicFont(asd::ToAString("").c_str(), 35, asd::Color(255, 255, 255, 255), 1, asd::Color(0, 0, 0, 255));

	// アナログスティックの入力状態を表示する文字描画オブジェクトを設定して、エンジンに追加する。
	auto stateText = std::make_shared<asd::TextObject2D>();
	stateText->SetPosition(asd::Vector2DF(10, 10));
	stateText->SetFont(font);
	asd::Engine::AddObject2D(stateText);

	// Altseedのウインドウが閉じられていないか確認する。
	while (asd::Engine::DoEvents())
	{
		asd::astring displayStr = asd::ToAString("");

		// ジョイスティックが接続されているかどうかを確認する。
		if (!asd::Engine::GetJoystickContainer()->GetIsPresentAt(0))
		{
			displayStr += asd::ToAString("ジョイスティックが接続されていません。");
		}
		else
		{
			// 1つ目のジョイスティックの全てのアナログスティックの入力状態を表示する。
			auto joystick = asd::Engine::GetJoystickContainer()->GetJoystickAt(0);

			for (int axisIndex = 0; axisIndex < joystick->GetAxesCount(); ++axisIndex)
			{
				auto axisVal = joystick->GetAxisState(axisIndex);
				displayStr += asd::ToAString(("軸 " + std::to_string(axisIndex) + ": ").c_str());
				displayStr += asd::ToAString(std::to_string(axisVal).c_str());
				displayStr += asd::ToAString("\n");
			}

		}

		stateText->SetText(displayStr.c_str());

		// Altseedを更新する。
		asd::Engine::Update();
	}

	//Altseedの終了処理をする。
	asd::Engine::Terminate();

	return;
}