vector4.vala 997 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2012-2020 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/dbartolini/crown/blob/master/LICENSE
  4. */
  5. using Gee;
  6. namespace Crown
  7. {
  8. [Compact]
  9. public struct Vector4
  10. {
  11. public double x;
  12. public double y;
  13. public double z;
  14. public double w;
  15. public Vector4(double x, double y, double z, double w)
  16. {
  17. this.x = x;
  18. this.y = y;
  19. this.z = z;
  20. this.w = w;
  21. }
  22. public Vector4.from_array(ArrayList<Value?> arr)
  23. {
  24. this.x = (double)arr[0];
  25. this.y = (double)arr[1];
  26. this.z = (double)arr[2];
  27. this.w = (double)arr[3];
  28. }
  29. public ArrayList<Value?> to_array()
  30. {
  31. ArrayList<Value?> arr = new ArrayList<Value?>();
  32. arr.add(this.x);
  33. arr.add(this.y);
  34. arr.add(this.z);
  35. arr.add(this.w);
  36. return arr;
  37. }
  38. public string to_string()
  39. {
  40. return "%f, %f, %f, %f".printf(x, y, z, w);
  41. }
  42. }
  43. public const Vector4 VECTOR4_ZERO = { 0.0, 0.0, 0.0, 0.0 };
  44. public const Vector4 VECTOR4_ONE = { 1.0, 1.0, 1.0, 1.0 };
  45. }