Compare commits

..

No commits in common. "f0879c0a0c75b9d800f62118d02021689351b205" and "80aec21b52a92462175123e387a061d57c793374" have entirely different histories.

1 changed files with 2 additions and 73 deletions

View File

@ -1,36 +1,5 @@
use std::fmt::{Debug, Formatter}; use std::ops::{Add, Sub};
use std::ops::{Add, Index, Mul, Sub};
pub struct Matrix3(Vec<Vector3>);
impl Debug for Matrix3 {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "[")?;
for coord in 0..3 {
for vec in self.0.iter() {
write!(f, " {:06.2}", vec[coord])?;
}
if coord == 2 {
write!(f, " ]\n")?;
} else {
write!(f, "\n ")?;
}
}
Ok(())
}
}
impl Matrix3 {
pub fn new(i: Vector3, j: Vector3, k: Vector3) -> Self {
Self { 0: vec![i, j, k] }
}
pub fn transform(&self, vector: Vector3) -> Vector3 {
self.0[0] * vector.x + self.0[1] * vector.y + self.0[2] * vector.z
}
}
#[derive(Debug)]
pub struct Vector2 { pub struct Vector2 {
pub x: f32, pub x: f32,
pub y: f32, pub y: f32,
@ -48,7 +17,6 @@ impl Vector2 {
} }
} }
#[derive(Debug, Copy, Clone)]
pub struct Vector3 { pub struct Vector3 {
pub x: f32, pub x: f32,
pub y: f32, pub y: f32,
@ -65,18 +33,6 @@ impl Default for Vector3 {
} }
} }
impl Index<usize> for Vector3 {
type Output = f32;
fn index(&self, index: usize) -> &Self::Output {
match index {
0 => &self.x,
1 => &self.y,
2 => &self.z,
_ => panic!("Index {index} is out of bounds in a Vector3!"),
}
}
}
impl Add for Vector3 { impl Add for Vector3 {
type Output = Self; type Output = Self;
fn add(self, rhs: Self) -> Self::Output { fn add(self, rhs: Self) -> Self::Output {
@ -89,7 +45,7 @@ impl Add for Vector3 {
} }
impl Sub for Vector3 { impl Sub for Vector3 {
type Output = Self; type Output = Vector3;
fn sub(self, rhs: Self) -> Self::Output { fn sub(self, rhs: Self) -> Self::Output {
Self::Output { Self::Output {
x: self.x - rhs.x, x: self.x - rhs.x,
@ -99,39 +55,12 @@ impl Sub for Vector3 {
} }
} }
impl Mul for Vector3 {
type Output = Self;
fn mul(self, rhs: Self) -> Self::Output {
Self::Output {
x: self.x * rhs.x,
y: self.y * rhs.y,
z: self.z * rhs.z,
}
}
}
impl Mul<f32> for Vector3 {
type Output = Self;
fn mul(self, rhs: f32) -> Self::Output {
Self::Output {
x: self.x * rhs,
y: self.y * rhs,
z: self.z * rhs,
}
}
}
impl Vector3 { impl Vector3 {
pub fn new(x: f32, y: f32, z: f32) -> Self { pub fn new(x: f32, y: f32, z: f32) -> Self {
Self { x, y, z } Self { x, y, z }
} }
pub fn flatten(&self) -> Vector2 {
Vector2::new(self.x, self.y)
}
} }
#[derive(Debug)]
pub struct Vertex { pub struct Vertex {
pub position: Vector3, pub position: Vector3,
pub uv: Vector2, pub uv: Vector2,