Support Forum G3D Web Page |
Platform-independent tracking of input from an Xbox360 controller.
More...
Inherits G3D::Widget.
Classes | |
class | Button |
class | Stick |
Public Member Functions | |
float | angleDelta (JoystickIndex s) const |
Returns the counter-clockwise angle in radians that the stick has rotated through between the last two calls to onAfterEvents. More... | |
virtual Rect2D | bounds () const override |
Inherited from Surface2D. More... | |
bool | currentlyDown (GKey k) const |
Returns true if this controller button was held down as of the last onAfterEvents call. More... | |
Vector2 | delta (JoystickIndex s) const |
Change in position of an analog stick between the previous two calls to onAfterEvents. More... | |
virtual float | depth () const override |
Inherited from Surface2D. More... | |
virtual void | fireEvent (const GEvent &event) |
Fire an event on the containing window. More... | |
bool | justPressed (GKey k) const |
Returns true if this controller button was pressed between the last two calls of onAfterEvents. More... | |
bool | justReleased (GKey k) const |
Returns true if this controller button was released between the last two calls of onAfterEvents. More... | |
WidgetManager * | manager () const |
virtual void | onAfterEvents () override |
Latches the state of the controller. More... | |
virtual void | onAI () |
virtual void | onBeforeGraphics () |
Invoked by WidgetManager immediately before GApp::onGraphics runs. More... | |
virtual bool | onEvent (const GEvent &event) |
Returning true consumes the event and prevents other GModules from seeing it. More... | |
virtual void | onNetwork () |
virtual void | onPose (Array< shared_ptr< Surface > > &surfaceArray, Array< shared_ptr< Surface2D > > &surface2DArray) |
Appends a posed model for this object to the array, if it has a graphic representation. More... | |
virtual void | onSimulation (RealTime rdt, SimTime sdt, SimTime idt) |
virtual void | onUserInput (UserInput *ui) |
Vector2 | position (JoystickIndex s) const |
Position of an analog stick as of onAfterEvents. More... | |
virtual float | positionalEventZ (const Point2 &pixel) const |
The camera-space z position that this Widget considers this pixel to be at. More... | |
bool | present () const |
True if this controller is connected and appears to actually be an Xbox360 controller. More... | |
virtual void | render (RenderDevice *rd) const override |
Inherited from Surface2D. More... | |
virtual void | setDepth (float d) |
Called by the WidgetManager. More... | |
virtual void | setManager (WidgetManager *m) override |
Called by the WidgetManager when this module is added to it. More... | |
virtual OSWindow * | window () const |
Returns the operating system window that is currently rendering this Widget. More... | |
Static Public Member Functions | |
static shared_ptr< GameController > | create (unsigned int joystickNumber) |
static void | sort (Array< shared_ptr< Surface2D >> &array) |
Sorts from farthest to nearest. More... | |
static void | sortAndRender (RenderDevice *rd, Array< shared_ptr< Surface2D >> &array) |
Calls sort, RenderDevice::push2D, and then render on all elements. More... | |
Protected Types | |
enum | { NUM_STICKS = 6, NUM_BUTTONS = GKey::CONTROLLER_GUIDE - GKey::CONTROLLER_A + 1 } |
Protected Member Functions | |
GameController (unsigned int n) | |
Button & | button (GKey k) |
Performs range checking. More... | |
const Button & | button (GKey k) const |
const Stick & | stick (JoystickIndex) const |
Performs range checking. More... | |
Static Protected Member Functions | |
template<class T , class ... ArgTypes> | |
static shared_ptr< T > | createShared (ArgTypes &&... args) |
Like std::make_shared, but works for protected constructors. More... | |
Protected Attributes | |
Button | m_buttonArray [NUM_BUTTONS] |
State of the buttons, where index = k - GKey::CONTROLLER_A More... | |
float | m_depth |
unsigned int | m_joystickNumber |
WidgetManager * | m_manager |
The manager, set by setManager(). More... | |
bool | m_present |
Stick | m_stickArray [NUM_STICKS] |
Platform-independent tracking of input from an Xbox360 controller.
The Xbox360 controller has become the de facto standard PC controller and merits special support in G3D. Unforuntately, the controller's axes and buttons are mapped differently on Windows and OS X by the underlying drivers. This class provides a uniform interface.
A reliable open source OS X driver for the Xbox360/XboxOne controller is available from https://github.com/360Controller/360Controller/releases and a Wireless Gaming Receiver for Windows is available from http://tattiebogle.net/index.php/ProjectRoot/GameController/OsxDriver
There is no hardware difference between the "Xbox360 controller for Windows" by Microsoft and the "Xbox360 controller" that ships for the console itself. However, third party controllers may not work with the Microsoft driver for Windows. A driver that the G3D team has used successfully with these controllers is available (with source) at: http://vba-m.com/forum/Thread-xbcd-0-2-7-release-info-updates-will-be-posted-here (follow the installation instructions carefully).
On Windows, the left and right trigger buttons are mapped to the same axis due to a strange underlying API choice by Microsoft in their own driver and DirectInput 8.
The newer XInput API supports the axes correctly, and force feedback. Since G3D 9.0, G3D uses the GLFW library for access to the joystick. G3D will provide independent access to the triggers when the GLFW project adds support for XInput.
|
inlineprotected |
float G3D::GameController::angleDelta | ( | JoystickIndex | s | ) | const |
Returns the counter-clockwise angle in radians that the stick has rotated through between the last two calls to onAfterEvents.
This is zero if the stick position had magnitude less than 0.20 during the frame. Useful for gesture-based input, such as the spray-painting swipes in Jet Grind Radio.
|
inlineoverridevirtualinherited |
Inherited from Surface2D.
Implements G3D::Surface2D.
Reimplemented in G3D::GuiWindow, G3D::GConsole, and G3D::FullScreenWidget.
Performs range checking.
Referenced by button(), currentlyDown(), justPressed(), and justReleased().
|
inlinestatic |
|
inlinestaticprotectedinherited |
Like std::make_shared, but works for protected constructors.
Call as createShared<myclass>.
|
inline |
Returns true if this controller button was held down as of the last onAfterEvents call.
Supports GKey::CONTROLLER_A through GKey::CONTROLLER_GUIDE.
|
inline |
Change in position of an analog stick between the previous two calls to onAfterEvents.
|
inlineoverridevirtualinherited |
Inherited from Surface2D.
Controls the depth of objects when rendering. Subclasses may override this but it can interfere with the normal handling of rendering and event delivery. depth = 0 is usually the "top" widget and depth = 1 is usually the "bottom" widget.
Implements G3D::Surface2D.
Reimplemented in G3D::GuiWindow, G3D::GConsole, and G3D::FullScreenWidget.
|
virtualinherited |
Fire an event on the containing window.
Reimplemented in G3D::WidgetManager.
|
inline |
Returns true if this controller button was pressed between the last two calls of onAfterEvents.
Supports GKey::CONTROLLER_A through GKey::CONTROLLER_GUIDE.
|
inline |
Returns true if this controller button was released between the last two calls of onAfterEvents.
Supports GKey::CONTROLLER_A through GKey::CONTROLLER_GUIDE.
|
inlineinherited |
|
overridevirtual |
Latches the state of the controller.
Reimplemented from G3D::Widget.
|
inlinevirtualinherited |
|
inlinevirtualinherited |
Invoked by WidgetManager immediately before GApp::onGraphics runs.
Reimplemented in G3D::WidgetManager, G3D::CallbackWidget, and G3D::XRWidget.
|
inlinevirtualinherited |
Returning true consumes the event and prevents other GModules from seeing it.
Motion events (GEventType::MOUSEMOTION, GEventType::JOYHATMOTION, JGEventType::OYBALLMOTION, and GEventType::JOYAXISMOTION) cannot be cancelled.
Reimplemented in G3D::GuiWindow, G3D::WidgetManager, G3D::ThirdPersonManipulator, G3D::GConsole, G3D::Discovery::Client, G3D::SceneEditorWindow, G3D::FirstPersonManipulator, G3D::VideoRecordDialog, G3D::UprightSplineManipulator, G3D::CameraControlWindow, G3D::GuiMenu, G3D::ControlPointEditor, G3D::DeveloperWindow, and G3D::ArticulatedModelSpecificationEditorDialog.
|
inlinevirtualinherited |
|
inlinevirtualinherited |
Appends a posed model for this object to the array, if it has a graphic representation.
The posed model appended is allowed to reference the agent and is allowed to mutate if the agent is mutated.
Reimplemented in G3D::GuiWindow, G3D::WidgetManager, G3D::Discovery::Client, G3D::SceneEditorWindow, G3D::CallbackWidget, G3D::FullScreenWidget, G3D::UprightSplineManipulator, and G3D::ControlPointEditor.
|
inlinevirtualinherited |
|
inline |
Position of an analog stick as of onAfterEvents.
|
inlinevirtualinherited |
The camera-space z position that this Widget considers this pixel to be at.
Used for positional event (e.g., mouse click) delivery. Higher means closer.
Large negative values are far away. 0 is the closest 3D object. Values greater than zero are used for 2D objects. Returning fnan() [the default] requests the WidgetManager to set hte positionalEventZ to the object's normal event zorder.
See the implementation of ControlPointEditor::positionalEventZ for an example of how to use this with a 3D object.
Reimplemented in G3D::ControlPointEditor.
|
inline |
True if this controller is connected and appears to actually be an Xbox360 controller.
|
inlineoverridevirtualinherited |
Inherited from Surface2D.
Implements G3D::Surface2D.
Reimplemented in G3D::GConsole, G3D::GuiWindow, G3D::GuiMenu, and G3D::DebugTextWidget.
|
inlinevirtualinherited |
Called by the WidgetManager.
This is the depth that the Widget is expected to use when posed as a Surface2D. Subclasses may override or ignore this but it can interfere with the normal handling of rendering.
|
overridevirtual |
Called by the WidgetManager when this module is added to it.
The argument may be nullptr
Reimplemented from G3D::Widget.
Sorts from farthest to nearest.
|
staticinherited |
Calls sort, RenderDevice::push2D, and then render on all elements.
|
protected |
Performs range checking.
Referenced by delta(), and position().
|
virtualinherited |
Returns the operating system window that is currently rendering this Widget.
Reimplemented in G3D::WidgetManager.
Referenced by G3D::FullScreenWidget::bounds().
|
protected |
State of the buttons, where index = k - GKey::CONTROLLER_A
|
protectedinherited |
Referenced by G3D::Widget::depth(), and G3D::Widget::setDepth().
|
protected |
|
protectedinherited |
The manager, set by setManager().
This cannot be a reference counted pointer because that would create a cycle between the Widget and its manager.
Referenced by G3D::Widget::manager(), G3D::GuiWindow::manager(), G3D::Widget::setManager(), and G3D::GuiWindow::setVisible().
|
protected |
Referenced by present().
|
protected |