vector3.vala 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 Vector3
  10. {
  11. public double x;
  12. public double y;
  13. public double z;
  14. public Vector3(double x, double y, double z)
  15. {
  16. this.x = x;
  17. this.y = y;
  18. this.z = z;
  19. }
  20. public Vector3.from_array(ArrayList<Value?> arr)
  21. {
  22. this.x = (double)arr[0];
  23. this.y = (double)arr[1];
  24. this.z = (double)arr[2];
  25. }
  26. public ArrayList<Value?> to_array()
  27. {
  28. ArrayList<Value?> arr = new ArrayList<Value?>();
  29. arr.add(this.x);
  30. arr.add(this.y);
  31. arr.add(this.z);
  32. return arr;
  33. }
  34. public string to_string()
  35. {
  36. return "%f, %f, %f".printf(x, y, z);
  37. }
  38. }
  39. public const Vector3 VECTOR3_ZERO = { 0.0, 0.0, 0.0 };
  40. public const Vector3 VECTOR3_ONE = { 1.0, 1.0, 1.0 };
  41. public const Vector3 VECTOR3_MIN = {-double.MAX, -double.MAX, -double.MAX };
  42. public const Vector3 VECTOR3_MAX = { double.MAX, double.MAX, double.MAX };
  43. }