bevy/crates/bevy_math/src/face_toward.rs
2020-07-16 17:11:52 -07:00

20 lines
510 B
Rust

use crate::{Mat4, Vec3};
pub trait FaceToward {
fn face_toward(eye: Vec3, center: Vec3, up: Vec3) -> Self;
}
impl FaceToward for Mat4 {
fn face_toward(eye: Vec3, center: Vec3, up: Vec3) -> Self {
let forward = (center - eye).normalize();
let right = up.cross(forward).normalize();
let up = forward.cross(right);
Mat4::from_cols(
right.extend(0.0),
up.extend(0.0),
forward.extend(0.0),
eye.extend(1.0),
)
}
}