CubeDrawer.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using UnityEngine;
  2. namespace Popcron
  3. {
  4. public class CubeDrawer : Drawer
  5. {
  6. public override int Draw(ref Vector3[] buffer, params object[] values)
  7. {
  8. Vector3 position = (Vector3)values[0];
  9. Quaternion rotation = (Quaternion)values[1];
  10. Vector3 size = (Vector3)values[2];
  11. size *= 0.5f;
  12. Vector3 point1 = new Vector3(position.x - size.x, position.y - size.y, position.z - size.z);
  13. Vector3 point2 = new Vector3(position.x + size.x, position.y - size.y, position.z - size.z);
  14. Vector3 point3 = new Vector3(position.x + size.x, position.y + size.y, position.z - size.z);
  15. Vector3 point4 = new Vector3(position.x - size.x, position.y + size.y, position.z - size.z);
  16. Vector3 point5 = new Vector3(position.x - size.x, position.y - size.y, position.z + size.z);
  17. Vector3 point6 = new Vector3(position.x + size.x, position.y - size.y, position.z + size.z);
  18. Vector3 point7 = new Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
  19. Vector3 point8 = new Vector3(position.x - size.x, position.y + size.y, position.z + size.z);
  20. point1 = rotation * (point1 - position);
  21. point1 += position;
  22. point2 = rotation * (point2 - position);
  23. point2 += position;
  24. point3 = rotation * (point3 - position);
  25. point3 += position;
  26. point4 = rotation * (point4 - position);
  27. point4 += position;
  28. point5 = rotation * (point5 - position);
  29. point5 += position;
  30. point6 = rotation * (point6 - position);
  31. point6 += position;
  32. point7 = rotation * (point7 - position);
  33. point7 += position;
  34. point8 = rotation * (point8 - position);
  35. point8 += position;
  36. //square
  37. buffer[0] = point1;
  38. buffer[1] = point2;
  39. buffer[2] = point2;
  40. buffer[3] = point3;
  41. buffer[4] = point3;
  42. buffer[5] = point4;
  43. buffer[6] = point4;
  44. buffer[7] = point1;
  45. //other square
  46. buffer[8] = point5;
  47. buffer[9] = point6;
  48. buffer[10] = point6;
  49. buffer[11] = point7;
  50. buffer[12] = point7;
  51. buffer[13] = point8;
  52. buffer[14] = point8;
  53. buffer[15] = point5;
  54. //connectors
  55. buffer[16] = point1;
  56. buffer[17] = point5;
  57. buffer[18] = point2;
  58. buffer[19] = point6;
  59. buffer[20] = point3;
  60. buffer[21] = point7;
  61. buffer[22] = point4;
  62. buffer[23] = point8;
  63. return 24;
  64. }
  65. }
  66. }