using System; using UnityEngine; [AddComponentMenu("Modifiers/Warps/Globe")] public class MegaGlobeWarp : MegaWarp { public float dir = -90f; public float dir1 = -90f; public MegaAxis axis; public MegaAxis axis1 = MegaAxis.Z; private Matrix4x4 mat = default(Matrix4x4); public bool twoaxis = true; private Matrix4x4 tm1 = default(Matrix4x4); private Matrix4x4 invtm1 = default(Matrix4x4); public float r; public float r1; public float radius = 10f; public bool linkRadii = true; public float radius1 = 10f; public override string WarpName() { return "Globe"; } public override string GetHelpURL() { return "?page_id=3752"; } public override Vector3 Map(int i, Vector3 p) { if (r == 0f) { return p; } p = tm.MultiplyPoint3x4(p); Vector3 a = p; float magnitude = p.magnitude; float t = Mathf.Exp((0f - totaldecay) * Mathf.Abs(magnitude)); float x = p.x; float y = p.y; float num = y / r; float num2 = Mathf.Cos((float)Math.PI - num); float num3 = Mathf.Sin((float)Math.PI - num); float x2 = r * num2 + r - x * num2; p.x = x2; float y2 = r * num3 - x * num3; p.y = y2; p = Vector3.Lerp(a, p, t); p = invtm.MultiplyPoint3x4(p); if (twoaxis) { p = tm1.MultiplyPoint3x4(p); x = p.x; y = p.y; num = y / r1; num2 = Mathf.Cos((float)Math.PI - num); num3 = Mathf.Sin((float)Math.PI - num); x2 = r1 * num2 + r1 - x * num2; p.x = x2; y2 = r1 * num3 - x * num3; p.y = y2; p = Vector3.Lerp(a, p, t); p = invtm1.MultiplyPoint3x4(p); } return p; } private void Calc() { tm = base.transform.worldToLocalMatrix; invtm = tm.inverse; mat = Matrix4x4.identity; tm1 = tm; invtm1 = invtm; switch (axis) { case MegaAxis.X: MegaMatrix.RotateZ(ref mat, (float)Math.PI / 2f); break; case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -(float)Math.PI / 2f); break; } MegaMatrix.RotateY(ref mat, (float)Math.PI / 180f * dir); SetAxis(mat); mat = Matrix4x4.identity; switch (axis1) { case MegaAxis.X: MegaMatrix.RotateZ(ref mat, (float)Math.PI / 2f); break; case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -(float)Math.PI / 2f); break; } MegaMatrix.RotateY(ref mat, (float)Math.PI / 180f * dir1); Matrix4x4 inverse = mat.inverse; tm1 = mat * tm1; invtm1 *= inverse; r = 0f - radius; if (linkRadii) { r1 = 0f - radius; } else { r1 = 0f - radius1; } } public override bool Prepare(float decay) { Calc(); totaldecay = Decay + decay; if (totaldecay < 0f) { totaldecay = 0f; } return true; } }