示例#1
0
        /// <summary>
        /// Get squared distance between two world locations (in meters)
        /// </summary>
        public static float GetDistanceSquared(WorldLocation location1, WorldLocation location2)
        {
            var dx = location1.Location.X - location2.Location.X;
            var dy = location1.Location.Y - location2.Location.Y;
            var dz = location1.Location.Z - location2.Location.Z;

            dx += 2048 * (location1.TileX - location2.TileX);
            dz += 2048 * (location1.TileZ - location2.TileZ);
            return(dx * dx + dy * dy + dz * dz);
        }
示例#2
0
 /// <summary>
 /// Copy constructor using a MSTS-coordinates world-location
 /// </summary>
 public WorldPosition(WorldLocation copy)
 {
     TileX    = copy.TileX;
     TileZ    = copy.TileZ;
     Location = copy.Location;
 }
示例#3
0
 /// <summary>
 /// Get a (2D) vector pointing from <paramref name="locationFrom"/> to <paramref name="locationTo"/>, so neglecting height (y) information
 /// </summary>
 public static Vector2 GetDistance2D(WorldLocation locationFrom, WorldLocation locationTo)
 {
     return(new Vector2(locationTo.Location.X - locationFrom.Location.X + (locationTo.TileX - locationFrom.TileX) * 2048, locationTo.Location.Z - locationFrom.Location.Z + (locationTo.TileZ - locationFrom.TileZ) * 2048));
 }
示例#4
0
 /// <summary>
 /// Check whether location1 and location2 are within given distance from each other
 /// </summary>
 /// <param name="location1">first location</param>
 /// <param name="location2">second location</param>
 /// <param name="distance">distance defining the boundary between 'within' and 'outside'</param>
 public static bool Within(WorldLocation location1, WorldLocation location2, float distance)
 {
     return(GetDistanceSquared(location1, location2) < distance * distance);
 }
示例#5
0
 /// <summary>
 /// Constructor from another location
 /// </summary>
 /// <param name="worldLocation">the other location to use as initialization</param>
 public WorldLocation(WorldLocation worldLocation)
 {
     TileX    = worldLocation.TileX;
     TileZ    = worldLocation.TileZ;
     Location = worldLocation.Location;
 }
示例#6
0
 /// <summary>
 /// Create a nice string-representation of the world position
 /// </summary>
 public override string ToString()
 {
     return(WorldLocation.ToString());
 }