public static BezierGroup Transformation(BezierGroup bzgroup, Vector3?startPoint = null, Vector3?startDirection = null, Vector3?symmetryPoint = null, Vector3?symmetryAxis = null) { BezierGroup newGroup = new BezierGroup(); for (int i = 0; i < bzgroup.Count; i++) { Bezier bz = new Bezier(bzgroup[i].P0, bzgroup[i].P1, bzgroup[i].P2, bzgroup[i].P3); // 如果 symmetryPoint 和 symmetryAxis 同时存在, 优先处理 symmetryPoint. if (symmetryPoint.HasValue) { bz.SymmetryTranslateByPoint((Vector3)symmetryPoint); } if (symmetryAxis.HasValue) { bz.SymmetryTranslateByAxis((Vector3)symmetryAxis); } if (startPoint.HasValue || startDirection.HasValue) { if (i == 0) { bz.TranslateTo(startPoint, startDirection); } else { bz.TranslateTo(newGroup[-1].P3, newGroup[-1].P3 - newGroup[-1].P2); } } newGroup.AddBizer(bz); } return(newGroup); }
public static BezierGroup FromJsonData(JsonObject data) { BezierGroup bzg = new BezierGroup(); List <string> keys = new List <string>(); foreach (var k in data.Keys) { keys.Add((string)k); } keys.Sort(); List <Vector3> tempP = new List <Vector3>(); for (int i = 0; i < keys.Count; i++) { string k = keys[i]; List <object> xy = (List <object>)data[k]; Vector3 p = new Vector3((float)xy[0], (float)xy[1]); tempP.Add(p); if (tempP.Count == 4) { var bz = new Bezier(tempP[0], tempP[1], tempP[2], tempP[3]); bzg.AddBizer(bz); tempP.Clear(); tempP.Add(p); } } return(bzg); }
public static BezierGroup Reverse(BezierGroup bzgroup) { BezierGroup newGroup = new BezierGroup(); for (int i = bzgroup.Count - 1; i >= 0; i--) { Bezier bz = new Bezier(bzgroup[i].P3, bzgroup[i].P2, bzgroup[i].P1, bzgroup[i].P0); newGroup.AddBizer(bz); } return(newGroup); }
public void Initialize(BezierGroup curve, float velocity, Vector3?toward = null, bool smoothStart = false, bool allowLoop = false) { this.curve = curve; this.V = velocity; if (toward.HasValue) { this.toward = (Vector3)toward; } this.smoothStart = smoothStart; this.allowLoop = allowLoop; }
private void CodeToBezierUiButtonOnClick(object sender, RoutedEventArgs e) { var txt = SourceCode1.Text; SourceCode2.Text = SourceCode3.Text = SourceCode4.Text = ""; ReDrawCanvas(); IBezierGroup bg = _runners[0]?.BezierGroup; if (bg == null || bg.FragmentsCount == 0) { txt = txt .Replace(" ", "") .Replace("\t", "") .Replace("\n", "") .Replace("\r", "") .Replace("return", "") .ToLowerInvariant(); if (txt.StartsWith("bezier(")) { txt = RemoveBezierNonNumbers(txt); var arr = ToNumbers(txt); if (arr.Length == 4) { IBezierGroupBuilder bgb = new BezierGroup(); bgb.from(0, 0); bgb.to(1, 1).curve(arr[0], arr[1], arr[2], arr[3]); bg = (IBezierGroup)bgb; } else if (arr.Length == 8) { IBezierGroupBuilder bgb = new BezierGroup(); bgb.from(arr[0], arr[1]); bgb.to(arr[6], arr[7]).curve(arr[2], arr[3], arr[4], arr[5]); bg = (IBezierGroup)bgb; } } else if (txt.StartsWith("bezier2parts")) { txt = RemoveBezierNonNumbers(txt); var arr = ToNumbers(txt); if (arr.Length == (8 * 2 - 2)) { IBezierGroupBuilder bgb = new BezierGroup(); bgb.from(arr[0], arr[1]); bgb.to(arr[6], arr[7]).curve(arr[2], arr[3], arr[4], arr[5]); bgb.to(arr[12], arr[13]).curve(arr[8], arr[9], arr[10], arr[11]); bg = (IBezierGroup)bgb; } } else if (txt.StartsWith("bezier3parts")) { txt = RemoveBezierNonNumbers(txt); var arr = ToNumbers(txt); if (arr.Length == (8 * 3 - 2 * 2)) { IBezierGroupBuilder bgb = new BezierGroup(); bgb.from(arr[0], arr[1]); bgb.to(arr[6], arr[7]).curve(arr[2], arr[3], arr[4], arr[5]); bgb.to(arr[12], arr[13]).curve(arr[8], arr[9], arr[10], arr[11]); bgb.to(arr[18], arr[19]).curve(arr[14], arr[15], arr[16], arr[17]); bg = (IBezierGroup)bgb; } } else if (txt.StartsWith("bezier4parts")) { txt = RemoveBezierNonNumbers(txt); var arr = ToNumbers(txt); if (arr.Length == (8 * 4 - 3 * 2)) { IBezierGroupBuilder bgb = new BezierGroup(); bgb.from(arr[0], arr[1]); bgb.to(arr[6], arr[7]).curve(arr[2], arr[3], arr[4], arr[5]); bgb.to(arr[12], arr[13]).curve(arr[8], arr[9], arr[10], arr[11]); bgb.to(arr[18], arr[19]).curve(arr[14], arr[15], arr[16], arr[17]); bgb.to(arr[24], arr[25]).curve(arr[20], arr[21], arr[22], arr[23]); bg = (IBezierGroup)bgb; } } if (bg == null) { IBezierGroupBuilder bgb = new BezierGroup(); bgb.from(0, 0); bgb.to(1, 1).curve(0.17, 0.67, 0.8, 0.33); bg = (IBezierGroup)bgb; } } // ReSharper disable once PossibleNullReferenceException GenerateBezierUi(bg, TheCanvas, this); }