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::Block<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
178unsafe impl NSObjectProtocol for GCMotion {}
179
180impl GCMotion {
181    extern_methods!(
182        #[cfg(feature = "GCController")]
183        #[unsafe(method(controller))]
184        #[unsafe(method_family = none)]
185        pub unsafe fn controller(&self) -> Option<Retained<GCController>>;
186
187        #[cfg(feature = "block2")]
188        #[unsafe(method(valueChangedHandler))]
189        #[unsafe(method_family = none)]
190        pub unsafe fn valueChangedHandler(&self) -> GCMotionValueChangedHandler;
191
192        #[cfg(feature = "block2")]
193        /// Setter for [`valueChangedHandler`][Self::valueChangedHandler].
194        #[unsafe(method(setValueChangedHandler:))]
195        #[unsafe(method_family = none)]
196        pub unsafe fn setValueChangedHandler(
197            &self,
198            value_changed_handler: GCMotionValueChangedHandler,
199        );
200
201        /// If this property is returns YES, you are responsible for setting sensorsActive to YES when you need motion data from the controller.
202        ///
203        /// Some controllers, such as the Siri Remote, automatically activate and deactivate motion sensors. In such a case, this property
204        /// will return NO.
205        ///
206        ///
207        /// See: sensorsActive
208        #[unsafe(method(sensorsRequireManualActivation))]
209        #[unsafe(method_family = none)]
210        pub unsafe fn sensorsRequireManualActivation(&self) -> bool;
211
212        /// 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
213        /// will be disabled and the GCMotion profile will not be updated.
214        ///
215        ///
216        /// Note: It is highly recommended that you only enable sensor during the period of time you directly need motion data. Motion sensors
217        /// can drain controller battery, device battery, and needlessly consume Bluetooth bandwidth.
218        ///
219        ///
220        /// See: sensorsRequireManualActivation
221        #[unsafe(method(sensorsActive))]
222        #[unsafe(method_family = none)]
223        pub unsafe fn sensorsActive(&self) -> bool;
224
225        /// Setter for [`sensorsActive`][Self::sensorsActive].
226        #[unsafe(method(setSensorsActive:))]
227        #[unsafe(method_family = none)]
228        pub unsafe fn setSensorsActive(&self, sensors_active: bool);
229
230        /// Returns YES if the controller is capable of reporting gravity and user acceleration separately.
231        ///
232        ///
233        /// Note: Some controllers do not separate gravity from user acceleration, and only report the total acceleration of the controller.
234        /// Query whether the connected controller has the ability to separate gravity and user acceleration, and it doesn’t, use acceleration instead.
235        ///
236        ///
237        /// See: acceleration
238        #[unsafe(method(hasGravityAndUserAcceleration))]
239        #[unsafe(method_family = none)]
240        pub unsafe fn hasGravityAndUserAcceleration(&self) -> bool;
241
242        /// The gravity vector expressed in the controller's reference frame.
243        ///
244        /// Note that the total acceleration of the controller is equal to gravity plus userAcceleration.
245        ///
246        ///
247        /// See: userAcceleration
248        ///
249        /// See: acceleration
250        #[unsafe(method(gravity))]
251        #[unsafe(method_family = none)]
252        pub unsafe fn gravity(&self) -> GCAcceleration;
253
254        /// The acceleration that the user is giving to the controller.
255        ///
256        /// Note that the total acceleration of the controller is equal to gravity plus userAcceleration.
257        ///
258        ///
259        /// See: gravity
260        ///
261        /// See: acceleration
262        #[unsafe(method(userAcceleration))]
263        #[unsafe(method_family = none)]
264        pub unsafe fn userAcceleration(&self) -> GCAcceleration;
265
266        /// The total acceleration of the controller.
267        ///
268        ///
269        /// See: gravity
270        ///
271        /// See: userAcceleration
272        #[unsafe(method(acceleration))]
273        #[unsafe(method_family = none)]
274        pub unsafe fn acceleration(&self) -> GCAcceleration;
275
276        /// 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.
277        #[deprecated = "hasAttitudeAndRotationRate has been deprecated, use -hasAttitude and -hasRotationRate instead"]
278        #[unsafe(method(hasAttitudeAndRotationRate))]
279        #[unsafe(method_family = none)]
280        pub unsafe fn hasAttitudeAndRotationRate(&self) -> bool;
281
282        /// 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.
283        #[unsafe(method(hasAttitude))]
284        #[unsafe(method_family = none)]
285        pub unsafe fn hasAttitude(&self) -> bool;
286
287        /// 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.
288        #[unsafe(method(hasRotationRate))]
289        #[unsafe(method_family = none)]
290        pub unsafe fn hasRotationRate(&self) -> bool;
291
292        /// The current attitude of the controller.
293        ///
294        ///
295        /// 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.
296        ///
297        /// See: hasAttitude
298        ///
299        /// See: GCMicroGamepad
300        #[unsafe(method(attitude))]
301        #[unsafe(method_family = none)]
302        pub unsafe fn attitude(&self) -> GCQuaternion;
303
304        /// The current rotation rate of the controller.
305        ///
306        ///
307        /// 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.
308        ///
309        /// See: hasRotationRate
310        ///
311        /// See: GCMicroGamepad
312        #[unsafe(method(rotationRate))]
313        #[unsafe(method_family = none)]
314        pub unsafe fn rotationRate(&self) -> GCRotationRate;
315
316        /// Sets the gravity vector expressed in the controller's reference frame.
317        ///
318        ///
319        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
320        ///
321        /// See: gravity
322        #[unsafe(method(setGravity:))]
323        #[unsafe(method_family = none)]
324        pub unsafe fn setGravity(&self, gravity: GCAcceleration);
325
326        /// Sets the acceleration that the user is giving to the controller.
327        ///
328        ///
329        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
330        ///
331        /// See: userAcceleration
332        #[unsafe(method(setUserAcceleration:))]
333        #[unsafe(method_family = none)]
334        pub unsafe fn setUserAcceleration(&self, user_acceleration: GCAcceleration);
335
336        /// Sets the acceleration that the user is giving to the controller.
337        ///
338        ///
339        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
340        ///
341        /// See: userAcceleration
342        #[unsafe(method(setAcceleration:))]
343        #[unsafe(method_family = none)]
344        pub unsafe fn setAcceleration(&self, acceleration: GCAcceleration);
345
346        /// Sets the current rotation rate of the controller.
347        ///
348        ///
349        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
350        ///
351        /// See: attitude
352        #[unsafe(method(setAttitude:))]
353        #[unsafe(method_family = none)]
354        pub unsafe fn setAttitude(&self, attitude: GCQuaternion);
355
356        /// Sets the current rotation rate of the controller.
357        ///
358        ///
359        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
360        ///
361        /// See: rotationRate
362        #[unsafe(method(setRotationRate:))]
363        #[unsafe(method_family = none)]
364        pub unsafe fn setRotationRate(&self, rotation_rate: GCRotationRate);
365
366        /// Sets the state vector of the motion profile to a copy of the input motion profile's state vector.
367        ///
368        ///
369        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
370        ///
371        /// See: GCController.snapshot
372        #[unsafe(method(setStateFromMotion:))]
373        #[unsafe(method_family = none)]
374        pub unsafe fn setStateFromMotion(&self, motion: &GCMotion);
375    );
376}
377
378/// Methods declared on superclass `NSObject`.
379impl GCMotion {
380    extern_methods!(
381        #[unsafe(method(init))]
382        #[unsafe(method_family = init)]
383        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
384
385        #[unsafe(method(new))]
386        #[unsafe(method_family = new)]
387        pub unsafe fn new() -> Retained<Self>;
388    );
389}