use super::{Point, Vector3};
#[cfg(feature = "bevy")]
use bevy::prelude::GlobalTransform;
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct CoordinateSystem {
pub right: Vector3,
pub up: Vector3,
pub ahead: Vector3,
pub origin: Point,
}
impl Default for CoordinateSystem {
fn default() -> Self {
Self {
right: Vector3::new(1.0, 0.0, 0.0),
up: Vector3::new(0.0, 1.0, 0.0),
ahead: Vector3::new(0.0, 0.0, 1.0),
origin: Vector3::new(0.0, 0.0, 0.0),
}
}
}
impl From<CoordinateSystem> for audionimbus_sys::IPLCoordinateSpace3 {
fn from(coordinate_system: CoordinateSystem) -> Self {
Self {
right: coordinate_system.right.into(),
up: coordinate_system.up.into(),
ahead: coordinate_system.ahead.into(),
origin: coordinate_system.origin.into(),
}
}
}
impl From<audionimbus_sys::IPLCoordinateSpace3> for CoordinateSystem {
fn from(coordinate_system: audionimbus_sys::IPLCoordinateSpace3) -> Self {
Self {
right: coordinate_system.right.into(),
up: coordinate_system.up.into(),
ahead: coordinate_system.ahead.into(),
origin: coordinate_system.origin.into(),
}
}
}
#[cfg(feature = "bevy")]
impl From<GlobalTransform> for CoordinateSystem {
fn from(global_transform: GlobalTransform) -> Self {
Self {
right: global_transform.right().to_array().into(),
up: global_transform.up().to_array().into(),
ahead: global_transform.forward().to_array().into(),
origin: global_transform.translation().to_array().into(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_coordinate_system_default() {
let cs = CoordinateSystem::default();
assert_eq!(
cs,
CoordinateSystem {
right: Vector3::new(1.0, 0.0, 0.0),
up: Vector3::new(0.0, 1.0, 0.0),
ahead: Vector3::new(0.0, 0.0, 1.0),
origin: Vector3::new(0.0, 0.0, 0.0),
}
);
}
}