Guest User

Untitled

a guest
Jan 23rd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. use std::ops::{Add, Div, Index, Mul, Sub};
  2.  
  3. #[derive(Debug)]
  4. pub struct Vec3 {
  5. inner: [f32; 3],
  6. }
  7.  
  8. impl Vec3 {
  9. pub fn new(a: f32, b: f32, c: f32) -> Vec3 {
  10. Vec3 { inner: [a, b, c] }
  11. }
  12. }
  13.  
  14. impl Mul<Vec3> for Vec3 {
  15. type Output = Vec3;
  16.  
  17. fn mul(self, o: Vec3) -> Vec3 {
  18. Vec3 {
  19. inner: [
  20. self.inner[0] * o.inner[0],
  21. self.inner[1] * o.inner[1],
  22. self.inner[2] * o.inner[2],
  23. ],
  24. }
  25. }
  26. }
  27.  
  28. impl Mul<f32> for Vec3 {
  29. type Output = Vec3;
  30.  
  31. fn mul(self, o: f32) -> Vec3 {
  32. Vec3 {
  33. inner: [self.inner[0] * o, self.inner[1] * o, self.inner[2] * o],
  34. }
  35. }
  36. }
  37.  
  38. fn main() {
  39.  
  40. let v = Vec3::new(1.0, 1.0, 1.0);
  41.  
  42. println!("{:?}", v * 0.5);
  43. }
Add Comment
Please, Sign In to add comment