fmod/studio/event_instance/attributes_3d.rs
1// Copyright (c) 2024 Lily Lyons
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7use std::{
8 ffi::{c_float, c_uint},
9 mem::MaybeUninit,
10};
11
12use fmod_sys::*;
13
14use crate::studio::EventInstance;
15use crate::Attributes3D;
16
17impl EventInstance {
18 /// Sets the 3D attributes.
19 ///
20 /// An event's 3D attributes specify its position, velocity and orientation.
21 /// The 3D attributes are used to calculate 3D panning, doppler and the values of automatic distance and angle parameters.
22 pub fn set_3d_attributes(&self, attributes: Attributes3D) -> Result<()> {
23 let mut attributes = attributes.into();
24 unsafe {
25 // FIXME is this supposed to take an &mut
26 FMOD_Studio_EventInstance_Set3DAttributes(self.inner, &mut attributes).to_result()
27 }
28 }
29
30 /// Retrieves the 3D attributes.
31 pub fn get_3d_attributes(&self) -> Result<Attributes3D> {
32 let mut attributes = MaybeUninit::zeroed();
33 unsafe {
34 FMOD_Studio_EventInstance_Get3DAttributes(self.inner, attributes.as_mut_ptr())
35 .to_result()?;
36
37 let attributes = attributes.assume_init().into();
38 Ok(attributes)
39 }
40 }
41
42 /// Sets the listener mask.
43 ///
44 /// The listener mask controls which listeners are considered when calculating 3D panning and the values of listener relative automatic parameters.
45 ///
46 /// To create the mask you must perform bitwise OR and shift operations, the basic form is 1 << `listener_index` or'd together with other required listener indices.
47 /// For example to create a mask for listener index `0` and `2` the calculation would be `mask = (1 << 0) | (1 << 2)`, to include all listeners use the default mask of `0xFFFFFFFF`.
48 pub fn set_listener_mask(&self, mask: c_uint) -> Result<()> {
49 unsafe { FMOD_Studio_EventInstance_SetListenerMask(self.inner, mask).to_result() }
50 }
51
52 /// Retrieves the listener mask.
53 pub fn get_listener_mask(&self) -> Result<c_uint> {
54 let mut mask = 0;
55 unsafe {
56 FMOD_Studio_EventInstance_GetListenerMask(self.inner, &mut mask).to_result()?;
57 }
58 Ok(mask)
59 }
60
61 /// Retrieves the minimum and maximum distances for 3D attenuation.
62 pub fn get_min_max_distance(&self) -> Result<(c_float, c_float)> {
63 let mut min = 0.0;
64 let mut max = 0.0;
65 unsafe {
66 FMOD_Studio_EventInstance_GetMinMaxDistance(self.inner, &mut min, &mut max)
67 .to_result()?;
68 }
69 Ok((min, max))
70 }
71}