Jump to content

Ultra Engine Player Input Features


Josh

2,888 views

 Share

There are three new features in the upcoming Ultra Engine (Leadwerks 5) that will make game input better than ever before.

High Precision Mouse Input

Raw mouse input measures the actual movement of the mouse device, and has nothing to do with a cursor on the screen. Windows provides an interface to capture the raw mouse input so your game can use mouse movement with greater precision than the screen pixels. The code to implement this is rather complicated, but in the end it just boils down to one simple command expose to the end user:

Vec2 Window::MouseMovement(const int dpi = 1000);

What's really hilarious about this feature is it actually makes mouse control code a lot simpler. For first-person controls, you just take the mouse movement value, and that is your camera rotation value. There's no need to calculate the center of the window or move the mouse pointer back to the middle. (You can if you want to, but it has no effect on the raw mouse input this command measures.)

The MousePosition() command is still available, but will return the integer coordinates the Windows mouse cursor system uses.

High Frequency Mouse Look

To enable ultra high-precision mouse look controls, I have added a new command:

void Camera::SetFreeLookMode(const bool mode, const float speed = 0.1f, const int smoothing = 0)

When this setting is enabled, the mouse movement will be queried in the rendering thread and applied to the camera rotation. That means real-time mouse looking at 1000 FPS is supported, even as the game thread is running at a slower frequency of 60 Hz. This was not possible in Leadwerks 4, as mouse looking would become erratic if it wasn't measured over a slower interval due to the limited precision of integer coordinates.

XBox Controller Input

I'm happy to say we will also have native built-in support for XBox controllers (both 360 and One versions). Here are the commands:

bool GamePadConnected(const int controller = 0)
bool GamePadButtonDown(const GamePadButton button, const int controller = 0)
bool GamePadButtonHit(const GamePadButton button, const int controller = 0)
Vec2 GamePadAxisPosition(const GamePadAxis axis, const int controller = 0)
void GamePadRumble(const float left, const float right, const int controller = 0)

To specify a button you use a button code:

GAMEPADBUTTON_DPADUP
GAMEPADBUTTON_DPADDOWN
GAMEPADBUTTON_DPADLEFT
GAMEPADBUTTON_DPADRIGHT
GAMEPADBUTTON_START
GAMEPADBUTTON_BACK
GAMEPADBUTTON_LTHUMB
GAMEPADBUTTON_RTHUMB
GAMEPADBUTTON_LSHOULDER
GAMEPADBUTTON_RSHOULDER
GAMEPADBUTTON_A
GAMEPADBUTTON_B
GAMEPADBUTTON_X
GAMEPADBUTTON_Y
GAMEPADBUTTON_RTRIGGER
GAMEPADBUTTON_LTRIGGER

And axes are specified with these codes:

GAMEPADAXIS_RTRIGGER
GAMEPADAXIS_LTRIGGER
GAMEPADAXIS_RSTICK
GAMEPADAXIS_LSTICK

These features will give your games new player options and a refined sense of movement and control.

  • Like 1
 Share

10 Comments


Recommended Comments

1 minute ago, Genebris said:

Don't you need to have your player movement in rendering thread as well then?

No, the camera orientation feeds back from the rendering thread to the main thread.

Link to comment
4 minutes ago, Genebris said:

I get the orientation part, but what about position? Is it interpolated? I don't want any smoothing or lags in my movement.

The mouse does not affect movement, except the direction you are looking will. There is going to be acceleration in the player movement anyways, so I don't think this is critical.

It's similar to the way we handle VR head tracking, where the headset orientation is detected in the rendering thread at the last possible moment before rendering a new frame.

Link to comment
14 minutes ago, Genebris said:

I assume main thread doesn't have to be locked at 60hz, right?

By default the main thread is running at a constant 60 Hz. This is good because it gives your game code a full 16 milliseconds to operate. There is an optional parameter that can be passed to the World::Update() method to change this, but I don't know any reason you would want to.

Link to comment
Quote

Raw mouse input measures the actual movement of the mouse device, and has nothing to do with a cursor on the screen. Windows provides an interface to capture the raw mouse input so your game can use mouse movement with greater precision than the screen pixels. The code to implement this is rather complicated, but in the end it just boils down to one simple command expose to the end user:

This is a good step into turning the mouse look into an axis which can be set via an action binding system. You can also make a multiplier value for sensitivity. Thanks.

Also, hopefully you got hold of an XInput device since the initial implementation of controller support. :)

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...