Support Forum       G3D Web Page     
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
G3D::GameController Class Reference


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...
 
WidgetManagermanager () 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 OSWindowwindow () const
 Returns the operating system window that is currently rendering this Widget. More...
 

Static Public Member Functions

static shared_ptr< GameControllercreate (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)
 
Buttonbutton (GKey k)
 Performs range checking. More...
 
const Buttonbutton (GKey k) const
 
const Stickstick (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
 
WidgetManagerm_manager
 The manager, set by setManager(). More...
 
bool m_present
 
Stick m_stickArray [NUM_STICKS]
 

Detailed Description


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.

See also
UserInput, UserInput::virtualStick1, OSWindow::getJoystickState

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
NUM_STICKS 
NUM_BUTTONS 

Constructor & Destructor Documentation

◆ GameController()

G3D::GameController::GameController ( unsigned int  n)
inlineprotected

Member Function Documentation

◆ angleDelta()

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.

◆ bounds()

virtual Rect2D G3D::Widget::bounds ( ) const
inlineoverridevirtualinherited

Inherited from Surface2D.

Implements G3D::Surface2D.

Reimplemented in G3D::GuiWindow, G3D::GConsole, and G3D::FullScreenWidget.

◆ button() [1/2]

Button& G3D::GameController::button ( GKey  k)
protected

Performs range checking.

Referenced by button(), currentlyDown(), justPressed(), and justReleased().

◆ button() [2/2]

const Button& G3D::GameController::button ( GKey  k) const
inlineprotected

◆ create()

static shared_ptr<GameController> G3D::GameController::create ( unsigned int  joystickNumber)
inlinestatic

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ currentlyDown()

bool G3D::GameController::currentlyDown ( GKey  k) const
inline

Returns true if this controller button was held down as of the last onAfterEvents call.

Supports GKey::CONTROLLER_A through GKey::CONTROLLER_GUIDE.

◆ delta()

Vector2 G3D::GameController::delta ( JoystickIndex  s) const
inline

Change in position of an analog stick between the previous two calls to onAfterEvents.

◆ depth()

virtual float G3D::Widget::depth ( ) const
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.

◆ fireEvent()

virtual void G3D::Widget::fireEvent ( const GEvent event)
virtualinherited

Fire an event on the containing window.

Reimplemented in G3D::WidgetManager.

◆ justPressed()

bool G3D::GameController::justPressed ( GKey  k) const
inline

Returns true if this controller button was pressed between the last two calls of onAfterEvents.

Supports GKey::CONTROLLER_A through GKey::CONTROLLER_GUIDE.

◆ justReleased()

bool G3D::GameController::justReleased ( GKey  k) const
inline

Returns true if this controller button was released between the last two calls of onAfterEvents.

Supports GKey::CONTROLLER_A through GKey::CONTROLLER_GUIDE.

◆ manager()

WidgetManager* G3D::Widget::manager ( ) const
inlineinherited

◆ onAfterEvents()

virtual void G3D::GameController::onAfterEvents ( )
overridevirtual

Latches the state of the controller.

Reimplemented from G3D::Widget.

◆ onAI()

virtual void G3D::Widget::onAI ( )
inlinevirtualinherited

◆ onBeforeGraphics()

virtual void G3D::Widget::onBeforeGraphics ( )
inlinevirtualinherited

Invoked by WidgetManager immediately before GApp::onGraphics runs.

Reimplemented in G3D::WidgetManager, G3D::CallbackWidget, and G3D::XRWidget.

◆ onEvent()

virtual bool G3D::Widget::onEvent ( const GEvent event)
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.

◆ onNetwork()

virtual void G3D::Widget::onNetwork ( )
inlinevirtualinherited

◆ onPose()

virtual void G3D::Widget::onPose ( Array< shared_ptr< Surface > > &  surfaceArray,
Array< shared_ptr< Surface2D > > &  surface2DArray 
)
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.

◆ onSimulation()

virtual void G3D::Widget::onSimulation ( RealTime  rdt,
SimTime  sdt,
SimTime  idt 
)
inlinevirtualinherited

◆ onUserInput()

virtual void G3D::Widget::onUserInput ( UserInput ui)
inlinevirtualinherited

◆ position()

Vector2 G3D::GameController::position ( JoystickIndex  s) const
inline

Position of an analog stick as of onAfterEvents.

◆ positionalEventZ()

virtual float G3D::Widget::positionalEventZ ( const Point2 pixel) const
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.

◆ present()

bool G3D::GameController::present ( ) const
inline

True if this controller is connected and appears to actually be an Xbox360 controller.

◆ render()

virtual void G3D::Widget::render ( RenderDevice rd) const
inlineoverridevirtualinherited

Inherited from Surface2D.

Implements G3D::Surface2D.

Reimplemented in G3D::GConsole, G3D::GuiWindow, G3D::GuiMenu, and G3D::DebugTextWidget.

◆ setDepth()

virtual void G3D::Widget::setDepth ( float  d)
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.

◆ setManager()

virtual void G3D::GameController::setManager ( WidgetManager m)
overridevirtual

Called by the WidgetManager when this module is added to it.

The argument may be nullptr

Reimplemented from G3D::Widget.

◆ sort()

static void G3D::Surface2D::sort ( Array< shared_ptr< Surface2D >> &  array)
staticinherited

Sorts from farthest to nearest.

◆ sortAndRender()

static void G3D::Surface2D::sortAndRender ( RenderDevice rd,
Array< shared_ptr< Surface2D >> &  array 
)
staticinherited

Calls sort, RenderDevice::push2D, and then render on all elements.

◆ stick()

const Stick& G3D::GameController::stick ( JoystickIndex  ) const
protected

Performs range checking.

Referenced by delta(), and position().

◆ window()

virtual OSWindow* G3D::Widget::window ( ) const
virtualinherited

Returns the operating system window that is currently rendering this Widget.

Reimplemented in G3D::WidgetManager.

Referenced by G3D::FullScreenWidget::bounds().

Member Data Documentation

◆ m_buttonArray

Button G3D::GameController::m_buttonArray[NUM_BUTTONS]
protected

State of the buttons, where index = k - GKey::CONTROLLER_A

◆ m_depth

float G3D::Widget::m_depth
protectedinherited

◆ m_joystickNumber

unsigned int G3D::GameController::m_joystickNumber
protected

◆ m_manager

WidgetManager* G3D::Widget::m_manager
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().

◆ m_present

bool G3D::GameController::m_present
protected

Referenced by present().

◆ m_stickArray

Stick G3D::GameController::m_stickArray[NUM_STICKS]
protected

documentation generated on Wed Nov 24 2021 08:01:55 using doxygen 1.8.15