MegaShapeArc.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 
  2. using UnityEngine;
  3. [AddComponentMenu("MegaShapes/Arc")]
  4. public class MegaShapeArc : MegaShape
  5. {
  6. public float from = 0.0f;
  7. public float to = 270.0f;
  8. public float radius = 1.0f;
  9. public bool pie = false;
  10. public override void MakeShape()
  11. {
  12. Matrix4x4 tm = GetMatrix();
  13. //lastout = 0.0f;
  14. //lastin = -9999.0f;
  15. // Delete all points in the existing spline
  16. MegaSpline spline = NewSpline();
  17. Vector3 origin = Vector3.zero;
  18. float fromrad = from * Mathf.Deg2Rad;
  19. float torad = to * Mathf.Deg2Rad;
  20. // Order angles properly
  21. if ( fromrad > torad )
  22. torad += Mathf.PI * 2.0f;
  23. float totAngle = torad - fromrad;
  24. float vector = veccalc(totAngle / 3.0f) * radius;
  25. // Now add all the necessary points
  26. float angStep = totAngle / 3.0f;
  27. for ( int ix = 0; ix < 4; ++ix )
  28. {
  29. float angle = fromrad + (float)ix * angStep;
  30. float sinfac = Mathf.Sin(angle);
  31. float cosfac = Mathf.Cos(angle);
  32. Vector3 p = new Vector3(cosfac * radius, sinfac * radius, 0.0f);
  33. Vector3 rotvec = new Vector3(sinfac * vector, -cosfac * vector, 0.0f);
  34. Vector3 invec = (ix == 0) ? p : p + rotvec;
  35. Vector3 outvec = (ix == 3) ? p : p - rotvec;
  36. spline.AddKnot(p, invec, outvec, tm);
  37. }
  38. if ( pie )
  39. {
  40. spline.AddKnot(origin, origin, origin);
  41. spline.closed = true;
  42. }
  43. CalcLength(); //10);
  44. //if ( reverse )
  45. //spline->Reverse(TRUE);
  46. }
  47. }