objc2_game_controller/generated/
GCMotion.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9/// A 3 dimensional acceleration vector measured as scalar multiples of earth's gravitational acceleration, G.
10///
11/// The azimuth direction is assumed to be (0, 0, 1), so a device held at rest with the z axis aligned with the azimuth
12/// is assumed to have gravitation applying the vector (0, 0, -1).
13///
14/// Field: x X-axis acceleration as a scalar multiple of earth's gravitational acceleration, G.
15/// Field: y Y-axis acceleration as a scalar multiple of earth's gravitational acceleration, G.
16/// Field: z Z-axis acceleration as a scalar multiple of earth's gravitational acceleration, G.
17///
18/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcacceleration?language=objc)
19#[repr(C)]
20#[derive(Clone, Copy, Debug, PartialEq)]
21pub struct GCAcceleration {
22    pub x: c_double,
23    pub y: c_double,
24    pub z: c_double,
25}
26
27unsafe impl Encode for GCAcceleration {
28    const ENCODING: Encoding = Encoding::Struct(
29        "?",
30        &[
31            <c_double>::ENCODING,
32            <c_double>::ENCODING,
33            <c_double>::ENCODING,
34        ],
35    );
36}
37
38unsafe impl RefEncode for GCAcceleration {
39    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
40}
41
42/// A structure containing 3-axis rotation rate data.
43///
44/// Field: x   X-axis rotation rate in radians/second. The sign follows the right hand
45/// rule (i.e. if the right hand is wrapped around the X axis such that the
46/// tip of the thumb points toward positive X, a positive rotation is one
47/// toward the tips of the other 4 fingers).
48///
49/// Field: y   Y-axis rotation rate in radians/second. The sign follows the right hand
50/// rule (i.e. if the right hand is wrapped around the Y axis such that the
51/// tip of the thumb points toward positive Y, a positive rotation is one
52/// toward the tips of the other 4 fingers).
53/// Field: z
54/// Z-axis rotation rate in radians/second. The sign follows the right hand
55/// rule (i.e. if the right hand is wrapped around the Z axis such that the
56/// tip of the thumb points toward positive Z, a positive rotation is one
57/// toward the tips of the other 4 fingers).
58///
59/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcrotationrate?language=objc)
60#[repr(C)]
61#[derive(Clone, Copy, Debug, PartialEq)]
62pub struct GCRotationRate {
63    pub x: c_double,
64    pub y: c_double,
65    pub z: c_double,
66}
67
68unsafe impl Encode for GCRotationRate {
69    const ENCODING: Encoding = Encoding::Struct(
70        "?",
71        &[
72            <c_double>::ENCODING,
73            <c_double>::ENCODING,
74            <c_double>::ENCODING,
75        ],
76    );
77}
78
79unsafe impl RefEncode for GCRotationRate {
80    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
81}
82
83/// A structure containing 3-axis rotation data. The angles are rotated in order or pitch then yaw then roll.
84///
85/// Field: pitch X-axis rotation in radians. The sign follows the right hand
86/// rule (i.e. if the right hand is wrapped around the X axis such that the
87/// tip of the thumb points toward positive X, a positive rotation is one
88/// toward the tips of the other 4 fingers).
89///
90/// Field: yaw   Y-axis rotation in radians. The sign follows the right hand
91/// rule (i.e. if the right hand is wrapped around the Y axis such that the
92/// tip of the thumb points toward positive Y, a positive rotation is one
93/// toward the tips of the other 4 fingers).
94///
95/// Field: roll  Z-axis rotation in radians. The sign follows the right hand
96/// rule (i.e. if the right hand is wrapped around the Z axis such that the
97/// tip of the thumb points toward positive Z, a positive rotation is one
98/// toward the tips of the other 4 fingers).
99///
100/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gceulerangles?language=objc)
101#[repr(C)]
102#[derive(Clone, Copy, Debug, PartialEq)]
103pub struct GCEulerAngles {
104    pub pitch: c_double,
105    pub yaw: c_double,
106    pub roll: c_double,
107}
108
109unsafe impl Encode for GCEulerAngles {
110    const ENCODING: Encoding = Encoding::Struct(
111        "?",
112        &[
113            <c_double>::ENCODING,
114            <c_double>::ENCODING,
115            <c_double>::ENCODING,
116        ],
117    );
118}
119
120unsafe impl RefEncode for GCEulerAngles {
121    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
122}
123
124/// Represents a quaternion (one way of parameterizing attitude).
125/// If q is an instance of GCQuaternion, mathematically it represents the following quaternion:
126///
127/// q.x*i + q.y*j + q.z*k + q.w
128///
129/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcquaternion?language=objc)
130#[repr(C)]
131#[derive(Clone, Copy, Debug, PartialEq)]
132pub struct GCQuaternion {
133    pub x: c_double,
134    pub y: c_double,
135    pub z: c_double,
136    pub w: c_double,
137}
138
139unsafe impl Encode for GCQuaternion {
140    const ENCODING: Encoding = Encoding::Struct(
141        "GCQuaternion",
142        &[
143            <c_double>::ENCODING,
144            <c_double>::ENCODING,
145            <c_double>::ENCODING,
146            <c_double>::ENCODING,
147        ],
148    );
149}
150
151unsafe impl RefEncode for GCQuaternion {
152    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
153}
154
155/// Called whenever a motion value changed.
156///
157/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcmotionvaluechangedhandler?language=objc)
158#[cfg(feature = "block2")]
159pub type GCMotionValueChangedHandler = *mut block2::DynBlock<dyn Fn(NonNull<GCMotion>)>;
160
161extern_class!(
162    /// A profile for getting motion input from a controller that has the ability to measure acceleration
163    /// and rotation rate.
164    ///
165    /// You check for the availablity of motion inputs by getting the motion property
166    /// of a controller. If that returns a nil value; motion is not available. A non-nil value is a valid
167    /// GCMotion profile that is able to provide motion input.
168    ///
169    ///
170    /// See: GCController.motion
171    ///
172    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcmotion?language=objc)
173    #[unsafe(super(NSObject))]
174    #[derive(Debug, PartialEq, Eq, Hash)]
175    pub struct GCMotion;
176);
177
178extern_conformance!(
179    unsafe impl NSObjectProtocol for GCMotion {}
180);
181
182impl GCMotion {
183    extern_methods!(
184        #[cfg(feature = "GCController")]
185        /// A profile keeps a reference to the controller that it is mapping input from.
186        ///
187        ///
188        /// See: GCController
189        #[unsafe(method(controller))]
190        #[unsafe(method_family = none)]
191        pub unsafe fn controller(&self) -> Option<Retained<GCController>>;
192
193        #[cfg(feature = "block2")]
194        #[unsafe(method(valueChangedHandler))]
195        #[unsafe(method_family = none)]
196        pub unsafe fn valueChangedHandler(&self) -> GCMotionValueChangedHandler;
197
198        #[cfg(feature = "block2")]
199        /// Setter for [`valueChangedHandler`][Self::valueChangedHandler].
200        #[unsafe(method(setValueChangedHandler:))]
201        #[unsafe(method_family = none)]
202        pub unsafe fn setValueChangedHandler(
203            &self,
204            value_changed_handler: GCMotionValueChangedHandler,
205        );
206
207        /// If this property is returns YES, you are responsible for setting sensorsActive to YES when you need motion data from the controller.
208        ///
209        /// Some controllers, such as the Siri Remote, automatically activate and deactivate motion sensors. In such a case, this property
210        /// will return NO.
211        ///
212        ///
213        /// See: sensorsActive
214        #[unsafe(method(sensorsRequireManualActivation))]
215        #[unsafe(method_family = none)]
216        pub unsafe fn sensorsRequireManualActivation(&self) -> bool;
217
218        /// Set this property to YES when you wish to receive motion data from the controller. When you set this property to NO, the motion sensors
219        /// will be disabled and the GCMotion profile will not be updated.
220        ///
221        ///
222        /// Note: It is highly recommended that you only enable sensor during the period of time you directly need motion data. Motion sensors
223        /// can drain controller battery, device battery, and needlessly consume Bluetooth bandwidth.
224        ///
225        ///
226        /// See: sensorsRequireManualActivation
227        #[unsafe(method(sensorsActive))]
228        #[unsafe(method_family = none)]
229        pub unsafe fn sensorsActive(&self) -> bool;
230
231        /// Setter for [`sensorsActive`][Self::sensorsActive].
232        #[unsafe(method(setSensorsActive:))]
233        #[unsafe(method_family = none)]
234        pub unsafe fn setSensorsActive(&self, sensors_active: bool);
235
236        /// Returns YES if the controller is capable of reporting gravity and user acceleration separately.
237        ///
238        ///
239        /// Note: Some controllers do not separate gravity from user acceleration, and only report the total acceleration of the controller.
240        /// Query whether the connected controller has the ability to separate gravity and user acceleration, and it doesn’t, use acceleration instead.
241        ///
242        ///
243        /// See: acceleration
244        #[unsafe(method(hasGravityAndUserAcceleration))]
245        #[unsafe(method_family = none)]
246        pub unsafe fn hasGravityAndUserAcceleration(&self) -> bool;
247
248        /// The gravity vector expressed in the controller's reference frame.
249        ///
250        /// Note that the total acceleration of the controller is equal to gravity plus userAcceleration.
251        ///
252        ///
253        /// See: userAcceleration
254        ///
255        /// See: acceleration
256        #[unsafe(method(gravity))]
257        #[unsafe(method_family = none)]
258        pub unsafe fn gravity(&self) -> GCAcceleration;
259
260        /// The acceleration that the user is giving to the controller.
261        ///
262        /// Note that the total acceleration of the controller is equal to gravity plus userAcceleration.
263        ///
264        ///
265        /// See: gravity
266        ///
267        /// See: acceleration
268        #[unsafe(method(userAcceleration))]
269        #[unsafe(method_family = none)]
270        pub unsafe fn userAcceleration(&self) -> GCAcceleration;
271
272        /// The total acceleration of the controller.
273        ///
274        ///
275        /// See: gravity
276        ///
277        /// See: userAcceleration
278        #[unsafe(method(acceleration))]
279        #[unsafe(method_family = none)]
280        pub unsafe fn acceleration(&self) -> GCAcceleration;
281
282        /// The controller generating the motion data has sensors that can accurately determine the current attitude and rotation rate. If this is enabled the motion data for attitude and rotation rate are usable for inputs.
283        #[deprecated = "Use -hasAttitude and -hasRotationRate methods instead"]
284        #[unsafe(method(hasAttitudeAndRotationRate))]
285        #[unsafe(method_family = none)]
286        pub unsafe fn hasAttitudeAndRotationRate(&self) -> bool;
287
288        /// The controller generating the motion data has sensors that can accurately determine the current attitude. If this is enabled the motion data for attitude is usable for inputs.
289        #[unsafe(method(hasAttitude))]
290        #[unsafe(method_family = none)]
291        pub unsafe fn hasAttitude(&self) -> bool;
292
293        /// The controller generating the motion data has sensors that can accurately determine the current rotation rate. If this is enabled the motion data for rotation rate is usable for inputs.
294        #[unsafe(method(hasRotationRate))]
295        #[unsafe(method_family = none)]
296        pub unsafe fn hasRotationRate(&self) -> bool;
297
298        /// The current attitude of the controller.
299        ///
300        ///
301        /// Note: Remotes without accurate attitude and rotation rate can not determine a stable attitude so the values will be (0,0,0,1) at all times.
302        ///
303        /// See: hasAttitude
304        ///
305        /// See: GCMicroGamepad
306        #[unsafe(method(attitude))]
307        #[unsafe(method_family = none)]
308        pub unsafe fn attitude(&self) -> GCQuaternion;
309
310        /// The current rotation rate of the controller.
311        ///
312        ///
313        /// Note: Remotes without accurate attitude and rotation rate can not determine a stable rotation rate so the values will be (0,0,0) at all times.
314        ///
315        /// See: hasRotationRate
316        ///
317        /// See: GCMicroGamepad
318        #[unsafe(method(rotationRate))]
319        #[unsafe(method_family = none)]
320        pub unsafe fn rotationRate(&self) -> GCRotationRate;
321
322        /// Sets the gravity vector expressed in the controller's reference frame.
323        ///
324        ///
325        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
326        ///
327        /// See: gravity
328        #[unsafe(method(setGravity:))]
329        #[unsafe(method_family = none)]
330        pub unsafe fn setGravity(&self, gravity: GCAcceleration);
331
332        /// Sets the acceleration that the user is giving to the controller.
333        ///
334        ///
335        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
336        ///
337        /// See: userAcceleration
338        #[unsafe(method(setUserAcceleration:))]
339        #[unsafe(method_family = none)]
340        pub unsafe fn setUserAcceleration(&self, user_acceleration: GCAcceleration);
341
342        /// Sets the acceleration that the user is giving to the controller.
343        ///
344        ///
345        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
346        ///
347        /// See: userAcceleration
348        #[unsafe(method(setAcceleration:))]
349        #[unsafe(method_family = none)]
350        pub unsafe fn setAcceleration(&self, acceleration: GCAcceleration);
351
352        /// Sets the current rotation rate of the controller.
353        ///
354        ///
355        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
356        ///
357        /// See: attitude
358        #[unsafe(method(setAttitude:))]
359        #[unsafe(method_family = none)]
360        pub unsafe fn setAttitude(&self, attitude: GCQuaternion);
361
362        /// Sets the current rotation rate of the controller.
363        ///
364        ///
365        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
366        ///
367        /// See: rotationRate
368        #[unsafe(method(setRotationRate:))]
369        #[unsafe(method_family = none)]
370        pub unsafe fn setRotationRate(&self, rotation_rate: GCRotationRate);
371
372        /// Sets the state vector of the motion profile to a copy of the input motion profile's state vector.
373        ///
374        ///
375        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
376        ///
377        /// See: GCController.snapshot
378        #[unsafe(method(setStateFromMotion:))]
379        #[unsafe(method_family = none)]
380        pub unsafe fn setStateFromMotion(&self, motion: &GCMotion);
381    );
382}
383
384/// Methods declared on superclass `NSObject`.
385impl GCMotion {
386    extern_methods!(
387        #[unsafe(method(init))]
388        #[unsafe(method_family = init)]
389        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
390
391        #[unsafe(method(new))]
392        #[unsafe(method_family = new)]
393        pub unsafe fn new() -> Retained<Self>;
394    );
395}