ft: 5,6.1: sphere class + normals

This commit is contained in:
2026-04-15 13:32:29 +02:00
parent 67c1eb861d
commit ebf39d014b
8 changed files with 126 additions and 12 deletions

View File

@@ -46,15 +46,11 @@ impl Vec3 {
(self.r * self.r + self.g * self.g + self.b * self.b) as f32
}
pub fn dot(self, other: Vec3) -> Vec3 {
Vec3 {
r: self.r * other.r,
g: self.g * other.g,
b: self.b * other.b,
}
pub fn dot(&self, other: &Vec3) -> f32 {
self.r * other.r + self.g * other.g + self.b * other.b
}
pub fn cross(self, other: Vec3) -> Vec3 {
pub fn cross(&self, other: &Vec3) -> Vec3 {
Vec3 {
r: self.g * other.b - self.b * other.g,
g: self.b * other.r - self.r * other.b,
@@ -142,6 +138,17 @@ impl AddAssign<f32> for Vec3 {
};
}
}
impl Sub<&Vec3> for Vec3 {
type Output = Self;
fn sub(self, rhs: &Self) -> Self {
Self {
r: self.r - rhs.r,
g: self.g - rhs.g,
b: self.b - rhs.b,
}
}
}
impl Sub<Vec3> for Vec3 {
type Output = Self;