Implemting multiplication of vector3 with scalar
This commit is contained in:
parent
31c9bda5a2
commit
07b2fc28d8
12
src/main.rs
12
src/main.rs
@ -1,4 +1,4 @@
|
||||
use std::ops::{Add, Sub};
|
||||
use std::ops::{Add, Mul, Sub};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Vector3 {
|
||||
@ -29,13 +29,23 @@ impl Sub for Vector3 {
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<f64> for Vector3 {
|
||||
type Output = Vector3;
|
||||
|
||||
fn mul(self, rhs: f64) -> Self::Output {
|
||||
Vector3::new(self.x * rhs, self.y * rhs, self.z * rhs)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let vec1 = Vector3::new(1.0, 0.0, 0.0);
|
||||
let vec2 = Vector3::new(0.0, 1.0, 0.0);
|
||||
|
||||
let vec3 = vec1 + vec2;
|
||||
let vec4 = vec1 - vec2;
|
||||
let vec5 = vec4 * 3.14159;
|
||||
|
||||
println!("x = {}, y = {}, z = {}", vec3.x, vec3.y, vec3.z);
|
||||
println!("x = {}, y = {}, z = {}", vec4.x, vec4.y, vec4.z);
|
||||
println!("x = {}, y = {}, z = {}", vec5.x, vec5.y, vec5.z);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user