glfw: add Joystick.getAxes
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
e7c6454f3d
commit
e31e9fe694
1 changed files with 47 additions and 30 deletions
|
@ -69,36 +69,33 @@ pub inline fn isPresent(self: Joystick) Error!bool {
|
||||||
return is_present == c.GLFW_TRUE;
|
return is_present == c.GLFW_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(joystick)
|
/// Returns the values of all axes of the specified joystick.
|
||||||
// /// Returns the values of all axes of the specified joystick.
|
///
|
||||||
// ///
|
/// This function returns the values of all axes of the specified joystick. Each element in the
|
||||||
// /// This function returns the values of all axes of the specified joystick.
|
/// array is a value between -1.0 and 1.0.
|
||||||
// /// Each element in the array is a value between -1.0 and 1.0.
|
///
|
||||||
// ///
|
/// If the specified joystick is not present this function will return null but will not generate
|
||||||
// /// If the specified joystick is not present this function will return null
|
/// an error. This can be used instead of first calling glfw.Joystick.isPresent.
|
||||||
// /// but will not generate an error. This can be used instead of first calling
|
///
|
||||||
// /// @ref glfwJoystickPresent.
|
/// @return An array of axis values, or null if the joystick is not present.
|
||||||
// ///
|
///
|
||||||
// /// @param[in] jid The [joystick](@ref joysticks) to query.
|
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError.
|
||||||
// /// @param[out] count Where to store the number of axis values in the returned
|
///
|
||||||
// /// array. This is set to zero if the joystick is not present or an error
|
/// @pointer_lifetime The returned array is allocated and freed by GLFW. You should not free it
|
||||||
// /// occurred.
|
/// yourself. It is valid until the specified joystick is disconnected or the library is
|
||||||
// /// @return An array of axis values, or null if the joystick is not present or
|
/// terminated.
|
||||||
// /// an error occurred.
|
///
|
||||||
// ///
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
// /// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError.
|
///
|
||||||
// ///
|
/// see also: joystick_axis
|
||||||
// /// @pointer_lifetime The returned array is allocated and freed by GLFW. You
|
/// Replaces `glfwGetJoystickPos`.
|
||||||
// /// should not free it yourself. It is valid until the specified joystick is
|
pub inline fn getAxes(self: Joystick) Error!?[]const f32 {
|
||||||
// /// disconnected or the library is terminated.
|
var count: c_int = undefined;
|
||||||
// ///
|
const axes = c.glfwGetJoystickAxes(self.jid, &count);
|
||||||
// /// @thread_safety This function must only be called from the main thread.
|
try getError();
|
||||||
// ///
|
if (axes == null) return null;
|
||||||
// /// see also: joystick_axis
|
return axes[0..@intCast(usize, count)];
|
||||||
// /// Replaces `glfwGetJoystickPos`.
|
}
|
||||||
// ///
|
|
||||||
// /// @ingroup input
|
|
||||||
// GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count);
|
|
||||||
|
|
||||||
// TODO(joystick)
|
// TODO(joystick)
|
||||||
// /// Returns the state of all buttons of the specified joystick.
|
// /// Returns the state of all buttons of the specified joystick.
|
||||||
|
@ -442,6 +439,26 @@ pub inline fn getGamepadState(self: Joystick) Error!?GamepadState {
|
||||||
return if (success == c.GLFW_TRUE) state else null;
|
return if (success == c.GLFW_TRUE) state else null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "isPresent" {
|
||||||
|
const glfw = @import("main.zig");
|
||||||
|
try glfw.init();
|
||||||
|
defer glfw.terminate();
|
||||||
|
|
||||||
|
const joystick = glfw.Joystick{ .jid = glfw.Joystick.one };
|
||||||
|
|
||||||
|
_ = joystick.isPresent() catch |err| std.debug.print("failed to detect joystick, joysticks not supported? error={}\n", .{err});
|
||||||
|
}
|
||||||
|
|
||||||
|
test "getAxes" {
|
||||||
|
const glfw = @import("main.zig");
|
||||||
|
try glfw.init();
|
||||||
|
defer glfw.terminate();
|
||||||
|
|
||||||
|
const joystick = glfw.Joystick{ .jid = glfw.Joystick.one };
|
||||||
|
|
||||||
|
_ = joystick.getAxes() catch |err| std.debug.print("failed to get joystick axes, joysticks not supported? error={}\n", .{err});
|
||||||
|
}
|
||||||
|
|
||||||
test "setUserPointer_syntax" {
|
test "setUserPointer_syntax" {
|
||||||
const glfw = @import("main.zig");
|
const glfw = @import("main.zig");
|
||||||
try glfw.init();
|
try glfw.init();
|
||||||
|
|
Loading…
Add table
Reference in a new issue