204 lines
3.9 KiB
C#
204 lines
3.9 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Page Flip")]
|
|
public class MegaPageFlip : MegaModifier
|
|
{
|
|
public bool animT;
|
|
|
|
public bool autoMode = true;
|
|
|
|
public bool lockRho = true;
|
|
|
|
public bool lockTheta = true;
|
|
|
|
public float timeStep = 0.01f;
|
|
|
|
public float rho;
|
|
|
|
public float theta;
|
|
|
|
public float deltaT;
|
|
|
|
public float kT = 1f;
|
|
|
|
public float turn;
|
|
|
|
public float ap1 = -15f;
|
|
|
|
public float ap2 = -2.5f;
|
|
|
|
public float ap3 = -3.5f;
|
|
|
|
public bool flipx = true;
|
|
|
|
private Vector3 apex = new Vector3(0f, 0f, -3f);
|
|
|
|
private Vector3 _cornerP;
|
|
|
|
private Vector3 _pageOrigin;
|
|
|
|
private float fx = 1f;
|
|
|
|
public void calcAuto(float t)
|
|
{
|
|
float num = (float)Math.PI / 2f;
|
|
if (t == 0f)
|
|
{
|
|
rho = 0f;
|
|
theta = num;
|
|
apex.z = ap1;
|
|
}
|
|
else if (t <= 0.15f)
|
|
{
|
|
float f = t / 0.15f;
|
|
float ft = Mathf.Sin((float)Math.PI * Mathf.Pow(f, 0.05f) / 2f);
|
|
float ft2 = Mathf.Sin((float)Math.PI * Mathf.Pow(f, 0.5f) / 2f);
|
|
rho = t * 180f;
|
|
theta = funcLinear(ft, (float)Math.PI / 2f, (float)Math.PI * 2f / 45f);
|
|
apex.z = funcLinear(ft2, ap1, ap2);
|
|
}
|
|
else if (t <= 0.4f)
|
|
{
|
|
float f = (t - 0.15f) / 0.25f;
|
|
rho = t * 180f;
|
|
theta = funcLinear(f, (float)Math.PI * 2f / 45f, (float)Math.PI / 30f);
|
|
apex.z = funcLinear(f, ap2, ap3);
|
|
}
|
|
else if (t <= 1f)
|
|
{
|
|
float f = (t - 0.4f) / 0.6f;
|
|
rho = t * 180f;
|
|
float ft = Mathf.Sin((float)Math.PI * Mathf.Pow(f, 10f) / 2f);
|
|
float ft2 = Mathf.Sin((float)Math.PI * Mathf.Pow(f, 2f) / 2f);
|
|
theta = funcLinear(ft, (float)Math.PI / 30f, (float)Math.PI / 2f);
|
|
apex.z = funcLinear(ft2, ap3, ap1);
|
|
}
|
|
}
|
|
|
|
public float calcTheta(float _rho)
|
|
{
|
|
int num = 0;
|
|
float num2 = 1f;
|
|
float num3 = 0.05f;
|
|
float num4 = (float)Math.PI / 2f;
|
|
float num5 = (num2 - num3) * num4;
|
|
float num6 = _rho / 180f;
|
|
if (num6 < 0.25f)
|
|
{
|
|
num = (int)(num6 / 0.25f);
|
|
}
|
|
else if (num6 < 0.5f)
|
|
{
|
|
num = 1;
|
|
}
|
|
else if (num6 <= 1f)
|
|
{
|
|
num = (int)((1f - num6) * 0.5f);
|
|
}
|
|
return num4 - (float)num * num5;
|
|
}
|
|
|
|
public float calcTheta2(float t)
|
|
{
|
|
float num = 0.1f;
|
|
float num2 = (float)Math.PI / 4f;
|
|
float num3 = Mathf.Abs(1f - t * 2f);
|
|
return num * num2 + num3 * num2;
|
|
}
|
|
|
|
public Vector3 curlTurn(Vector3 p)
|
|
{
|
|
float num = Mathf.Sqrt(p.x * p.x + Mathf.Pow(p.z - apex.z, 2f));
|
|
float num2 = num * Mathf.Sin(theta);
|
|
float f = Mathf.Asin(p.x / num) / Mathf.Sin(theta);
|
|
p.x = num2 * Mathf.Sin(f);
|
|
p.z = num + apex.z - num2 * (1f - Mathf.Cos(f)) * Mathf.Sin(theta);
|
|
p.y = num2 * (1f - Mathf.Cos(f)) * Mathf.Cos(theta);
|
|
return p;
|
|
}
|
|
|
|
public float funcLinear(float ft, float f0, float f1)
|
|
{
|
|
return f0 + (f1 - f0) * ft;
|
|
}
|
|
|
|
public float funcQuad(float ft, float f0, float f1, float p)
|
|
{
|
|
return f0 + (f1 - f0) * Mathf.Pow(ft, p);
|
|
}
|
|
|
|
public override string ModName()
|
|
{
|
|
return "PageFlip";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=271";
|
|
}
|
|
|
|
public Vector3 flatTurn1(Vector3 p)
|
|
{
|
|
float x = p.x;
|
|
p.x = Mathf.Cos(rho * ((float)Math.PI / 180f)) * x;
|
|
p.y = Mathf.Sin(rho * ((float)Math.PI / 180f)) * (0f - x);
|
|
return p;
|
|
}
|
|
|
|
public Vector3 rotpage(Vector3 p)
|
|
{
|
|
float x = p.x;
|
|
float y = p.y;
|
|
p.x = Mathf.Cos(rho * ((float)Math.PI / 180f)) * x + Mathf.Sin(rho * ((float)Math.PI / 180f)) * y;
|
|
p.y = Mathf.Sin(rho * ((float)Math.PI / 180f)) * (0f - x) + Mathf.Cos(rho * ((float)Math.PI / 180f)) * y;
|
|
return p;
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
p = tm.MultiplyPoint3x4(p);
|
|
p = curlTurn(p);
|
|
p.x *= fx;
|
|
p = rotpage(p);
|
|
p.x *= fx;
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
public override bool ModLateUpdate(MegaModContext mc)
|
|
{
|
|
return Prepare(mc);
|
|
}
|
|
|
|
public override bool Prepare(MegaModContext mc)
|
|
{
|
|
if (flipx)
|
|
{
|
|
fx = -1f;
|
|
}
|
|
else
|
|
{
|
|
fx = 1f;
|
|
}
|
|
theta = (float)Math.PI / 12f;
|
|
if (turn < 0f)
|
|
{
|
|
turn = 0f;
|
|
}
|
|
if (turn > 100f)
|
|
{
|
|
turn = 100f;
|
|
}
|
|
deltaT = turn / 100f;
|
|
if (animT)
|
|
{
|
|
deltaT = kT * Time.time % 1f;
|
|
}
|
|
if (autoMode)
|
|
{
|
|
calcAuto(deltaT);
|
|
}
|
|
return true;
|
|
}
|
|
}
|