/
d.vision
/
division_math
Обзор
Документация
Войти
/
d.vision
/
division_math
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/vector3.rs
57 строк
1 KB
d.vision
Added const to functions
31 июл 2025, 10:36
31 июл 2025, 10:36
047b825
Код
Авторство
О чём код?
use crate::Vector4; use std::fmt::Debug; #[repr(C)] #[derive(PartialEq, Copy, Clone, Debug)] pub struct Vector3 { pub x: f32, pub y: f32, pub z: f32, } impl Vector3 { #[inline] pub const fn forward() -> Vector3 { Vector3 { x: 0., y: 0., z: 1., } } #[inline] pub const fn right() -> Vector3 { Vector3 { x: 1., y: 0., z: 0., } } #[inline] pub const fn up() -> Vector3 { Vector3 { x: 0., y: 1., z: 0., } } #[inline] pub fn cross(l: Vector3, r: Vector3) -> Vector3 { let c = l * Vector3::new(r.y, r.z, r.x) - Vector3::new(l.y, l.z, l.x) * r; Vector3::new(c.y, c.z, c.x) } #[inline] pub const fn dot(l: Vector3, r: Vector3) -> f32 { l.x * r.x + l.y * r.y + l.z * r.z } #[inline] pub const fn to_vec4_as_point(self) -> Vector4 { Vector4::new(self.x, self.y, self.z, 1.) } #[inline] pub const fn to_vec4_as_direction(self) -> Vector4 { Vector4::new(self.x, self.y, self.z, 0.) } }