ft: 5,6.1: sphere class + normals
This commit is contained in:
21
src/vec3.rs
21
src/vec3.rs
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user