Copperfield Engine 0.1
C++ Game Engine
Loading...
Searching...
No Matches
InputManager Class Reference

Interface to retrieve keyboard and mouse input. More...

#include <input.hpp>

Public Member Functions

 InputManager (const Window &window, InputButtonMap input_button_map)
 Creates and binds an input map. More...
 
void setCursorMode (CursorMode mode) const
 Overrides the CursorMode of the Window. More...
 
void toggleCursor () const
 Alternates the CursorMode between Normal and Disabled. More...
 
bool buttonDown (const std::string &action) const
 Checks if any of the buttons assigned to an action have been pressed during the frame. More...
 
bool buttonUp (const std::string &action) const
 Checks if any of the buttons assigned to an action have been released during the frame. More...
 
bool buttonPressed (const std::string &action) const
 Checks if any of the buttons assigned to an action is currently held down More...
 
coma::Vec2 getMousePosition () const
 Gets the position of the mouse. More...
 
coma::Vec2 getMouseOffset () const
 Gets the pixels the mouse has displaced since the last frame. More...
 
coma::Vec3 getMouseRotation (const coma::Vec3 &start_rotation) const
 Gets an updated rotation based on the mouse offset. More...
 
void setMouseRotation (coma::Vec3 &start_rotation, float sensitivity=1.0f) const
 Updates a rotation based on the mouse offset. More...
 

Detailed Description

Interface to retrieve keyboard and mouse input.

This class is closely related to the InputButtonMap.

Constructor & Destructor Documentation

◆ InputManager()

InputManager::InputManager ( const Window window,
InputButtonMap  input_button_map 
)

Creates and binds an input map.

Parameters
windowWindow handle reference
input_button_mapMap to bind

Member Function Documentation

◆ buttonDown()

bool InputManager::buttonDown ( const std::string &  action) const

Checks if any of the buttons assigned to an action have been pressed during the frame.

Parameters
actionAction to check
Returns
True if action has been performed, false otherwise

◆ buttonPressed()

bool InputManager::buttonPressed ( const std::string &  action) const

Checks if any of the buttons assigned to an action is currently held down

Parameters
actionAction to check
Returns
True if action is currently held down, false otherwise

◆ buttonUp()

bool InputManager::buttonUp ( const std::string &  action) const

Checks if any of the buttons assigned to an action have been released during the frame.

Parameters
actionAction to check
Returns
True if action has been performed, false otherwise

◆ getMouseOffset()

coma::Vec2 InputManager::getMouseOffset ( ) const

Gets the pixels the mouse has displaced since the last frame.

Returns
Displacement of the mouse

◆ getMousePosition()

coma::Vec2 InputManager::getMousePosition ( ) const

Gets the position of the mouse.

Returns
Mouse position

Gets the position of the mouse in pixels relative to the top-left corner.

◆ getMouseRotation()

coma::Vec3 InputManager::getMouseRotation ( const coma::Vec3 start_rotation) const

Gets an updated rotation based on the mouse offset.

Parameters
start_rotationRotation to update in euler
Returns
Updated rotation in euler

Can be useful for a first-person camera.

◆ setCursorMode()

void InputManager::setCursorMode ( CursorMode  mode) const

Overrides the CursorMode of the Window.

Parameters
modeMode to use

◆ setMouseRotation()

void InputManager::setMouseRotation ( coma::Vec3 start_rotation,
float  sensitivity = 1.0f 
) const

Updates a rotation based on the mouse offset.

Parameters
start_rotationRotation to update in euler
sensitivityRotation speed multiplier

Can be useful for a first-person camera.

◆ toggleCursor()

void InputManager::toggleCursor ( ) const

Alternates the CursorMode between Normal and Disabled.

If the cursor was Normal or Hidden, makes it Disabled; if the cursor was Disabled, makes it Normal.