/// <summary> /// Transforms a point in local tile space to world space. /// </summary> public Int2 TransformLocalToWorld(Int2 localPosition) { Float2 localCenter = (archetype.Size - Float2.one) / 2f; //Not rotated center Float2 center = (Size - Float2.one) / 2f; //Rotated center of the cube Float2 offset = localPosition - localCenter; //The position compared to center return((center + offset.Rotate(-rotation)).Rounded + mainPosition); }
/// <summary> /// 优化路线 /// </summary> /// <param name="lineStart">线段起点</param> /// <param name="lineEnd">线段终点</param> /// <param name="near">与动态挡格相交 near点</param> /// <param name="far">与动态挡格相交 far点</param> /// <param name="listMidPoint">2个交点之间的路线</param> /// <returns></returns> public static List <Float2> OptimizationLine(Float2 lineStart, Float2 lineEnd, Float2 near, Float2 far, bool isCounterclockwiseDir, List <Float2> listMidPoint) { if (listMidPoint == null || listMidPoint.Count == 0) { return(listMidPoint); } #if UNITY_EDITOR // List<Float2> l = new List<Float2>(); // l.Add(near); // l.AddRange(listMidPoint); // l.Add(far); // SkillObb.instance.TargetPoly = l.ToArray(); #endif List <Float2> listOptimizationLine = listMidPoint; // 先顺序来一次优化 Float2 outdir = (lineEnd - lineStart).normalized; if (isCounterclockwiseDir == false) { outdir = Float2.Rotate(outdir, MathUtil.kPI - MathUtil.kEpsilon); } else { outdir = Float2.Rotate(outdir, -MathUtil.kPI + MathUtil.kEpsilon); } listOptimizationLine = SearchOutPoint(lineStart, far, outdir.normalized, listOptimizationLine); // 再倒序来一次优化 listOptimizationLine.Reverse(); outdir = (lineEnd - lineStart).normalized; if (isCounterclockwiseDir == true) { outdir = Float2.Rotate(outdir, MathUtil.kPI - MathUtil.kEpsilon); } else { outdir = Float2.Rotate(outdir, -MathUtil.kPI + MathUtil.kEpsilon); } listOptimizationLine = SearchOutPoint(lineEnd, near, outdir.normalized, listOptimizationLine); listOptimizationLine.Reverse(); // return(listOptimizationLine); }
public static Float2 RotateD(this Float2 f, float degrees) { return(f.Rotate(degrees * MathFast.Deg2Rad)); }