Unify VecPtComp
with Vec1
, and VecPt
with Vec2
.
This commit is contained in:
@@ -288,17 +288,14 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class Vector : IComparable<Vector> {
|
||||
public abstract class Vector {
|
||||
public Vector() { }
|
||||
|
||||
public abstract byte Dimension { get; }
|
||||
|
||||
public abstract int CompareTo(Vector other);
|
||||
|
||||
public abstract void ApplyFrom(Vector parent);
|
||||
public abstract void ReplaceFrom(Vector parent);
|
||||
public abstract void LerpWith(Vector start, float lerpedTime, ref Vector result);
|
||||
public abstract bool IsZero();
|
||||
public abstract override string ToString();
|
||||
public abstract unsafe void ToArray(float* arr);
|
||||
|
||||
@@ -319,13 +316,10 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public class Vec1 : Vector, IComparable<Vec1> {
|
||||
public class Vec1 : Vector {
|
||||
public float Value;
|
||||
|
||||
public Vec1() { Value = 0; }
|
||||
public Vec1(string s) {
|
||||
Value = float.Parse(s);
|
||||
}
|
||||
public Vec1(float[] v) {
|
||||
Value = v[0];
|
||||
}
|
||||
@@ -335,13 +329,6 @@ namespace Cryville.Crtr {
|
||||
|
||||
public override byte Dimension { get { return 1; } }
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
return CompareTo((Vec1)other);
|
||||
}
|
||||
public int CompareTo(Vec1 other) {
|
||||
return Value.CompareTo(other.Value);
|
||||
}
|
||||
|
||||
public override void ApplyFrom(Vector parent) {
|
||||
var p = (Vec1)parent;
|
||||
Value += p.Value;
|
||||
@@ -362,10 +349,6 @@ namespace Cryville.Crtr {
|
||||
r.Value = s.Value * (1 - lerpedTime) + Value * lerpedTime;
|
||||
}
|
||||
|
||||
public override bool IsZero() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void CopyTo(Vector dest) {
|
||||
var d = (Vec1)dest;
|
||||
d.Value = Value;
|
||||
@@ -384,9 +367,6 @@ namespace Cryville.Crtr {
|
||||
public int Value;
|
||||
|
||||
public VecI1() { Value = 0; }
|
||||
public VecI1(string s) {
|
||||
Value = int.Parse(s);
|
||||
}
|
||||
public VecI1(float[] v) {
|
||||
Value = (int)Math.Round(v[0]);
|
||||
}
|
||||
@@ -396,10 +376,6 @@ namespace Cryville.Crtr {
|
||||
|
||||
public override byte Dimension { get { return 1; } }
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void ApplyFrom(Vector parent) {
|
||||
var p = (VecI1)parent;
|
||||
Value += p.Value;
|
||||
@@ -420,10 +396,6 @@ namespace Cryville.Crtr {
|
||||
r.Value = (int)(s.Value * (1 - lerpedTime) + Value * lerpedTime);
|
||||
}
|
||||
|
||||
public override bool IsZero() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void CopyTo(Vector dest) {
|
||||
var d = (VecI1)dest;
|
||||
d.Value = Value;
|
||||
@@ -442,9 +414,6 @@ namespace Cryville.Crtr {
|
||||
public float Value;
|
||||
|
||||
public Vec1m() { Value = 1; }
|
||||
public Vec1m(string s) {
|
||||
Value = float.Parse(s);
|
||||
}
|
||||
public Vec1m(float[] v) {
|
||||
Value = v[0];
|
||||
}
|
||||
@@ -454,10 +423,6 @@ namespace Cryville.Crtr {
|
||||
|
||||
public override byte Dimension { get { return 1; } }
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void ApplyFrom(Vector parent) {
|
||||
var p = (Vec1m)parent;
|
||||
Value *= p.Value;
|
||||
@@ -478,10 +443,6 @@ namespace Cryville.Crtr {
|
||||
r.Value = s.Value * (1 - lerpedTime) + Value * lerpedTime;
|
||||
}
|
||||
|
||||
public override bool IsZero() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void CopyTo(Vector dest) {
|
||||
var d = (Vec1m)dest;
|
||||
d.Value = Value;
|
||||
@@ -496,103 +457,61 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public class VecPtComp : Vector {
|
||||
float? w, h;
|
||||
public class Vec2 : Vector {
|
||||
float? x, y;
|
||||
|
||||
public VecPtComp() { w = h = 0; }
|
||||
public VecPtComp(string s) {
|
||||
Parse(s, out w, out h);
|
||||
public Vec2() { x = y = 0; }
|
||||
public Vec2(float[] v) {
|
||||
x = v[0]; y = v[1];
|
||||
}
|
||||
public VecPtComp(float[] v) {
|
||||
w = v[0]; h = v[1];
|
||||
}
|
||||
public VecPtComp(float w, float h) : base() {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
public Vec2(float x, float y) {
|
||||
this.x = x; this.y = y;
|
||||
}
|
||||
|
||||
public override byte Dimension { get { return 2; } }
|
||||
|
||||
public static void Parse(string s, out float? w, out float? h) {
|
||||
string[] c = s.Split('+');
|
||||
float rw = 0, rh = 0;
|
||||
bool aw = false, ah = false;
|
||||
if (s != "") {
|
||||
foreach (var i in c) {
|
||||
if (i == "0") {
|
||||
aw = true;
|
||||
ah = true;
|
||||
continue;
|
||||
}
|
||||
float n = float.Parse(i.Substring(0, i.Length - 1));
|
||||
if (i.EndsWith("w")) {
|
||||
rw += n;
|
||||
aw = true;
|
||||
}
|
||||
else if (i.EndsWith("h")) {
|
||||
rh += n;
|
||||
ah = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
w = aw ? rw : null;
|
||||
h = ah ? rh : null;
|
||||
}
|
||||
|
||||
public static VecPtComp Parse(string s) {
|
||||
var r = new VecPtComp();
|
||||
float? w, h;
|
||||
Parse(s, out w, out h);
|
||||
r.w = w; r.h = h;
|
||||
return r;
|
||||
}
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void ApplyFrom(Vector parent) {
|
||||
var p = (VecPtComp)parent;
|
||||
w += p.w ?? 0; h += p.h ?? 0;
|
||||
var p = (Vec2)parent;
|
||||
x += p.x.GetValueOrDefault(); y += p.y.GetValueOrDefault();
|
||||
}
|
||||
|
||||
public override void ReplaceFrom(Vector parent) {
|
||||
var p = (VecPtComp)parent;
|
||||
if (p.w.HasValue) w = p.w;
|
||||
if (p.h.HasValue) h = p.h;
|
||||
var p = (Vec2)parent;
|
||||
if (p.x.HasValue) x = p.x;
|
||||
if (p.y.HasValue) y = p.y;
|
||||
}
|
||||
|
||||
public override void LerpWith(Vector start, float lerpedTime, ref Vector result) {
|
||||
throw new NotImplementedException();
|
||||
var r = (Vec2)result;
|
||||
if (start == null) {
|
||||
r.x = x;
|
||||
r.y = y;
|
||||
return;
|
||||
}
|
||||
var s = (Vec2)start;
|
||||
r.x = x.HasValue ? (s.x.Value * (1 - lerpedTime) + x.Value * lerpedTime) : s.x.Value;
|
||||
r.y = y.HasValue ? (s.y.Value * (1 - lerpedTime) + y.Value * lerpedTime) : s.y.Value;
|
||||
}
|
||||
|
||||
public override bool IsZero() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public float ToFloat(Rect rect) {
|
||||
return (w ?? 0) * rect.width + (h ?? 0) * rect.height;
|
||||
public Vector3 ToVector2() {
|
||||
return new Vector3(x.Value, y.Value);
|
||||
}
|
||||
|
||||
public override void CopyTo(Vector dest) {
|
||||
var d = (VecPtComp)dest;
|
||||
d.w = w; d.h = h;
|
||||
}
|
||||
|
||||
public static string ToString(float? w, float? h) {
|
||||
List<string> list = new List<string>();
|
||||
if (w != null) list.Add(w.Value.ToString(CultureInfo.InvariantCulture) + "w");
|
||||
if (h != null) list.Add(h.Value.ToString(CultureInfo.InvariantCulture) + "h");
|
||||
return string.Join("+", list.ToArray());
|
||||
var d = (Vec2)dest;
|
||||
d.x = x; d.y = y;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return ToString(w, h);
|
||||
return string.Format("{0},{1}",
|
||||
x != null ? x.Value.ToString(CultureInfo.InvariantCulture) : "",
|
||||
y != null ? y.Value.ToString(CultureInfo.InvariantCulture) : ""
|
||||
);
|
||||
}
|
||||
|
||||
public override unsafe void ToArray(float* arr) {
|
||||
arr[0] = w.Value;
|
||||
arr[1] = h.Value;
|
||||
arr[0] = x.Value;
|
||||
arr[1] = y.Value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -600,28 +519,6 @@ namespace Cryville.Crtr {
|
||||
float? x, y, z;
|
||||
|
||||
public Vec3() { x = y = z = 0; }
|
||||
public Vec3(string s) {
|
||||
Match m = Regex.Match(s, @"^(\^?)(.*?),(.*?),(.*?)$");
|
||||
if (m.Groups[1].Value != "") {
|
||||
float tx = 0, ty = 0, tz = 0;
|
||||
if (m.Groups[2].Value != "")
|
||||
tx = VecPtComp.Parse(m.Groups[2].Value).ToFloat(ChartPlayer.hitRect);
|
||||
if (m.Groups[3].Value != "")
|
||||
ty = VecPtComp.Parse(m.Groups[3].Value).ToFloat(ChartPlayer.hitRect);
|
||||
if (m.Groups[4].Value != "")
|
||||
tz = VecPtComp.Parse(m.Groups[4].Value).ToFloat(ChartPlayer.hitRect);
|
||||
Vector3 r = Quaternion.LookRotation(new Vector3(tx, ty, tz)).eulerAngles;
|
||||
x = r.x; y = r.y; z = r.z;
|
||||
}
|
||||
else {
|
||||
if (m.Groups[2].Value != "")
|
||||
x = float.Parse(m.Groups[2].Value);
|
||||
if (m.Groups[3].Value != "")
|
||||
y = float.Parse(m.Groups[3].Value);
|
||||
if (m.Groups[4].Value != "")
|
||||
z = float.Parse(m.Groups[4].Value);
|
||||
}
|
||||
}
|
||||
public Vec3(float[] v) {
|
||||
x = v[0]; y = v[1]; z = v[2];
|
||||
}
|
||||
@@ -631,13 +528,9 @@ namespace Cryville.Crtr {
|
||||
|
||||
public override byte Dimension { get { return 3; } }
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void ApplyFrom(Vector parent) {
|
||||
var p = (Vec3)parent;
|
||||
x += p.x ?? 0; y += p.y ?? 0; z += p.z ?? 0;
|
||||
x += p.x.GetValueOrDefault(); y += p.y.GetValueOrDefault(); z += p.z.GetValueOrDefault();
|
||||
}
|
||||
|
||||
public override void ReplaceFrom(Vector parent) {
|
||||
@@ -661,10 +554,6 @@ namespace Cryville.Crtr {
|
||||
r.z = z.HasValue ? (s.z.Value * (1 - lerpedTime) + z.Value * lerpedTime) : s.z.Value;
|
||||
}
|
||||
|
||||
public override bool IsZero() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Vector3 ToVector3() {
|
||||
return new Vector3(x.Value, y.Value, z.Value);
|
||||
}
|
||||
@@ -689,177 +578,6 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public class VecPt : Vector {
|
||||
public float? xw, xh, yw, yh;
|
||||
|
||||
public VecPt() { xw = xh = yw = yh = 0; }
|
||||
public VecPt(string s) {
|
||||
Match m = Regex.Match(s, "^(.*?),(.*?)$");
|
||||
VecPtComp.Parse(m.Groups[1].Value, out xw, out xh);
|
||||
VecPtComp.Parse(m.Groups[2].Value, out yw, out yh);
|
||||
}
|
||||
public VecPt(float[] v) {
|
||||
xw = v[0]; xh = v[1]; yw = v[2]; yh = v[3];
|
||||
}
|
||||
public VecPt(float xw, float xh, float yw, float yh) {
|
||||
this.xw = xw; this.xh = xh; this.yw = yw; this.yh = yh;
|
||||
}
|
||||
|
||||
public override byte Dimension { get { return 4; } }
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void ApplyFrom(Vector parent) {
|
||||
var p = (VecPt)parent;
|
||||
xw += p.xw ?? 0; xh += p.xh ?? 0;
|
||||
yw += p.yw ?? 0; yh += p.yh ?? 0;
|
||||
}
|
||||
|
||||
public override void ReplaceFrom(Vector parent) {
|
||||
var p = (VecPt)parent;
|
||||
if (p.xw.HasValue) xw = p.xw;
|
||||
if (p.xh.HasValue) xh = p.xh;
|
||||
if (p.yw.HasValue) yw = p.yw;
|
||||
if (p.yh.HasValue) yh = p.yh;
|
||||
}
|
||||
|
||||
public override void LerpWith(Vector start, float lerpedTime, ref Vector result) {
|
||||
var r = (VecPt)result;
|
||||
if (start == null) {
|
||||
r.xw = xw;
|
||||
r.xh = xh;
|
||||
r.yw = yw;
|
||||
r.yh = yh;
|
||||
return;
|
||||
}
|
||||
var s = (VecPt)start;
|
||||
r.xw = xw.HasValue ? (s.xw.Value * (1 - lerpedTime) + xw.Value * lerpedTime) : s.xw.Value;
|
||||
r.xh = xh.HasValue ? (s.xh.Value * (1 - lerpedTime) + xh.Value * lerpedTime) : s.xh.Value;
|
||||
r.yw = yw.HasValue ? (s.yw.Value * (1 - lerpedTime) + yw.Value * lerpedTime) : s.yw.Value;
|
||||
r.yh = yh.HasValue ? (s.yh.Value * (1 - lerpedTime) + yh.Value * lerpedTime) : s.yh.Value;
|
||||
}
|
||||
|
||||
public override bool IsZero() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Vector2 ToVector2(Rect rect) {
|
||||
return new Vector2(
|
||||
xw.Value * rect.width + xh.Value * rect.height,
|
||||
yw.Value * rect.width + yh.Value * rect.height
|
||||
);
|
||||
}
|
||||
|
||||
public override void CopyTo(Vector dest) {
|
||||
var d = (VecPt)dest;
|
||||
d.xw = xw; d.xh = xh; d.yw = yw; d.yh = yh;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return VecPtComp.ToString(xw, xh) + "," + VecPtComp.ToString(yw, yh);
|
||||
}
|
||||
|
||||
public override unsafe void ToArray(float* arr) {
|
||||
arr[0] = xw.Value;
|
||||
arr[1] = xh.Value;
|
||||
arr[2] = yw.Value;
|
||||
arr[3] = yh.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public class VecCtrl : Vector {
|
||||
public float? xw, xh, yw, yh, z;
|
||||
public VecCtrl() { xw = xh = yw = yh = z = 0; }
|
||||
public VecCtrl(string s) {
|
||||
Match m = Regex.Match(s, "^(.*?),(.*?),(.*?)$");
|
||||
VecPtComp.Parse(m.Groups[1].Value, out xw, out xh);
|
||||
VecPtComp.Parse(m.Groups[2].Value, out yw, out yh);
|
||||
if (m.Groups[3].Value != "") z = float.Parse(m.Groups[3].Value);
|
||||
}
|
||||
public VecCtrl(float[] v) {
|
||||
xw = v[0]; xh = v[1]; yw = v[2]; yh = v[3]; z = v[4];
|
||||
}
|
||||
public VecCtrl(float xw, float xh, float yw, float yh, float z) {
|
||||
this.xw = xw; this.xh = xh; this.yw = yw; this.yh = yh; this.z = z;
|
||||
}
|
||||
|
||||
public override byte Dimension { get { return 5; } }
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void ApplyFrom(Vector parent) {
|
||||
var p = (VecCtrl)parent;
|
||||
xw += p.xw ?? 0; xh += p.xh ?? 0;
|
||||
yw += p.yw ?? 0; yh += p.yh ?? 0;
|
||||
z += p.z ?? 0;
|
||||
}
|
||||
|
||||
public override void ReplaceFrom(Vector parent) {
|
||||
var p = (VecCtrl)parent;
|
||||
if (p.xw.HasValue) xw = p.xw;
|
||||
if (p.xh.HasValue) xh = p.xh;
|
||||
if (p.yw.HasValue) yw = p.yw;
|
||||
if (p.yh.HasValue) yh = p.yh;
|
||||
if (p.z.HasValue) z = p.z;
|
||||
}
|
||||
|
||||
public override void LerpWith(Vector start, float lerpedTime, ref Vector result) {
|
||||
var r = (VecCtrl)result;
|
||||
if (start == null) {
|
||||
r.xw = xw;
|
||||
r.xh = xh;
|
||||
r.yw = yw;
|
||||
r.yh = yh;
|
||||
r.z = z;
|
||||
return;
|
||||
}
|
||||
var s = (VecCtrl)start;
|
||||
r.xw = xw.HasValue ? (s.xw.Value * (1 - lerpedTime) + xw.Value * lerpedTime) : s.xw.Value;
|
||||
r.xh = xh.HasValue ? (s.xh.Value * (1 - lerpedTime) + xh.Value * lerpedTime) : s.xh.Value;
|
||||
r.yw = yw.HasValue ? (s.yw.Value * (1 - lerpedTime) + yw.Value * lerpedTime) : s.yw.Value;
|
||||
r.yh = yh.HasValue ? (s.yh.Value * (1 - lerpedTime) + yh.Value * lerpedTime) : s.yh.Value;
|
||||
r.z = z.HasValue ? (s.z.Value * (1 - lerpedTime) + z.Value * lerpedTime) : s.z.Value;
|
||||
}
|
||||
|
||||
public override bool IsZero() {
|
||||
if (xw == null || xw != 0) return false;
|
||||
if (xh == null || xh != 0) return false;
|
||||
if (yw == null || yw != 0) return false;
|
||||
if (xh == null || xh != 0) return false;
|
||||
if (z == null || z != 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public Vector3 ToVector3(Rect rect, float deltaz) {
|
||||
return new Vector3(
|
||||
xw.Value * rect.width + xh.Value * rect.height,
|
||||
yw.Value * rect.width + yh.Value * rect.height,
|
||||
z.Value * deltaz
|
||||
);
|
||||
}
|
||||
|
||||
public override void CopyTo(Vector dest) {
|
||||
var d = (VecCtrl)dest;
|
||||
d.xw = xw; d.xh = xh; d.yw = yw; d.yh = yh; d.z = z;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return VecPtComp.ToString(xw, xh) + "," + VecPtComp.ToString(yw, yh) + "," + (z != null ? z.Value.ToString(CultureInfo.InvariantCulture) : "");
|
||||
}
|
||||
|
||||
public override unsafe void ToArray(float* arr) {
|
||||
arr[0] = xw.Value;
|
||||
arr[1] = xh.Value;
|
||||
arr[2] = yw.Value;
|
||||
arr[3] = yh.Value;
|
||||
arr[4] = z.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe class VectorSrc : PropSrc.FixedBuffer {
|
||||
const int MAX_DIMENSION = 8;
|
||||
protected readonly Func<Vector> _cb;
|
||||
|
Reference in New Issue
Block a user