vector4.vala 972 B

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