Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::ops::{Add, Div, Index, Mul, Sub};
- #[derive(Debug)]
- pub struct Vec3 {
- inner: [f32; 3],
- }
- impl Vec3 {
- pub fn new(a: f32, b: f32, c: f32) -> Vec3 {
- Vec3 { inner: [a, b, c] }
- }
- }
- impl Mul<Vec3> for Vec3 {
- type Output = Vec3;
- fn mul(self, o: Vec3) -> Vec3 {
- Vec3 {
- inner: [
- self.inner[0] * o.inner[0],
- self.inner[1] * o.inner[1],
- self.inner[2] * o.inner[2],
- ],
- }
- }
- }
- impl Mul<f32> for Vec3 {
- type Output = Vec3;
- fn mul(self, o: f32) -> Vec3 {
- Vec3 {
- inner: [self.inner[0] * o, self.inner[1] * o, self.inner[2] * o],
- }
- }
- }
- fn main() {
- let v = Vec3::new(1.0, 1.0, 1.0);
- println!("{:?}", v * 0.5);
- }
Add Comment
Please, Sign In to add comment