From 9d786ab096ed36ea384e03ee5cea498790e31eec Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Sun, 17 Jul 2022 20:26:28 +0200 Subject: wip --- Samples/AnimTest/Animation/Path.cs | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Samples/AnimTest/Animation/Path.cs (limited to 'Samples/AnimTest/Animation/Path.cs') diff --git a/Samples/AnimTest/Animation/Path.cs b/Samples/AnimTest/Animation/Path.cs new file mode 100644 index 00000000..1f04e090 --- /dev/null +++ b/Samples/AnimTest/Animation/Path.cs @@ -0,0 +1,51 @@ +// Copyright (c) 2015-2021 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +using System.Numerics; + +namespace vke { + public class Path + { + public Vector3 Start; + public Vector3 End; + + float length; + Vector3 vDir; + + public Path(Vector3 startPos, Vector3 endPos){ + Start = startPos; + End = endPos; + initialComputations (); + } + protected void initialComputations(){ + Vector3 vPath = End - Start; + vDir = Vector3.Normalize (vPath); + length = vPath.Length(); + } + /// + /// Get single step on the path + /// + /// return position on the path + /// Position expressed as percentage of total length + public virtual Vector3 GetStep(float pos){ + return Start + vDir * length * pos; + } + + public static Vector3 CalculateBezierPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3) + { + float u = 1 - t; + float tt = t * t; + float uu = u * u; + float uuu = uu * u; + float ttt = tt * t; + + Vector3 p = uuu * p0; + p += 3 * uu * t * p1; + p += 3 * u * tt * p2; + p += ttt * p3; + + return p; + } + } + +} -- cgit v1.3.1-4-g156e