/// <summary> /// Get the VectorUv along the curve /// </summary> /// <param name="leftStart">The left most point</param> /// <param name="rightStart">The right most point</param> /// <param name="far">The far corner</param> /// <param name="percentage">The percentage along the line to get</param> /// <returns>The vectorUV point along the line</returns> private VectorUvs GetBezierCurvePoint(VectorUvs leftStart, VectorUvs rightStart, VectorUvs far, float percentage) { VectorUvs partA = VectorUvs.Lerp(leftStart, far, percentage); VectorUvs partB = VectorUvs.Lerp(far, rightStart, percentage); VectorUvs target = VectorUvs.Lerp(partA, partB, percentage); return(target); }
/// <summary> /// Gets the lerp of the position and UVS /// </summary> /// <param name="leading">The leading strright before the curve starts</param> /// <param name="far">The far point</param> /// <param name="startingPercent">the amont to lepr</param> /// <returns>The new VectorUvs of the lerped position</returns> public static VectorUvs Lerp(VectorUvs leading, VectorUvs far, float startingPercent) { Vector3 leadingVector = leading.Vector; Vector3 farVector = far.Vector; Vector2 leadingUV = leading.UV; Vector2 farUV = far.UV; VectorUvs uv = new VectorUvs(); uv.Vector = Vector3.Lerp(leadingVector, farVector, startingPercent); uv.UV = Vector3.Lerp(leadingUV, farUV, startingPercent); return(uv); }
/// <summary> /// Creates a fan list from a smotherCornerContext /// </summary> /// <param name="scc">The smother corner context</param> /// <param name="startingPercent">The starting point along the first lines</param> /// <param name="sections">The number of sections to use</param> /// <returns>The list of tris, as a fan list</returns> protected List <VectorUvs> CreateFanfrom(SmotherCornerContext scc, float startingPercent, int sections) { List <VectorUvs> l = new List <VectorUvs>(); // TODO: When starting percent is 0 - are we adding the first poly twice? l.Add(scc.Main); l.Add(scc.Leading); VectorUvs leftStartUV = VectorUvs.Lerp(scc.Leading, scc.Far, startingPercent); VectorUvs rightStartUV = VectorUvs.Lerp(scc.Ending, scc.Far, startingPercent); l.Add(leftStartUV); float sectionsGap = 1.0f / sections; for (int i = 0; i < sections + 1; i++) { l.Add(GetBezierCurvePoint(leftStartUV, rightStartUV, scc.Far, (i * sectionsGap))); } l.Add(scc.Ending); return(l); }
/// <summary> /// Draw a fan of tris. /// </summary> /// <param name="fanList">The list of verts</param> protected void DrawFanTriList(List <VectorUvs> fanList) { VectorUvs a = fanList[0]; VectorUvs b = fanList[1]; VectorUvs c = fanList[2]; DrawTri(a.Vector, c.Vector, b.Vector, a.UV, c.UV, b.UV); for (int i = 3; i < fanList.Count; i++) { b = c; c = fanList[i]; DrawTri(a.Vector, c.Vector, b.Vector, a.UV, c.UV, b.UV); } }
/// <summary> /// Draw a afan of tris, starting at the far end /// </summary> /// <param name="fanList">The list of verts</param> protected void DrawFanTriListBackWards(List <VectorUvs> fanList) { VectorUvs a = fanList[0]; int count = fanList.Count - 1; VectorUvs b = fanList[count--]; VectorUvs c = fanList[count--]; DrawTri(a.Vector, c.Vector, b.Vector, a.UV, c.UV, b.UV); for (int i = 3; i < fanList.Count; i++) { b = c; c = fanList[count--]; DrawTri(a.Vector, c.Vector, b.Vector, a.UV, c.UV, b.UV); } }