MegaShapeCircle.cs 762 B

1234567891011121314151617181920212223242526272829303132
  1. 
  2. using UnityEngine;
  3. [AddComponentMenu("MegaShapes/Circle")]
  4. public class MegaShapeCircle : MegaShape
  5. {
  6. public float Radius = 1.0f;
  7. const float CIRCLE_VECTOR_LENGTH = 0.5517861843f;
  8. public override void MakeShape()
  9. {
  10. Matrix4x4 tm = GetMatrix();
  11. float vector = CIRCLE_VECTOR_LENGTH * Radius;
  12. MegaSpline spline = NewSpline();
  13. for ( int ix = 0; ix < 4; ++ix )
  14. {
  15. float angle = (Mathf.PI * 2.0f) * (float)ix / (float)4;
  16. float sinfac = Mathf.Sin(angle);
  17. float cosfac = Mathf.Cos(angle);
  18. Vector3 p = new Vector3(cosfac * Radius, sinfac * Radius, 0.0f);
  19. Vector3 rotvec = new Vector3(sinfac * vector, -cosfac * vector, 0.0f);
  20. spline.AddKnot(p, p + rotvec, p - rotvec, tm);
  21. }
  22. spline.closed = true;
  23. CalcLength(); //10);
  24. }
  25. }