Add cubic bezier functions.

This commit is contained in:
2023-03-02 10:40:18 +08:00
parent a93c081dd8
commit 215f72b3b5
3 changed files with 98 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
using Cryville.Common;
using Cryville.Common.Math;
using Cryville.Common.Pdt;
using Cryville.Crtr.Event;
using System;
@@ -152,6 +153,11 @@ namespace Cryville.Crtr {
_ctxops.Add(IdentifierManager.SharedInstance.Request("max"), new func_max(() => ContextSelfValue));
_ctxops.Add(IdentifierManager.SharedInstance.Request("abs"), new func_abs(() => ContextSelfValue));
_ctxops.Add(IdentifierManager.SharedInstance.Request("anim"), new func_anim(() => ContextSelfValue));
_ctxops.Add(IdentifierManager.SharedInstance.Request("cubic_bezier"), new func_cubic_bezier(() => ContextSelfValue));
_ctxops.Add(IdentifierManager.SharedInstance.Request("ease"), new func_cubic_bezier_fixed(0.25f, 0.1f, 0.25f, 1f, () => ContextSelfValue));
_ctxops.Add(IdentifierManager.SharedInstance.Request("ease_in"), new func_cubic_bezier_fixed(0.42f, 0f, 1f, 1f, () => ContextSelfValue));
_ctxops.Add(IdentifierManager.SharedInstance.Request("ease_out"), new func_cubic_bezier_fixed(0f, 0f, 0.58f, 1f, () => ContextSelfValue));
_ctxops.Add(IdentifierManager.SharedInstance.Request("ease_in_out"), new func_cubic_bezier_fixed(0.42f, 0f, 0.58f, 1f, () => ContextSelfValue));
Func<int, PropSrc> cccb = k => ContextCascadeLookup(k);
_ctxops.Add(IdentifierManager.SharedInstance.Request("attack_timing"), new func_attack_timing(cccb));
@@ -533,6 +539,43 @@ namespace Cryville.Crtr {
}
}
}
class func_cubic_bezier : PdtOperator {
readonly Func<PropSrc> _ctxcb;
public func_cubic_bezier(Func<PropSrc> ctxcb) : base(5) {
_ctxcb = ctxcb;
}
protected override unsafe void Execute() {
float x1 = GetOperand(0).AsNumber(), y1 = GetOperand(1).AsNumber();
float x2 = GetOperand(2).AsNumber(), y2 = GetOperand(3).AsNumber();
float time;
switch (LoadedOperandCount) {
case 4: time = oputil.AsNumber(_ctxcb()); break;
case 5: time = GetOperand(4).AsNumber(); break;
default: throw new ArgumentException("Argument count not 4 or 5");
}
GetReturnFrame(PdtInternalType.Number, sizeof(float))
.SetNumber(CubicBezier.Evaluate(time, x1, y1, x2, y2, 1e-5f));
}
}
class func_cubic_bezier_fixed : PdtOperator {
readonly float x1, y1, x2, y2;
readonly Func<PropSrc> _ctxcb;
public func_cubic_bezier_fixed(float x1, float y1, float x2, float y2, Func<PropSrc> ctxcb) : base(1) {
this.x1 = x1; this.y1 = y1;
this.x2 = x2; this.y2 = y2;
_ctxcb = ctxcb;
}
protected override void Execute() {
float time;
switch (LoadedOperandCount) {
case 0: time = oputil.AsNumber(_ctxcb()); break;
case 1: time = GetOperand(0).AsNumber(); break;
default: throw new ArgumentException("Argument count not 0 or 1");
}
GetReturnFrame(PdtInternalType.Number, sizeof(float))
.SetNumber(CubicBezier.Evaluate(time, x1, y1, x2, y2, 1e-5f));
}
}
#endregion
#region Judge Functions
static readonly int _var_fn = IdentifierManager.SharedInstance.Request("fn");