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