Angel 3.2
A 2D Game Prototyping Engine
Public Member Functions | Static Protected Attributes | Friends | List of all members
Controller Class Reference

A class representing a gamepad controller. More...

#include <Controller.h>

Public Member Functions

void Setup ()
 
void UpdateState ()
 
const ControllerInput GetState ()
 
const Vector2 GetLeftThumbVec2 ()
 
const Vector2 GetRightThumbVec2 ()
 
const Vec2i GetLeftThumbstick ()
 
const Vec2i GetRightThumbstick ()
 
const int GetRightTrigger ()
 
const int GetLeftTrigger ()
 
const bool IsButtonDown (int buttonMask)
 
const bool IsAButtonDown ()
 
const bool IsBButtonDown ()
 
const bool IsXButtonDown ()
 
const bool IsYButtonDown ()
 
const bool IsLeftThumbstickButtonDown ()
 
const bool IsRightThumbstickButtonDown ()
 
const bool IsStartButtonDown ()
 
const bool IsBackButtonDown ()
 
const bool IsLeftBumperDown ()
 
const bool IsRightBumperDown ()
 
const bool IsLeftTriggerPressed ()
 
const bool IsRightTriggerPressed ()
 
void SetLeftVibrationRaw (unsigned int vibration)
 
void SetRightVibrationRaw (unsigned int vibration)
 
void SetLeftVibration (unsigned int vibration)
 
void SetRightVibration (unsigned int vibration)
 
const unsigned int GetLeftVibration ()
 
const unsigned int GetRightVibration ()
 
const bool IsConnected ()
 
const int GetControllerID ()
 

Static Protected Attributes

static Controllers_Controller = NULL
 

Friends

class ControllerManager
 

Detailed Description

This class is your means of getting data from a controller. At the moment we only test and support the Xbox 360 controller over USB, but this interface could be abstracted to support other controllers.

On Windows you'll need DirectX installed to play a game made with Angel, and the DirectX SDK to develop one. A pretty big download/install just to get access to a controller, but we figure most gamers/developers have already done so anyway.

On the Mac both players and developers need to install a kernel extension (sorry!) included in the Tools directory. We'd be more than happy to remove this requirement, but unless someone who knows more about how to use IOKit and raw USB values wants to help, this is what we've got.

Definition at line 168 of file Controller.h.

Member Function Documentation

void Controller::Setup ( )

Sets the controller up to read data every frame. If it's successful, the Controller::IsConnected function will return true.

Definition at line 139 of file Controller.cpp.

void Controller::UpdateState ( )

Called once per frame to read the data in from the controller. Called automatically by the ControllerManager.

Definition at line 302 of file Controller.cpp.

const ControllerInput Controller::GetState ( )

Directly access all current input on the controller.

Returns
The current input data from the buttons and thumbsticks of this controller.

Definition at line 502 of file Controller.cpp.

const Vector2 Controller::GetLeftThumbVec2 ( )

Get the X and Y positions of the left thumbstick as a Vector2.

Returns
The current direction of the left thumbstick, as a Vector2 with both dimensions ranging from -1.0 to 1.0.

Definition at line 507 of file Controller.cpp.

const Vector2 Controller::GetRightThumbVec2 ( )

Get the X and Y positions of the right thumbstick as a Vector2.

Returns
The current direction of the right thumbstick, as a Vector2 with both dimensions ranging from -1.0 to 1.0.

Definition at line 515 of file Controller.cpp.

const Vec2i Controller::GetLeftThumbstick ( )

Get the raw values of the left thumbstick as an integer vector.

Returns
The current raw values of the left thumbstick, with both X and Y ranging from -32768 to 32768.

Definition at line 523 of file Controller.cpp.

const Vec2i Controller::GetRightThumbstick ( )

Get the raw values of the right thumbstick as an integer vector.

Returns
The current raw values of the right thumbstick, with both X and Y ranging from -32768 to 32768.

Definition at line 530 of file Controller.cpp.

const int Controller::GetRightTrigger ( )

Get the current value of the right trigger.

Returns
How much the right analog trigger is pressed, ranging from 0 (untouched) to 255 (all the way down).

Definition at line 538 of file Controller.cpp.

const int Controller::GetLeftTrigger ( )

Get the current value of the left trigger.

Returns
How much the left analog trigger is pressed, ranging from 0 (untouched) to 255 (all the way down).

Definition at line 543 of file Controller.cpp.

const bool Controller::IsButtonDown ( int  buttonMask)

Pass a button mask to find out if a combination of buttons is depressed at the same time. Here are the mask values:

#define XINPUT_GAMEPAD_DPAD_UP 0x00000001
#define XINPUT_GAMEPAD_DPAD_DOWN 0x00000002
#define XINPUT_GAMEPAD_DPAD_LEFT 0x00000004
#define XINPUT_GAMEPAD_DPAD_RIGHT 0x00000008
#define XINPUT_GAMEPAD_START 0x00000010
#define XINPUT_GAMEPAD_BACK 0x00000020
#define XINPUT_GAMEPAD_LEFT_THUMB 0x00000040
#define XINPUT_GAMEPAD_RIGHT_THUMB 0x00000080
#define XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100
#define XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200
#define XINPUT_GAMEPAD_A 0x1000
#define XINPUT_GAMEPAD_B 0x2000
#define XINPUT_GAMEPAD_X 0x4000
#define XINPUT_GAMEPAD_Y 0x8000
Parameters
buttonMaskThe values you care about, combined as a bitmask
Returns
True if all the masked buttons are pressed, false if they're not

