Support Forum G3D Web Page |
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... | |
OSWindow * | window () const |
Return the window used internally by the UserInput More... | |
Public Attributes | |
bool | useJoystick |
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.
G3D::UserInput::UserInput | ( | OSWindow * | window | ) |
|
virtual |
Closes the joystick if necessary.
bool G3D::UserInput::anyKeyPressed | ( | ) | const |
True if any key has been pressed since the last call to poll().
|
inline |
void G3D::UserInput::beginEvents | ( | ) |
Call before your OSWindow event polling loop.If you are using G3D::GApplet, this is handled for you.
void G3D::UserInput::endEvents | ( | ) |
Call after your OSWindow event polling loop.
If you are using G3D::GApplet, this is handled for you.
int G3D::UserInput::getNumJoysticks | ( | ) | const |
float G3D::UserInput::getX | ( | ) | const |
Returns a number between -1 and 1 indicating the horizontal input from the user.
Keyboard overrides joystick.
Vector2 G3D::UserInput::getXY | ( | ) | const |
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.
bool G3D::UserInput::keyDown | ( | GKey | code | ) | const |
Returns true iff the given key is currently held down.
bool G3D::UserInput::keyPressed | ( | GKey | code | ) | const |
Returns true if this key went down at least once since the last call to poll().
bool G3D::UserInput::keyReleased | ( | GKey | code | ) | const |
Returns true if this key came up since the last call to poll().
|
inline |
Physical joystick.
float G3D::UserInput::mouseDX | ( | ) | const |
Vector2 G3D::UserInput::mouseDXY | ( | ) | const |
float G3D::UserInput::mouseDY | ( | ) | const |
|
inline |
An array of all keys pressed since the last poll() call.
void G3D::UserInput::processEvent | ( | const GEvent & | event | ) |
Call from inside the event loop for every event inside processEvents() (done for you by App3D.processEvents())
bool G3D::UserInput::pureDeltaMouse | ( | ) | const |
|
inline |
Physical joystick.
|
inline |
Artificial latency to inject.
void G3D::UserInput::setKeyMapping | ( | Table< GKey, UIFunction > * | keyMapping = nullptr | ) |
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().
|
inline |
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.
|
inline |
Physical joystick.
Vector2 G3D::UserInput::virtualStick1 | ( | ) | const |
Arrow keys, WASD, or the left stick of the joystick mapped to [0, 1] along X and Y axes.
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.
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.
bool G3D::UserInput::useJoystick |