Vector4.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 Vector4
  10. {
  11. public float x, y, z, w;
  12. public Vector4(float x, float y, float z, float w)
  13. {
  14. this.x = x;
  15. this.y = y;
  16. this.z = z;
  17. this.w = w;
  18. }
  19. public Vector4(ArrayList arr)
  20. {
  21. this.x = (float)(double)arr[0];
  22. this.y = (float)(double)arr[1];
  23. this.z = (float)(double)arr[2];
  24. this.w = (float)(double)arr[3];
  25. }
  26. public static Vector4 operator+(Vector4 a, Vector4 b)
  27. {
  28. return new Vector4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
  29. }
  30. public static Vector4 operator-(Vector4 a, Vector4 b)
  31. {
  32. return new Vector4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
  33. }
  34. public static Vector4 operator*(Vector4 a, float k)
  35. {
  36. return new Vector4(a.x * k, a.y * k, a.z * k, a.w * k);
  37. }
  38. public static Vector4 operator*(float k, Vector4 a)
  39. {
  40. return a * k;
  41. }
  42. public override string ToString()
  43. {
  44. return string.Format("{0}, {1}, {2}, {3}", x, y, z, w);
  45. }
  46. }
  47. }