Git Product home page Git Product logo

xbox360-gamepad-support's Introduction

XBOX360 Gamepad Support

IT SUPPORTS THE MYSTERIOUS GUIDE BUTTON!

It is a Gamepad class for getting input from XBOX 360 controller (it uses windows.h and Xinput, so it requires Windows (:D) and DirectX 9 SDK (or higher).

Usage

  Gamepad gamepad(0); // 0 is pad's ID - we can support up to 4 pads with id's 0, 1, 2, 3
  
  while (gamepad.connected()) // you don't really have to check for it,
                              // while (true) works well even if there
                              // is no controller
  {
    gamepad.update();
    
    ...
    ...
    ...
  }

Getting analog values (returns [-1, 1]):

  float walkX = gamepad.leftStick().x;
  float walkY = gamepad.leftStick().y;
  
  float lookX = gamepad.rightStick().x;
  float lookY = gamepad.rightStick().y;
  
  float doSthElseX = gamepad.dPad().x;
  float doSthElseY = gamepad.dPad().y;
  
  // you can also check for analog being in it's DEADZONE,
  // but it will still return { 0.0f, 0.0f } if so
  // if you really want to check for deadzone, do the following:
  
  if (!gamepad.leftStick().dead)
  {
    // perform some expensive code
  }

Getting trigger values (returns [0, 1]):

  float rt = gamepad.rightTrigger();
  float lt = gamepad.leftTrigger();

Getting button state (returns {0, 1}):

  // same for B, X, Y, RB, LB, RightStick, LeftStick, Start, Back and the Guide button
  int valueOfA = gamepad.button(Gamepad::Button::A);
  
  int dPadRight = gamepad.button(Gamepad::DPad::Right);

(returns {true, false}):

  // returns true only once - when A was just pressed
  gamepad.buttonDown(Gamepad::Button::A);
  // returns true if A is being pressed
  gamepad.buttonPressed(Gamepad::Button::A);
  // returns true only in the frame in which A was released
  gamepad.buttonUp(Gamepad::Button::A);

Vibrations (Rumble):

  float leftVibration = 0.75f; // should be from [0, 1]
  float rightVibration = 0.4f; // should be from [0, 1]
  gamepad.vibrate(leftVibration, rightVibration);

xbox360-gamepad-support's People

Contributors

daltondotgd avatar

Watchers

James Cloos avatar  avatar Peter avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.