Definition at line 548 of file Controller.cpp.

const bool Controller::IsAButtonDown ( )

Find out if the A button is currently pressed.

Returns
True if it is, false if it's not.

Definition at line 553 of file Controller.cpp.

const bool Controller::IsBButtonDown ( )

Find out if the B button is currently pressed.

Returns
True if it is, false if it's not.

Definition at line 565 of file Controller.cpp.

const bool Controller::IsXButtonDown ( )

Find out if the X button is currently pressed.

Returns
True if it is, false if it's not.

Definition at line 577 of file Controller.cpp.

const bool Controller::IsYButtonDown ( )

Find out if the Y button is currently pressed.

Returns
True if it is, false if it's not.

Definition at line 589 of file Controller.cpp.

const bool Controller::IsLeftThumbstickButtonDown ( )

Find out if the left thumbstick is currently pressed down.

Returns
True if it is, false if it's not.

Definition at line 601 of file Controller.cpp.

const bool Controller::IsRightThumbstickButtonDown ( )

Find out if the right thumbstick is currently pressed down.

Returns
True if it is, false if it's not.

Definition at line 613 of file Controller.cpp.

const bool Controller::IsStartButtonDown ( )

Find out if the start button is currently pressed.

Returns
True if it is, false if it's not.

Definition at line 625 of file Controller.cpp.

const bool Controller::IsBackButtonDown ( )

Find out if the back button is currently pressed.

Returns
True if it is, false if it's not.

Definition at line 637 of file Controller.cpp.

const bool Controller::IsLeftBumperDown ( )

Find out if the left shoulder button is currently pressed.

Returns
True if it is, false if it's not.

Definition at line 649 of file Controller.cpp.

const bool Controller::IsRightBumperDown ( )

Find out if the right shoulder button is currently pressed.

Returns
True if it is, false if it's not.

Definition at line 661 of file Controller.cpp.

const bool Controller::IsLeftTriggerPressed ( )

Find out if the left trigger is pressed down. Since it's an analog trigger, there's a driver-defined threshold that this function will use to determine when it can be considered "activated."

Returns
True if it is, false if it's not.

Definition at line 673 of file Controller.cpp.

const bool Controller::IsRightTriggerPressed ( )

Find out if the left trigger is pressed down. Since it's an analog trigger, there's a driver-defined threshold that this function will use to determine when it can be considered "activated."

Returns
True if it is, false if it's not.

Definition at line 685 of file Controller.cpp.

void Controller::SetLeftVibrationRaw ( unsigned int  vibration)

Set the rumble of the controller's lower frequencies. This sets the raw driver value.

Not available on Mac OS X. :-(

Parameters
frequenciesThe desired intensity, ranging from 0 to 65535.

Definition at line 708 of file Controller.cpp.

void Controller::SetRightVibrationRaw ( unsigned int  vibration)

Set the rumble of the controller's higher frequencies. This sets the raw driver value.

Not available on Mac OS X. :-(

Parameters
frequenciesThe desired intensity, ranging from 0 to 65535.

Definition at line 734 of file Controller.cpp.

void Controller::SetLeftVibration ( unsigned int  vibration)

Set the rumble of the controller's lower frequencies. This uses more manageable numbers if you don't feel like dealing with INT_MAX.

Not available on Mac OS X. :-(

Parameters
frequenciesThe desired intensity, ranging from 0 to 255.

Definition at line 760 of file Controller.cpp.

void Controller::SetRightVibration ( unsigned int  vibration)

Set the rumble of the controller's higher frequencies. This uses more manageable numbers if you don't feel like dealing with INT_MAX.

Not available on Mac OS X. :-(

Parameters
frequenciesThe desired intensity, ranging from 0 to 255.

Definition at line 773 of file Controller.cpp.

const unsigned int Controller::GetLeftVibration ( )

Get the current vibration setting for the lower frequencies.

Returns
Current intensity, ranging from 0 to 65535.

Definition at line 698 of file Controller.cpp.

const unsigned int Controller::GetRightVibration ( )

Get the current vibration setting for the higher frequencies.

Returns
Current intensity, ranging from 0 to 65535.

Definition at line 703 of file Controller.cpp.

const bool Controller::IsConnected ( )
inline

Find out if this controller object is currently mapped to a real-world controller and receiving input.

Returns
True if this controller gets input

Definition at line 419 of file Controller.h.

const int Controller::GetControllerID ( )
inline

Get the index this controller corresponds to in the ControllerManager.

Returns
The index that can be used in ControllerManager::GetController

Definition at line 426 of file Controller.h.


The documentation for this class was generated from the following files: