vector3.vala 863 B

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