mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 03:29:44 -06:00
Add support for several joysticks at the smae time
This commit is contained in:
@@ -77,43 +77,55 @@ public:
|
||||
void updateStateFromInput(
|
||||
const JoystickInputStates& joystickInputStates, double deltaTime);
|
||||
|
||||
void setAxisMapping(int axis, AxisType mapping,
|
||||
void setAxisMapping(const std::string& joystickName, int axis, AxisType mapping,
|
||||
AxisInvert shouldInvert = AxisInvert::No,
|
||||
AxisNormalize shouldNormalize = AxisNormalize::No,
|
||||
bool isSticky = false, double sensitivity = 0.0
|
||||
);
|
||||
|
||||
AxisInformation axisMapping(int axis) const;
|
||||
AxisInformation axisMapping(const std::string& joystickName, int axis) const;
|
||||
|
||||
void setDeadzone(int axis, float deadzone);
|
||||
float deadzone(int axis) const;
|
||||
void setDeadzone(const std::string& joystickName, int axis, float deadzone);
|
||||
float deadzone(const std::string& joystickName, int axis) const;
|
||||
|
||||
|
||||
void bindButtonCommand(int button, std::string command, JoystickAction action,
|
||||
ButtonCommandRemote remote, std::string documentation);
|
||||
void clearButtonCommand(int button);
|
||||
std::vector<std::string> buttonCommand(int button) const;
|
||||
void bindButtonCommand(const std::string& joystickName, int button,
|
||||
std::string command, JoystickAction action, ButtonCommandRemote remote,
|
||||
std::string documentation);
|
||||
void clearButtonCommand(const std::string& joystickName, int button);
|
||||
std::vector<std::string> buttonCommand(const std::string& joystickName,
|
||||
int button) const;
|
||||
|
||||
private:
|
||||
// We use an array for the axes and a map for the buttons since the axis are going to
|
||||
// be accessed much more often and thus have to be more efficient. And storing a few
|
||||
// extra AxisInformation that are not used will not matter that much; finding an axis
|
||||
// location in a potential map each frame, however, would
|
||||
struct JoystickCameraState {
|
||||
std::string joystickName;
|
||||
|
||||
std::array<AxisInformation, JoystickInputState::MaxAxes> _axisMapping;
|
||||
// We use an array for the axes and a map for the buttons since the axis are going to
|
||||
// be accessed much more often and thus have to be more efficient. And storing a few
|
||||
// extra AxisInformation that are not used will not matter that much; finding an axis
|
||||
// location in a potential map each frame, however, would
|
||||
|
||||
// This array is used to store the old axis values from the previous frame,
|
||||
// it is used to calculate the difference in the values in the case of a sticky axis
|
||||
std::array<float, JoystickInputState::MaxAxes> _prevAxisValues;
|
||||
std::array<AxisInformation, JoystickInputState::MaxAxes> axisMapping;
|
||||
|
||||
struct ButtonInformation {
|
||||
std::string command;
|
||||
JoystickAction action;
|
||||
ButtonCommandRemote synchronization;
|
||||
std::string documentation;
|
||||
// This array is used to store the old axis values from the previous frame,
|
||||
// it is used to calculate the difference in the values in the case of a sticky axis
|
||||
std::array<float, JoystickInputState::MaxAxes> prevAxisValues;
|
||||
|
||||
struct ButtonInformation {
|
||||
std::string command;
|
||||
JoystickAction action;
|
||||
ButtonCommandRemote synchronization;
|
||||
std::string documentation;
|
||||
};
|
||||
|
||||
std::multimap<int, ButtonInformation> buttonMapping;
|
||||
};
|
||||
|
||||
std::multimap<int, ButtonInformation> _buttonMapping;
|
||||
std::vector<JoystickCameraState> _joystickCameraStates;
|
||||
|
||||
// Find the item in _joystickCameraStates that corresponds to the given joystickName
|
||||
// return a pointer to the item, if not found then return nullptr
|
||||
JoystickCameraState* getJoystickCameraState(const std::string& joystickName);
|
||||
const JoystickCameraState* getJoystickCameraState(const std::string& joystickName) const;
|
||||
};
|
||||
|
||||
} // namespace openspace::interaction
|
||||
|
||||
@@ -72,11 +72,6 @@ struct JoystickInputState {
|
||||
/// \c nAxes values are defined values, the rest are undefined
|
||||
std::array<float, MaxAxes> axes;
|
||||
|
||||
/// The axis values can either go back to 0 when the joystick is released or it can
|
||||
/// stay at the value it was before the joystick was released.
|
||||
/// The latter is called a sticky axis, when the values don't go back to 0.
|
||||
bool isSticky = false;
|
||||
|
||||
/// The number of buttons that this joystick possesses
|
||||
int nButtons = 0;
|
||||
/// The status of each button. Only the first \c nButtons values are defined, the rest
|
||||
@@ -88,6 +83,10 @@ struct JoystickInputState {
|
||||
/// derived from the available GLFW constants
|
||||
constexpr const int MaxJoysticks = 16;
|
||||
struct JoystickInputStates : public std::array<JoystickInputState, MaxJoysticks> {
|
||||
/// The maximum number of joysticks that are supported by this system. This number is
|
||||
/// derived from the available GLFW constants
|
||||
static constexpr const int MaxNumJoysticks = 16;
|
||||
|
||||
/**
|
||||
* This function adds the contributions of all connected joysticks for the provided
|
||||
* \p axis. After adding each joysticks contribution, the result is clamped to [-1,1].
|
||||
@@ -99,7 +98,7 @@ struct JoystickInputStates : public std::array<JoystickInputState, MaxJoysticks>
|
||||
*
|
||||
* \pre \p axis must be 0 or positive
|
||||
*/
|
||||
float axis(int axis) const;
|
||||
float axis(const std::string& joystickName, int axis) const;
|
||||
|
||||
/**
|
||||
* This functions checks whether any connected joystick has its \p button in the
|
||||
@@ -113,7 +112,7 @@ struct JoystickInputStates : public std::array<JoystickInputState, MaxJoysticks>
|
||||
*
|
||||
* \pre \p button must be 0 or positive
|
||||
*/
|
||||
bool button(int button, JoystickAction action) const;
|
||||
bool button(const std::string& joystickName, int button, JoystickAction action) const;
|
||||
};
|
||||
|
||||
} // namespace openspace::interaction
|
||||
|
||||
@@ -98,7 +98,8 @@ public:
|
||||
void mousePositionCallback(double x, double y);
|
||||
void mouseScrollWheelCallback(double pos);
|
||||
|
||||
void setJoystickAxisMapping(int axis, JoystickCameraStates::AxisType mapping,
|
||||
void setJoystickAxisMapping(const std::string& joystickName,
|
||||
int axis, JoystickCameraStates::AxisType mapping,
|
||||
JoystickCameraStates::AxisInvert shouldInvert =
|
||||
JoystickCameraStates::AxisInvert::No,
|
||||
JoystickCameraStates::AxisNormalize shouldNormalize =
|
||||
@@ -106,16 +107,20 @@ public:
|
||||
bool isSticky = false, double sensitivity = 0.0
|
||||
);
|
||||
|
||||
JoystickCameraStates::AxisInformation joystickAxisMapping(int axis) const;
|
||||
JoystickCameraStates::AxisInformation joystickAxisMapping(
|
||||
const std::string& joystickName, int axis) const;
|
||||
|
||||
void setJoystickAxisDeadzone(int axis, float deadzone);
|
||||
float joystickAxisDeadzone(int axis) const;
|
||||
void setJoystickAxisDeadzone(const std::string& joystickName, int axis,
|
||||
float deadzone);
|
||||
float joystickAxisDeadzone(const std::string& joystickName, int axis) const;
|
||||
|
||||
void bindJoystickButtonCommand(int button, std::string command, JoystickAction action,
|
||||
void bindJoystickButtonCommand(const std::string& joystickName, int button,
|
||||
std::string command, JoystickAction action,
|
||||
JoystickCameraStates::ButtonCommandRemote remote, std::string documentation);
|
||||
|
||||
void clearJoystickButtonCommand(int button);
|
||||
std::vector<std::string> joystickButtonCommand(int button) const;
|
||||
void clearJoystickButtonCommand(const std::string& joystickName, int button);
|
||||
std::vector<std::string> joystickButtonCommand(const std::string& joystickName,
|
||||
int button) const;
|
||||
|
||||
// Websockets
|
||||
void setWebsocketAxisMapping(int axis, WebsocketCameraStates::AxisType mapping,
|
||||
|
||||
Reference in New Issue
Block a user