using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Sog; using Sog.Service; using ProtoCSStruct; namespace Game { public class MoveUtils { public static PF.Vector3 GetVector3FromPosition(DBPosition pos) { return new PF.Vector3((float)pos.X / 1000, (float)pos.Y / 1000, (float)pos.Z / 1000); } public static DBPosition GetPositionFromVector3(PF.Vector3 pos) { return new DBPosition() { X = (int)(pos.x*1000), Y = (int)(pos.y*1000), Z = (int)(pos.z*1000)}; } public static bool IsPosSame(DBPosition src, DBPosition dst) { return src.X == dst.X && src.Y == dst.Y && src.Z == dst.Z; } //不开方的计算,提高效率 public static long GetDistanceSquare3D(ref DBPosition pos1, ref DBPosition pos2) { long xDis = pos1.X - pos2.X; long yDis = pos1.Y - pos2.Y; long zDis = pos1.Z - pos2.Z; return xDis * xDis + yDis * yDis + zDis * zDis; } public static long GetDistance3D(ref DBPosition pos1, ref DBPosition pos2) { long disSquare = GetDistanceSquare3D(ref pos1, ref pos2); return (long)Sog.MathUtils.FastSqrtIEEE((double)disSquare); } //不开方的计算,提高效率 public static long GetDistanceSquare2D(ref DBPosition pos1, ref DBPosition pos2) { long xDis = pos1.X - pos2.X; long zDis = pos1.Z - pos2.Z; return xDis * xDis + zDis * zDis; } public static long GetDistance2D(ref DBPosition pos1, ref DBPosition pos2) { long disSquare = GetDistanceSquare3D(ref pos1, ref pos2); return (long)Sog.MathUtils.FastSqrtIEEE((double)disSquare); } public static int ComputeCoordinate(int iDeltaX, int x, int iDist1, int iDist2) { long tmpDeltaX; int tmpX; long tmpDist1; long tmpDist2; int iRet = 0; tmpDeltaX = iDeltaX; tmpX = x; tmpDist1 = iDist1; tmpDist2 = iDist2; if (tmpDist2 == 0) { tmpDist2 = 1; } iRet = (int)((tmpDeltaX * tmpDist1) / tmpDist2) + tmpX; return iRet; } } }