Support Forum       G3D Web Page     
Public Types | Public Member Functions | Public Attributes | List of all members
G3D::UserInput Class Reference


User input class that consolidates joystick, keyboard, and mouse state. More...

Public Types

enum  UIFunction {
  UP,
  DOWN,
  LEFT,
  RIGHT,
  NONE
}
 

Public Member Functions

 UserInput (OSWindow *window)
 
virtual ~UserInput ()
 
Closes the joystick if necessary. More...
 
bool anyKeyPressed () const
 
True if any key has been pressed since the last call to poll(). More...
 
float artificialLatency () const
 
void beginEvents ()
 
Call before your OSWindow event polling loop.If you are using G3D::GApplet, this is handled for you. More...
 
void endEvents ()
 
Call after your OSWindow event polling loop. More...
 
int getNumJoysticks () const
 
float getX () const
 
Returns a number between -1 and 1 indicating the horizontal input from the user. More...
 
Vector2 getXY () const
 
More...
 
float getY () const
 
Returns a number between -1 and 1 indicating the vertical input from the user. More...
 
bool keyDown (GKey code) const
 
Returns true iff the given key is currently held down. More...
 
bool keyPressed (GKey code) const
 
Returns true if this key went down at least once since the last call to poll(). More...
 
bool keyReleased (GKey code) const
 
Returns true if this key came up since the last call to poll(). More...
 
Vector2 leftStick () const
 Physical joystick. More...
 
float mouseDX () const
 
Vector2 mouseDXY () const
 
float mouseDY () const
 
Vector2 mouseXY () const
 
void pressedKeys (Array< GKey > &code) const
 An array of all keys pressed since the last poll() call. More...
 
void processEvent (const GEvent &event)
 
Call from inside the event loop for every event inside processEvents() (done for you by App3D.processEvents()) More...
 
bool pureDeltaMouse () const
 
void releasedKeys (Array< GKey > &code) const
 
Vector2 rightStick () const
 Physical joystick. More...
 
void setArtificialLatency (float delaySeconds)
 Artificial latency to inject. More...
 
void setKeyMapping (Table< GKey, UIFunction > *keyMapping=nullptr)
 
void setMouseXY (float x, float y)
 
Sets the mouse position. More...
 
void setMouseXY (const Vector2 &v)
 
void setPureDeltaMouse (bool m)
 
When set to true, the mouse cursor is invisible and the mouse is restricted to the current window. More...
 
Vector2 triggerStick () const
 Physical joystick. More...
 
Vector2 virtualStick1 () const
 Arrow keys, WASD, or the left stick of the joystick mapped to [0, 1] along X and Y axes. More...
 
Vector2 virtualStick2 () const
 Mouse dx, dy, Q and E, or the right stick of the joystick mapped to [0, 1] along the X and Y axes. More...
 
Vector2 virtualStick3 () const
 The 5th and 6th analog axes on a controller, for trigger buttons. More...
 
OSWindowwindow () const
 
Return the window used internally by the UserInput More...
 

Public Attributes

bool useJoystick
 

Detailed Description


User input class that consolidates joystick, keyboard, and mouse state.

Four axes are supported directly: joystick/keyboard x and y and mouse x and y. Mouse buttons, joystick buttons, and keyboard keys can all be used as 'keys' in the UserInput class.

Call beginEvents() immediately before your SDL event handling routine and hand events to processEvent() as they become available. Call endEvents() immediately after the loop.

See also
G3D::GEvent, G3D::GApp::onEvent, G3D::OSWindow

Member Enumeration Documentation

◆ UIFunction

Enumerator
UP 
DOWN 
LEFT 
RIGHT 
NONE 

Constructor & Destructor Documentation

◆ UserInput()

G3D::UserInput::UserInput ( OSWindow window)

◆ ~UserInput()

virtual G3D::UserInput::~UserInput ( )
virtual


Closes the joystick if necessary.

Member Function Documentation

◆ anyKeyPressed()

bool G3D::UserInput::anyKeyPressed ( ) const


True if any key has been pressed since the last call to poll().

◆ artificialLatency()

float G3D::UserInput::artificialLatency ( ) const
inline

◆ beginEvents()

void G3D::UserInput::beginEvents ( )


Call before your OSWindow event polling loop.If you are using G3D::GApplet, this is handled for you.

◆ endEvents()

void G3D::UserInput::endEvents ( )


