2026-01-25 09:26:30 -06:00
|
|
|
use core::ops::{Add, Mul, Sub};
|
|
|
|
|
|
2026-01-31 09:31:17 -06:00
|
|
|
use crate::pxl8::pxl8_vec3;
|
|
|
|
|
|
|
|
|
|
pub type Vec3 = pxl8_vec3;
|
2026-01-25 09:26:30 -06:00
|
|
|
|
2026-01-31 09:31:17 -06:00
|
|
|
pub const VEC3_ZERO: Vec3 = Vec3 { x: 0.0, y: 0.0, z: 0.0 };
|
|
|
|
|
pub const VEC3_Y: Vec3 = Vec3 { x: 0.0, y: 1.0, z: 0.0 };
|
|
|
|
|
|
|
|
|
|
pub trait Vec3Ext {
|
|
|
|
|
fn new(x: f32, y: f32, z: f32) -> Self;
|
|
|
|
|
fn dot(self, rhs: Self) -> f32;
|
|
|
|
|
}
|
2026-01-25 09:26:30 -06:00
|
|
|
|
2026-01-31 09:31:17 -06:00
|
|
|
impl Vec3Ext for pxl8_vec3 {
|
|
|
|
|
fn new(x: f32, y: f32, z: f32) -> Self {
|
2026-01-25 09:26:30 -06:00
|
|
|
Self { x, y, z }
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-31 09:31:17 -06:00
|
|
|
fn dot(self, rhs: Self) -> f32 {
|
2026-01-25 09:26:30 -06:00
|
|
|
self.x * rhs.x + self.y * rhs.y + self.z * rhs.z
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-31 09:31:17 -06:00
|
|
|
impl Default for pxl8_vec3 {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
VEC3_ZERO
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Add for pxl8_vec3 {
|
2026-01-25 09:26:30 -06:00
|
|
|
type Output = Self;
|
|
|
|
|
fn add(self, rhs: Self) -> Self {
|
2026-01-31 09:31:17 -06:00
|
|
|
Self {
|
|
|
|
|
x: self.x + rhs.x,
|
|
|
|
|
y: self.y + rhs.y,
|
|
|
|
|
z: self.z + rhs.z,
|
|
|
|
|
}
|
2026-01-25 09:26:30 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-31 09:31:17 -06:00
|
|
|
impl Sub for pxl8_vec3 {
|
2026-01-25 09:26:30 -06:00
|
|
|
type Output = Self;
|
|
|
|
|
fn sub(self, rhs: Self) -> Self {
|
2026-01-31 09:31:17 -06:00
|
|
|
Self {
|
|
|
|
|
x: self.x - rhs.x,
|
|
|
|
|
y: self.y - rhs.y,
|
|
|
|
|
z: self.z - rhs.z,
|
|
|
|
|
}
|
2026-01-25 09:26:30 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-31 09:31:17 -06:00
|
|
|
impl Mul<f32> for pxl8_vec3 {
|
2026-01-25 09:26:30 -06:00
|
|
|
type Output = Self;
|
|
|
|
|
fn mul(self, rhs: f32) -> Self {
|
2026-01-31 09:31:17 -06:00
|
|
|
Self {
|
|
|
|
|
x: self.x * rhs,
|
|
|
|
|
y: self.y * rhs,
|
|
|
|
|
z: self.z * rhs,
|
|
|
|
|
}
|
2026-01-25 09:26:30 -06:00
|
|
|
}
|
|
|
|
|
}
|