/// <summary> /// </summary> /// <param name="p"> /// </param> /// <returns> /// </returns> internal static List <PlayfieldWalls> ParseWalls(byte[] p) { BinaryReader br = new BinaryReader(new MemoryStream(p)); int counter1 = br.ReadInt32(); List <PlayfieldWalls> walls = new List <PlayfieldWalls>(100); while (counter1 > 0) { PlayfieldWalls pfws = new PlayfieldWalls(); br.ReadInt32(); // Filler int32? int counter2 = br.ReadInt32(); while (counter2 > 0) { PlayfieldWall pfw = new PlayfieldWall(); pfw.DestinationPlayfield = br.ReadInt16(); pfw.DestinationIndex = br.ReadByte(); pfw.Flags = br.ReadByte(); pfw.X = br.ReadSingle(); pfw.Y = br.ReadSingle(); pfw.Z = br.ReadSingle(); pfws.Walls.Add(pfw); counter2--; } walls.Add(pfws); counter1--; } return(walls); }
/// <summary> /// </summary> /// <param name="w1"> /// </param> /// <param name="x"> /// </param> /// <param name="z"> /// </param> /// <returns> /// </returns> private static float Distance(PlayfieldWall w1, float x, float z) { float d1 = w1.X - x; float d2 = w1.Z - z; return((float)Math.Sqrt(d1 * d1 + d2 * d2)); }
/// <summary> /// </summary> /// <param name="w1"> /// </param> /// <param name="w2"> /// </param> /// <param name="x"> /// </param> /// <param name="z"> /// </param> /// <returns> /// </returns> private static float DotProduct(PlayfieldWall w1, PlayfieldWall w2, float x, float z) { float[] AB = new float[2]; float[] BC = new float[2]; AB[0] = w2.X - w1.X; AB[1] = w2.Z - w1.Z; BC[0] = x - w2.X; BC[1] = z - w2.Z; float dot = AB[0] * BC[0] + AB[1] * BC[1]; return(dot); }
/// <summary> /// </summary> /// <param name="w1"> /// </param> /// <param name="w2"> /// </param> /// <param name="x"> /// </param> /// <param name="z"> /// </param> /// <returns> /// </returns> private static float CrossProduct(PlayfieldWall w1, PlayfieldWall w2, float x, float z) { float[] AB = new float[2]; float[] AC = new float[2]; AB[0] = w2.X - w1.X; AB[1] = w2.Z - w1.Z; AC[0] = x - w1.X; AC[1] = z - w1.Z; float cross = AB[0] * AC[1] - AB[1] * AC[0]; return(cross); }
/// <summary> /// </summary> /// <param name="w1"> /// </param> /// <param name="w2"> /// </param> /// <param name="x"> /// </param> /// <param name="z"> /// </param> /// <returns> /// </returns> private static float MinimalDistance(PlayfieldWall w1, PlayfieldWall w2, float x, float z) { if (DotProduct(w1, w2, x, z) > 0) { return(15.0f); } if (DotProduct(w2, w1, x, z) > 0) { return(15.0f); } return(Math.Abs(CrossProduct(w1, w2, x, z) / Distance(w1, w2.X, w2.Z))); }