/* Copyright (c) 2020 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __MoveInput_H__ #define __MoveInput_H__ #ifdef __cplusplus extern "C" { #endif #include #include typedef uint32_t MoveInputState; typedef unsigned int MoveInput_axis; #define MoveInputState_allNeutral 0 #define MOVE_INPUT_BITS_PER_AXIS 3 #define MOVE_AXIS_COUNT_MAX (sizeof(MoveInputState) * 8 / MOVE_INPUT_BITS_PER_AXIS) // 10 // These MoveInput_axis values are only suggestions; any arbitrary value is valid, up to MOVE_AXIS_COUNT_MAX - 1 #define MOVE_AXIS_X 0 #define MOVE_AXIS_Y 1 #define MOVE_AXIS_Z 2 #define MOVE_AXIS_PITCH 3 #define MOVE_AXIS_YAW 4 #define MOVE_AXIS_ROLL 5 typedef enum MoveInput_direction { MOVE_DIRECTION_NEGATIVE = -1, MOVE_DIRECTION_NEUTRAL = 0, MOVE_DIRECTION_POSITIVE = 1 } MoveInput_direction; // For all functions, direction must be MOVE_DIRECTION_NEGATIVE or MOVE_DIRECTION_POSITIVE; // MOVE_DIRECTION_NEUTRAL or any other value is invalid and will cause an assertion error. // For all functions, axis must be a number less than MOVE_AXIS_COUNT_MAX. // Returns true if a change was made to state bool MoveInput_start(MoveInputState * ioState, MoveInput_axis axis, MoveInput_direction direction); bool MoveInput_stop(MoveInputState * ioState, MoveInput_axis axis, MoveInput_direction direction); // Resets axis to MOVE_DIRECTION_NEUTRAL void MoveInput_clear(MoveInputState * ioState, MoveInput_axis axis); bool MoveInput_isInput(MoveInputState state, MoveInput_axis axis, MoveInput_direction direction); // NEUTRAL for neither, NEGATIVE for negative only, POSITIVE for positive only, NEUTRAL for both MoveInput_direction MoveInput_combinedDirection(MoveInputState state, MoveInput_axis axis); // NEUTRAL for neither, NEGATIVE or POSITIVE for most recently started if either/both MoveInput_direction MoveInput_mostRecentDirection(MoveInputState state, MoveInput_axis axis); #ifdef __cplusplus } #endif #endif