fmod/core/geometry/
spatialization.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 fmod_sys::*;
8use std::mem::MaybeUninit;
9
10use crate::{Geometry, Vector};
11
12impl Geometry {
13    /// Sets the 3D position of the object.
14    ///
15    /// Position is in world space.
16    pub fn set_position(&self, position: Vector) -> Result<()> {
17        unsafe {
18            FMOD_Geometry_SetPosition(self.inner, std::ptr::from_ref(&position).cast()).to_result()
19        }
20    }
21
22    /// Retrieves the 3D position of the object.
23    ///
24    /// Position is in world space.
25    pub fn get_position(&self) -> Result<Vector> {
26        let mut position = MaybeUninit::uninit();
27        unsafe {
28            FMOD_Geometry_GetPosition(self.inner, position.as_mut_ptr()).to_result()?;
29            let position = position.assume_init().into();
30            Ok(position)
31        }
32    }
33
34    /// Sets the 3D orientation of the object.
35    ///
36    /// See remarks in [`crate::System::set_3d_listener_attributes`] for more description on forward and up vectors.
37    pub fn set_rotation(&self, forward: Vector, up: Vector) -> Result<()> {
38        unsafe {
39            FMOD_Geometry_SetRotation(
40                self.inner,
41                std::ptr::from_ref(&forward).cast(),
42                std::ptr::from_ref(&up).cast(),
43            )
44            .to_result()
45        }
46    }
47
48    /// Retrieves the 3D orientation of the object.
49    pub fn get_rotation(&self) -> Result<(Vector, Vector)> {
50        let mut forward = MaybeUninit::uninit();
51        let mut up = MaybeUninit::uninit();
52        unsafe {
53            FMOD_Geometry_GetRotation(self.inner, forward.as_mut_ptr(), up.as_mut_ptr())
54                .to_result()?;
55            let forward = forward.assume_init().into();
56            let up = up.assume_init().into();
57            Ok((forward, up))
58        }
59    }
60
61    /// Sets the 3D scale of the object.
62    ///
63    /// An object can be scaled/warped in all 3 dimensions separately using this function without having to modify polygon data.
64    pub fn set_scale(&self, scale: Vector) -> Result<()> {
65        unsafe { FMOD_Geometry_SetScale(self.inner, std::ptr::from_ref(&scale).cast()).to_result() }
66    }
67
68    /// Retrieves the 3D scale of the object.
69    pub fn get_scale(&self) -> Result<Vector> {
70        let mut scale = MaybeUninit::uninit();
71        unsafe {
72            FMOD_Geometry_GetScale(self.inner, scale.as_mut_ptr()).to_result()?;
73            let scale = scale.assume_init().into();
74            Ok(scale)
75        }
76    }
77}