Пример #1
0
static bool joystickChangedCallback(tJoyState *oldState, tJoyState *newState)
{
    
    if (oldState->position != JOY_POS_CENTER)
        return false;
    
    if ((newState->button0) ||
        (newState->button1)) {
        switch (newState->position) {
            case JOY_POS_UP:
                return swapDir(DIR_UP);
                
            case JOY_POS_DOWN:
                return swapDir(DIR_DOWN);
                
            case JOY_POS_LEFT:
                return swapDir(DIR_LEFT);
                
            case JOY_POS_RIGHT:
                return swapDir(DIR_RIGHT);
                
            default:
                break;
        }
        return false;
    }
    
    joystickMove(newState->position);
    
    return false;
}
Пример #2
0
task main()
{
	  while(true)
	  {
		    joystickMove();
	  }
}
Пример #3
0
static bool joystickNoChangeCallback(tJoyState *oldState)
{
    if (oldState->button0)
        return false;
    
    if (oldState->button1)
        return false;
    
    joystickMove(oldState->position);
    return false;
}
Пример #4
0
void joystick_XboxController(
    int, // joyidx
    const float* pAxisStates,
    int numAxes,
    const unsigned char* pButtonStates,
    int numButtons,
    const char* pLastButtonStates)
{
    //ASSERT(numAxes == 5);
    //ASSERT(numButtons == 14);
    if (numAxes != 5)
        return;
    if (numButtons != 14)
        return;

    // Xbox controller layout in glfw:
    // numAxes 5, numButtons 14
    // 0 A (down position)
    // 1 B (right position)
    // 2 X (left position)
    // 3 Y (up position)
    // 4 L bumper
    // 5 R bumper
    // 6 Back (left center)
    // 7 Start (right center)
    // 8 Left stick push
    // 9 Right stick push
    // 10 Dpad Up
    // 11 Dpad right
    // 12 Dpad down
    // 13 Dpad left
    // Axis 0 1 Left stick x y
    // Axis 2 triggers, left positive right negative
    // Axis 3 4 right stick y x

    glm::vec3 joystickMove(0.0f, 0.0f, 0.0f);
    // Xbox controller Left stick controls movement
    if (numAxes >= 2)
    {
        const float x_move = pAxisStates[0];
        const float y_move = pAxisStates[1];
        const glm::vec3 forward(0.f, 0.f, -1.f);
        const glm::vec3 right(1.f, 0.f, 0.f);
        const float deadzone = 0.5f;
        if (fabs(x_move) > deadzone)
            joystickMove += x_move * right;
        if (fabs(y_move) > deadzone)
            joystickMove -= y_move * forward;
    }

    if (pButtonStates[0] == GLFW_PRESS) // A button
        joystickMove += glm::vec3(0.f, 1.f, 0.f);
    if (pButtonStates[1] == GLFW_PRESS) // B button
        joystickMove += glm::vec3(0.f, -1.f, 0.f);

    float mag = 1.f;
    if (numAxes > 2)
    {
        // Xbox left and right analog triggers control speed
        mag = pow(10.f, pAxisStates[2]);
    }
    m_joystickMove = mag * joystickMove;

    // Right stick controls yaw
    ///@todo Pitch, Roll(instant nausea!)
    if (numAxes > 3)
    {
        float x_move = pAxisStates[4];
        const glm::vec3 up(0.f, 1.f, 0.f);
        const float deadzone = 0.2f;
        if (fabs(x_move) < deadzone)
            x_move = 0.f;
        m_joystickYaw = 0.75f * static_cast<float>(x_move);
    }

    // Check for recent button pushes
    const float f = 0.9f;
    for (int i = 0; i<numButtons; ++i)
    {
        const bool pressed = (pButtonStates[i] == GLFW_PRESS) &&
            (pLastButtonStates[i] != GLFW_PRESS);
        const bool released = (pButtonStates[i] != GLFW_PRESS) &&
            (pLastButtonStates[i] == GLFW_PRESS);
        if (pressed)
        {
            if (i == 13) // Dpad left
            {
                m_fboScale *= f;
                m_fboScale = std::max(.05f, m_fboScale);
            }
            if (i == 11) // Dpad right
            {
                m_fboScale /= f;
                m_fboScale = std::min(1.f, m_fboScale);
            }
            if (i == 10) // Dpad up
            {
                m_cinemaScope += 0.1f;
                m_cinemaScope = std::min(.95f, m_cinemaScope);
            }
            if (i == 12) // Dpad down
            {
                m_cinemaScope -= 0.1f;
                m_cinemaScope = std::max(0.f, m_cinemaScope);
            }
            if (i == 4) // Left Bumper
            {
                ovr_RecenterTrackingOrigin(g_session);
            }
            if (i == 5) // Right Bumper
            {
                m_chassisPos = glm::vec3(0.f, 1.f, 0.f);
            }
            if (i == 7) // Start
            {
                g_gallery.ToggleShaderWorld();
            }
            if (i == 3) // Y button
            {
                g_tweakbarQuad.m_showQuadInWorld = !g_tweakbarQuad.m_showQuadInWorld;
            }
        }
        if (pressed || released)
        {
            if (i == 2) // X button
            {
                g_tweakbarQuad.MouseClick(pressed ? 1 : 0);
            }
        }
    }
}
Пример #5
0
void joystick_XboxController(
    int, // joyidx
    const float* pAxisStates,
    int numAxes,
    const unsigned char* pButtonStates,
    int numButtons,
    const char* pLastButtonStates)
{
    //ASSERT(numAxes == 5);
    //ASSERT(numButtons == 14);
    if (numAxes != 5)
        return;
    if (numButtons != 14)
        return;

    // Xbox controller layout in glfw:
    // numAxes 5, numButtons 14
    // 0 A (down position)
    // 1 B (right position)
    // 2 X (left position)
    // 3 Y (up position)
    // 4 L bumper
    // 5 R bumper
    // 6 Back (left center)
    // 7 Start (right center)
    // 8 Left stick push
    // 9 Right stick push
    // 10 Dpad Up
    // 11 Dpad right
    // 12 Dpad down
    // 13 Dpad left
    // Axis 0 1 Left stick x y
    // Axis 2 triggers, left positive right negative
    // Axis 3 4 right stick y x

    glm::vec3 joystickMove(0.0f, 0.0f, 0.0f);
    // Xbox controller Left stick controls movement
    if (numAxes >= 2)
    {
        const float x_move = pAxisStates[0];
        const float y_move = pAxisStates[1];
        const glm::vec3 forward(0.f, 0.f, -1.f);
        const glm::vec3 right(1.f, 0.f, 0.f);
        const float deadzone = 0.5f;
        if (fabs(x_move) > deadzone)
            joystickMove += x_move * right;
        if (fabs(y_move) > deadzone)
            joystickMove -= y_move * forward;
    }

    if (pButtonStates[0] == GLFW_PRESS) // A button
        joystickMove += glm::vec3( 0.f,  1.f,  0.f);
    if (pButtonStates[1] == GLFW_PRESS) // B button
        joystickMove += glm::vec3( 0.f, -1.f,  0.f);

    float mag = 1.f;
    if (numAxes > 2)
    {
        // Xbox left and right analog triggers control speed
        mag = pow(10.f, pAxisStates[2]);
    }
    g_app.m_joystickMove = mag * joystickMove;

    // Right stick controls yaw
    ///@todo Pitch, Roll(instant nausea!)
    if (numAxes > 3)
    {
        float x_move = pAxisStates[4];
        const glm::vec3 up(0.f, 1.f, 0.f);
        const float deadzone = 0.2f;
        if (fabs(x_move) < deadzone)
            x_move = 0.f;
        g_app.m_joystickYaw = 0.75f * static_cast<float>(x_move);
    }

    // Check for recent button pushes
    const float f = 0.9f;
    for (int i=0; i<numButtons; ++i)
    {
        const bool pressed = (pButtonStates[i] == GLFW_PRESS) &&
                             (pLastButtonStates[i] != GLFW_PRESS);
        const bool released = (pButtonStates[i] != GLFW_PRESS) &&
                              (pLastButtonStates[i] == GLFW_PRESS);
        if (pressed)
        {
            g_app.DismissHealthAndSafetyWarning();

            if (i == 13) // Dpad left
            {
                g_dynamicallyScaleFBO = false;
                g_app.SetFBOScale(f * g_app.GetFBOScale());
            }
            if (i == 11) // Dpad right
            {
                g_dynamicallyScaleFBO = false;
                g_app.SetFBOScale((1.f/f) * g_app.GetFBOScale());
            }
            if (i == 10) // Dpad up
            {
                g_app.m_cinemaScopeFactor -= 0.1f;
                g_app.m_cinemaScopeFactor = std::max(0.f, g_app.m_cinemaScopeFactor);
            }
            if (i == 12) // Dpad down
            {
                g_app.m_cinemaScopeFactor += 0.1f;
                g_app.m_cinemaScopeFactor = std::min(0.95f, g_app.m_cinemaScopeFactor);
            }
            if (i == 4) // Left Bumper
            {
                g_app.RecenterPose();
            }
            if (i == 5) // Right Bumper
            {
                g_app.ResetChassisTransformations();
            }
            if (i == 7) // Start
            {
                g_app.ToggleShaderWorld();
            }
            if (i == 3) // Y button
            {
                g_app.m_dashScene.m_bDraw = !g_app.m_dashScene.m_bDraw;
            }
        }
        if (pressed || released)
        {
            if (i == 2) // X button
            {
                g_app.m_dashScene.SendMouseClick(pressed?1:0);
            }
            if (i == 9) // Right stick push
            {
                g_app.m_dashScene.SetHoldingFlag(pressed?1:0);
            }
        }
    }
}
Пример #6
0
void joystick_GravisGamepadPro(
    int, // joyidx
    const float*, // pAxisStates
    int numAxes,
    const unsigned char* pButtonStates,
    int numButtons,
    const char* pLastButtonStates)
{
    // Map joystick buttons to move directions
    // Gravis Gamepad Pro layout in glfw:
    // 0 Red (left position)
    // 1 Yellow (down position)
    // 2 Green (right position)
    // 3 Blue (up position)
    // 4 Left top shoulder
    // 5 Right top shoulder
    // 6 Left bottom shoulder
    // 7 Right bottom shoulder
    // 8 Select (left center)
    // 9 Start (right center)
    const glm::vec3 moveDirsGravisGamepadPro[8] = {
        glm::vec3(-1.f,  0.f,  0.f),
        glm::vec3( 0.f,  0.f,  1.f),
        glm::vec3( 1.f,  0.f,  0.f),
        glm::vec3( 0.f,  0.f, -1.f),
        glm::vec3( 0.f,  0.f,  0.f),
        glm::vec3( 0.f,  0.f,  0.f),
        glm::vec3( 0.f,  0.f,  0.f),
        glm::vec3( 0.f,  0.f,  0.f),
    };
    glm::vec3 joystickMove(0.0f, 0.0f, 0.0f);
    for (int i=0; i<std::min(8,numButtons); ++i)
    {
        if (pButtonStates[i] == GLFW_PRESS)
        {
            joystickMove += moveDirsGravisGamepadPro[i];
        }
    }
    
    float mag = 1.f;
    if (numAxes > 2)
    {
    }
    g_app.m_joystickMove = mag * joystickMove;

    const int buttonAdjustVfov = 8;
    const int buttonCloseVfov = 4;
    const int buttonOpenVfov = 6;
    if (pButtonStates[buttonAdjustVfov] == GLFW_PRESS)
    {
        const float incr = 0.05f;
        float scope = g_app.m_cinemaScopeFactor;
        if (
            (pButtonStates[buttonCloseVfov] == GLFW_PRESS) &&
            (pLastButtonStates[buttonCloseVfov] != GLFW_PRESS)
            )
        {
            scope += incr;
        }
        else if (
            (pButtonStates[buttonOpenVfov] == GLFW_PRESS) &&
            (pLastButtonStates[buttonOpenVfov] != GLFW_PRESS)
            )
        {
            scope -= incr;
        }
        scope = std::max(0.0f, scope);
        scope = std::min(0.95f, scope);
        g_app.m_cinemaScopeFactor = scope;
    }
}
void joystick()
{
    if (g_joystickIdx == -1)
        return;

    ///@todo Do these calls take time? We can move them out if so
    int joyStick1Present = GL_FALSE;
    joyStick1Present = glfwJoystickPresent(g_joystickIdx);
    if (joyStick1Present != GL_TRUE)
        return;

    // Poll joystick
    int numAxes = 0;
    const float* pAxisStates = glfwGetJoystickAxes(g_joystickIdx, &numAxes);
    if (numAxes < 2)
        return;

    int numButtons = 0;
    const unsigned char* pButtonStates = glfwGetJoystickButtons(g_joystickIdx, &numButtons);
    if (numButtons < 8)
        return;

    // Map joystick buttons to move directions
    const glm::vec3 moveDirsGravisGamepadPro[8] = {
        glm::vec3(-1.f,  0.f,  0.f),
        glm::vec3( 0.f,  0.f,  1.f),
        glm::vec3( 1.f,  0.f,  0.f),
        glm::vec3( 0.f,  0.f, -1.f),
        glm::vec3( 0.f,  1.f,  0.f),
        glm::vec3( 0.f,  1.f,  0.f),
        glm::vec3( 0.f, -1.f,  0.f),
        glm::vec3( 0.f, -1.f,  0.f),
    };

    // Xbox controller layout in glfw:
    // numAxes 5, numButtons 14
    // 0 A (down position)
    // 1 B (right position)
    // 2 X (left position)
    // 3 Y (up position)
    // 4 L bumper
    // 5 R bumper
    // 6 Back (left center)
    // 7 Start (right center)
    // Axis 0 1 Left stick x y
    // Axis 2 triggers, left positive right negative
    // Axis 3 4 right stick x y
    const glm::vec3 moveDirsXboxController[8] = {
        glm::vec3( 0.f,  0.f,  1.f),
        glm::vec3( 1.f,  0.f,  0.f),
        glm::vec3(-1.f,  0.f,  0.f),
        glm::vec3( 0.f,  0.f, -1.f),
        glm::vec3( 0.f, -1.f,  0.f),
        glm::vec3( 0.f,  1.f,  0.f),
        glm::vec3( 0.f,  0.f,  0.f),
        glm::vec3( 0.f,  0.f,  0.f),
    };

    ///@todo Different mappings for different controllers.
    const glm::vec3* moveDirs = moveDirsGravisGamepadPro;
    // Take an educated guess that this is an Xbox controller - glfw's
    // id string says "Microsoft PC Joystick" for most gamepad types.
    if (numAxes == 5 && numButtons == 14)
    {
        moveDirs = moveDirsXboxController;
    }

    glm::vec3 joystickMove(0.0f, 0.0f, 0.0f);
    for (int i=0; i<std::min(8,numButtons); ++i)
    {
        if (pButtonStates[i] == GLFW_PRESS)
        {
            joystickMove += moveDirs[i];
        }
    }

    float mag = 1.f;
    if (numAxes > 2)
    {
        mag = pow(10.f, pAxisStates[2]);
    }
    g_app.m_joystickMove = mag * joystickMove;

    float x_move = pAxisStates[0];
    const float deadzone = 0.2f;
    if (fabs(x_move) < deadzone)
        x_move = 0.0f;
    g_app.m_joystickYaw = 0.5f * static_cast<float>(x_move);
}