43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
#![allow(dead_code)]
|
|
|
|
use bevy::math::{Quat, Vec3};
|
|
use bevy::prelude::Transform;
|
|
|
|
#[derive(Copy, Clone)]
|
|
pub struct OBB {
|
|
pub(crate) position: Vec3,
|
|
pub(crate) orientation: Quat,
|
|
pub(crate) half_size: Vec3,
|
|
}
|
|
|
|
impl OBB {
|
|
pub fn new(position: Vec3, orientation: Quat, half_size: Vec3) -> OBB {
|
|
return OBB {
|
|
position: position,
|
|
orientation: orientation,
|
|
half_size: half_size,
|
|
};
|
|
}
|
|
pub fn axis_x(&self) -> Vec3 {
|
|
return self.orientation.mul_vec3(Vec3::X);
|
|
}
|
|
pub fn axis_y(&self) -> Vec3 {
|
|
return self.orientation.mul_vec3(Vec3::Y);
|
|
}
|
|
pub fn axis_z(&self) -> Vec3 {
|
|
return self.orientation.mul_vec3(Vec3::Z);
|
|
}
|
|
pub fn as_transform(&self) -> Transform {
|
|
Transform::from_translation(self.position)
|
|
.with_rotation(self.orientation)
|
|
.with_scale(self.half_size * 2.)
|
|
}
|
|
pub fn from_transform(trans: Transform) -> OBB {
|
|
OBB {
|
|
position: trans.translation,
|
|
orientation: trans.rotation,
|
|
half_size: trans.scale / 2.,
|
|
}
|
|
}
|
|
}
|