Call after your OSWindow event polling loop.

If you are using G3D::GApplet, this is handled for you.

◆ getNumJoysticks()

int G3D::UserInput::getNumJoysticks ( ) const

◆ getX()

float G3D::UserInput::getX ( ) const


Returns a number between -1 and 1 indicating the horizontal input from the user.

Keyboard overrides joystick.

Deprecated:

◆ getXY()

Vector2 G3D::UserInput::getXY ( ) const

◆ getY()

float G3D::UserInput::getY ( ) const


Returns a number between -1 and 1 indicating the vertical input from the user.

Up is positive, down is negative. Keyboard overrides joystick.

Deprecated:

◆ keyDown()

bool G3D::UserInput::keyDown ( GKey  code) const


Returns true iff the given key is currently held down.

◆ keyPressed()

bool G3D::UserInput::keyPressed ( GKey  code) const


Returns true if this key went down at least once since the last call to poll().

◆ keyReleased()

bool G3D::UserInput::keyReleased ( GKey  code) const


Returns true if this key came up since the last call to poll().

◆ leftStick()

Vector2 G3D::UserInput::leftStick ( ) const
inline

Physical joystick.

See also
virtualStick1

◆ mouseDX()

float G3D::UserInput::mouseDX ( ) const

◆ mouseDXY()

Vector2 G3D::UserInput::mouseDXY ( ) const

◆ mouseDY()

float G3D::UserInput::mouseDY ( ) const

◆ mouseXY()

Vector2 G3D::UserInput::mouseXY ( ) const
inline

◆ pressedKeys()

void G3D::UserInput::pressedKeys ( Array< GKey > &  code) const

An array of all keys pressed since the last poll() call.

◆ processEvent()

void G3D::UserInput::processEvent ( const GEvent event)


Call from inside the event loop for every event inside processEvents() (done for you by App3D.processEvents())

◆ pureDeltaMouse()

bool G3D::UserInput::pureDeltaMouse ( ) const

◆ releasedKeys()

void G3D::UserInput::releasedKeys ( Array< GKey > &  code) const

◆ rightStick()

Vector2 G3D::UserInput::rightStick ( ) const
inline

Physical joystick.

See also
virtualStick2

◆ setArtificialLatency()

void G3D::UserInput::setArtificialLatency ( float  delaySeconds)
inline

Artificial latency to inject.

◆ setKeyMapping()

void G3D::UserInput::setKeyMapping ( Table< GKey, UIFunction > *  keyMapping = nullptr)

◆ setMouseXY() [1/2]

void G3D::UserInput::setMouseXY ( float  x,
float  y 
)


Sets the mouse position.

That new position will be returned by getMouseXY until the next endEvents() statement.

Referenced by setMouseXY().

◆ setMouseXY() [2/2]

void G3D::UserInput::setMouseXY ( const Vector2 v)
inline

◆ setPureDeltaMouse()

void G3D::UserInput::setPureDeltaMouse ( bool  m)


When set to true, the mouse cursor is invisible and the mouse is restricted to the current window.

Regardless of how far the user moves the mouse in one direction, continous mouseDXY values are returned.
The mouseXY values are not particularly useful in this mode.

This setting is commonly used by first-person games.

When the app loses focus the mouse is automatically freed and recaptured when focus returns. debugBreak also frees the mouse.

◆ triggerStick()

Vector2 G3D::UserInput::triggerStick ( ) const
inline

Physical joystick.

See also
virtualStick3

◆ virtualStick1()

Vector2 G3D::UserInput::virtualStick1 ( ) const

Arrow keys, WASD, or the left stick of the joystick mapped to [0, 1] along X and Y axes.

◆ virtualStick2()

Vector2 G3D::UserInput::virtualStick2 ( ) const

Mouse dx, dy, Q and E, or the right stick of the joystick mapped to [0, 1] along the X and Y axes.

There is no default keyboard rotate up/down mapping.

◆ virtualStick3()

Vector2 G3D::UserInput::virtualStick3 ( ) const

The 5th and 6th analog axes on a controller, for trigger buttons.

Left trigger is 'x' and right trigger is 'y'. Note the default state for each is -1, pressing makes them 1.

◆ window()

OSWindow* G3D::UserInput::window ( ) const


Return the window used internally by the UserInput

Member Data Documentation

◆ useJoystick

bool G3D::UserInput::useJoystick

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