use crate::cross::*;
use crate::node::*;
use crate::draw::*;
pub fn cube(w: f32, h: f32, l: f32) -> Object {
let w = w / 2.;
let h = h / 2.;
let l = l / 2.;
let verts = vec![
vec3(-w, -h, l), vec3(w, -h, l), vec3(w, h, l), vec3(-w, h, l), vec3(w, h, -l), vec3(w, -h, -l), vec3(-w, -h, -l), vec3(-w, h, -l), ];
let indis = vec![
0, 1, 2, 2, 3, 0,
7, 6, 0, 0, 3, 7,
0, 6, 5, 5, 1, 0,
2, 1, 5, 5, 4, 2,
7, 3, 2, 2, 4, 7,
4, 5, 6, 6, 7, 4,
];
Object::new(Draw::new(verts, indis))
}
pub struct Camera3d {
position: LData<Vec3>,
rotation: LData<Vec3>,
fov: LData<f32>,
}
impl Camera3d {
pub fn new() -> Self {
Self {
position: LData::new(Vec3::ZERO),
rotation: LData::new(Vec3::ZERO),
fov: LData::new(60.),
}
}
pub(crate) fn get_mat(&self, window: (f32, f32)) -> Mat4 {
let (width, height) = window;
let fov = *self.fov.lock();
let view = Mat4::perspective_rh_gl(
fov.to_radians(),
width / height,
0.01, 100.0
);
let position = *self.position.lock();
let position = Mat4::from_translation(-position);
view * position
}
pub fn position(&self) -> MutexGuard<'_, Vec3> {
self.position.lock()
}
pub fn fov(&self) -> MutexGuard<'_, f32> {
self.fov.lock()
}
}