MegaHumpWarp.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using UnityEngine;
  2. [AddComponentMenu("Modifiers/Warps/Hump")]
  3. public class MegaHumpWarp : MegaWarp
  4. {
  5. public float amount = 0.0f;
  6. public float cycles = 1.0f;
  7. public float phase = 0.0f;
  8. public bool animate = false;
  9. public float speed = 1.0f;
  10. public MegaAxis axis = MegaAxis.Z;
  11. float amt;
  12. Vector3 size = Vector3.zero;
  13. public override string WarpName() { return "Hump"; }
  14. public override string GetHelpURL() { return "?page_id=207"; }
  15. public override Vector3 Map(int i, Vector3 p)
  16. {
  17. p = tm.MultiplyPoint3x4(p);
  18. Vector3 ip = p;
  19. float dist = p.magnitude;
  20. float dcy = Mathf.Exp(-totaldecay * Mathf.Abs(dist));
  21. switch ( axis )
  22. {
  23. case MegaAxis.X: p.x += amt * Mathf.Sin(Mathf.Sqrt(p.x * p.x / size.x) + Mathf.Sqrt(p.y * p.y / size.y) * Mathf.PI / 0.1f * (Mathf.Deg2Rad * cycles) + phase); break;
  24. case MegaAxis.Y: p.y += amt * Mathf.Sin(Mathf.Sqrt(p.y * p.y / size.y) + Mathf.Sqrt(p.x * p.x / size.x) * Mathf.PI / 0.1f * (Mathf.Deg2Rad * cycles) + phase); break;
  25. case MegaAxis.Z: p.z += amt * Mathf.Sin(Mathf.Sqrt(p.x * p.x / size.x) + Mathf.Sqrt(p.y * p.y / size.y) * Mathf.PI / 0.1f * (Mathf.Deg2Rad * cycles) + phase); break;
  26. }
  27. p = Vector3.Lerp(ip, p, dcy);
  28. return invtm.MultiplyPoint3x4(p);
  29. }
  30. void Update()
  31. {
  32. if ( animate )
  33. {
  34. if ( Application.isPlaying )
  35. phase += Time.deltaTime * speed;
  36. }
  37. Prepare(Decay);
  38. }
  39. public override bool Prepare(float decay)
  40. {
  41. totaldecay = Decay + decay;
  42. if ( totaldecay < 0.0f )
  43. totaldecay = 0.0f;
  44. tm = transform.worldToLocalMatrix;
  45. invtm = tm.inverse;
  46. size.x = Width;
  47. size.y = Height;
  48. size.z = Length;
  49. amt = amount / 100.0f;
  50. return true;
  51. }
  52. }