Vector3.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. using System.Collections;
  6. using System;
  7. namespace Crown
  8. {
  9. public struct Vector3
  10. {
  11. public float x, y, z;
  12. public Vector3(float x, float y, float z)
  13. {
  14. this.x = x;
  15. this.y = y;
  16. this.z = z;
  17. }
  18. public Vector3(ArrayList arr)
  19. {
  20. this.x = (float)(double)arr[0];
  21. this.y = (float)(double)arr[1];
  22. this.z = (float)(double)arr[2];
  23. }
  24. public static Vector3 operator+(Vector3 a, Vector3 b)
  25. {
  26. return new Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
  27. }
  28. public static Vector3 operator-(Vector3 a, Vector3 b)
  29. {
  30. return new Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
  31. }
  32. public static Vector3 operator*(Vector3 a, float k)
  33. {
  34. return new Vector3(a.x * k, a.y * k, a.z * k);
  35. }
  36. public static Vector3 operator*(float k, Vector3 a)
  37. {
  38. return a * k;
  39. }
  40. public override string ToString()
  41. {
  42. return string.Format("{0}, {1}, {2}", x, y, z);
  43. }
  44. }
  45. }