2023-11-30 22:53:17 +00:00
|
|
|
use std::ops::{Add, Sub};
|
|
|
|
|
2023-11-30 16:28:37 +00:00
|
|
|
pub struct Vector2 {
|
2023-11-30 22:53:17 +00:00
|
|
|
pub x: f32,
|
|
|
|
pub y: f32,
|
2023-11-30 16:28:37 +00:00
|
|
|
}
|
|
|
|
|
2023-11-30 22:53:17 +00:00
|
|
|
impl Default for Vector2 {
|
2023-11-30 16:28:37 +00:00
|
|
|
fn default() -> Self {
|
2023-11-30 22:53:17 +00:00
|
|
|
Self { x: 0_f32, y: 0_f32 }
|
2023-11-30 16:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Vector2 {
|
|
|
|
pub fn new(x: f32, y: f32) -> Self {
|
|
|
|
Self { x, y }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Vector3 {
|
2023-11-30 22:53:17 +00:00
|
|
|
pub x: f32,
|
|
|
|
pub y: f32,
|
|
|
|
pub z: f32,
|
2023-11-30 16:28:37 +00:00
|
|
|
}
|
|
|
|
|
2023-11-30 22:53:17 +00:00
|
|
|
impl Default for Vector3 {
|
2023-11-30 16:28:37 +00:00
|
|
|
fn default() -> Self {
|
2023-11-30 22:53:17 +00:00
|
|
|
Self {
|
|
|
|
x: 0_f32,
|
|
|
|
y: 0_f32,
|
|
|
|
z: 0_f32,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Add for Vector3 {
|
|
|
|
type Output = Self;
|
|
|
|
fn add(self, rhs: Self) -> Self::Output {
|
|
|
|
Self::Output {
|
|
|
|
x: self.x + rhs.x,
|
|
|
|
y: self.y + rhs.y,
|
|
|
|
z: self.z + rhs.z,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Sub for Vector3 {
|
|
|
|
type Output = Vector3;
|
|
|
|
fn sub(self, rhs: Self) -> Self::Output {
|
|
|
|
Self::Output {
|
|
|
|
x: self.x - rhs.x,
|
|
|
|
y: self.y - rhs.y,
|
|
|
|
z: self.z - rhs.z,
|
|
|
|
}
|
2023-11-30 16:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Vector3 {
|
|
|
|
pub fn new(x: f32, y: f32, z: f32) -> Self {
|
|
|
|
Self { x, y, z }
|
|
|
|
}
|
|
|
|
}
|
2023-11-30 23:11:20 +00:00
|
|
|
|
|
|
|
pub struct Vertex {
|
|
|
|
pub position: Vector3,
|
|
|
|
pub uv: Vector2,
|
|
|
|
pub normal: Vector3,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Vertex {
|
|
|
|
pub fn new(position: Vector3, uv: Vector2, normal: Vector3) -> Self {
|
|
|
|
Self {
|
|
|
|
position,
|
|
|
|
uv,
|
|
|
|
normal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|