1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) 2024 Lily Lyons
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use fmod_sys::*;
use std::mem::MaybeUninit;

use crate::{Geometry, Vector};

impl Geometry {
    /// Sets the 3D position of the object.
    ///
    /// Position is in world space.
    pub fn set_position(&self, position: Vector) -> Result<()> {
        unsafe {
            FMOD_Geometry_SetPosition(self.inner, std::ptr::from_ref(&position).cast()).to_result()
        }
    }

    /// Retrieves the 3D position of the object.
    ///
    /// Position is in world space.
    pub fn get_position(&self) -> Result<Vector> {
        let mut position = MaybeUninit::uninit();
        unsafe {
            FMOD_Geometry_GetPosition(self.inner, position.as_mut_ptr()).to_result()?;
            let position = position.assume_init().into();
            Ok(position)
        }
    }

    /// Sets the 3D orientation of the object.
    ///
    /// See remarks in [`crate::System::set_3d_listener_attributes`] for more description on forward and up vectors.
    pub fn set_rotation(&self, forward: Vector, up: Vector) -> Result<()> {
        unsafe {
            FMOD_Geometry_SetRotation(
                self.inner,
                std::ptr::from_ref(&forward).cast(),
                std::ptr::from_ref(&up).cast(),
            )
            .to_result()
        }
    }

    /// Retrieves the 3D orientation of the object.
    pub fn get_rotation(&self) -> Result<(Vector, Vector)> {
        let mut forward = MaybeUninit::uninit();
        let mut up = MaybeUninit::uninit();
        unsafe {
            FMOD_Geometry_GetRotation(self.inner, forward.as_mut_ptr(), up.as_mut_ptr())
                .to_result()?;
            let forward = forward.assume_init().into();
            let up = up.assume_init().into();
            Ok((forward, up))
        }
    }

    /// Sets the 3D scale of the object.
    ///
    /// An object can be scaled/warped in all 3 dimensions separately using this function without having to modify polygon data.
    pub fn set_scale(&self, scale: Vector) -> Result<()> {
        unsafe { FMOD_Geometry_SetScale(self.inner, std::ptr::from_ref(&scale).cast()).to_result() }
    }

    /// Retrieves the 3D scale of the object.
    pub fn get_scale(&self) -> Result<Vector> {
        let mut scale = MaybeUninit::uninit();
        unsafe {
            FMOD_Geometry_GetScale(self.inner, scale.as_mut_ptr()).to_result()?;
            let scale = scale.assume_init().into();
            Ok(scale)
        }
    }
}