private PointF[] CalculateFaceTextureCoordinates(TmxTile tmxTile, bool flipDiagonal, bool flipHorizontal, bool flipVertical) { Point imageLocation = tmxTile.LocationOnSource; Size tileSize = tmxTile.TileSize; Size imageSize = tmxTile.TmxImage.Size; PointF[] points = new PointF[4]; points[0] = imageLocation; points[1] = PointF.Add(imageLocation, new Size(tileSize.Width, 0)); points[2] = PointF.Add(imageLocation, tileSize); points[3] = PointF.Add(imageLocation, new Size(0, tileSize.Height)); PointF center = new PointF(tileSize.Width * 0.5f, tileSize.Height * 0.5f); center.X += imageLocation.X; center.Y += imageLocation.Y; TmxMath.TransformPoints_DiagFirst(points, center, flipDiagonal, flipHorizontal, flipVertical); //TmxMath.TransformPoints(points, center, flipDiagonal, flipHorizontal, flipVertical); PointF[] coordinates = new PointF[4]; coordinates[3] = PointToTextureCoordinate(points[0], imageSize); coordinates[2] = PointToTextureCoordinate(points[1], imageSize); coordinates[1] = PointToTextureCoordinate(points[2], imageSize); coordinates[0] = PointToTextureCoordinate(points[3], imageSize); // Apply a small bias to the "inner" edges of the texels // This keeps us from seeing seams //const float bias = 1.0f / 8192.0f; //const float bias = 1.0f / 4096.0f; //const float bias = 1.0f / 2048.0f; if (Program.TexelBias > 0) { float bias = 1.0f / Program.TexelBias; PointF[] multiply = new PointF[4]; multiply[0] = new PointF(1, 1); multiply[1] = new PointF(-1, 1); multiply[2] = new PointF(-1, -1); multiply[3] = new PointF(1, -1); // This nudge has to be transformed too TmxMath.TransformPoints_DiagFirst(multiply, Point.Empty, flipDiagonal, flipHorizontal, flipVertical); coordinates[0] = TmxMath.AddPoints(coordinates[0], TmxMath.ScalePoints(multiply[0], bias)); coordinates[1] = TmxMath.AddPoints(coordinates[1], TmxMath.ScalePoints(multiply[1], bias)); coordinates[2] = TmxMath.AddPoints(coordinates[2], TmxMath.ScalePoints(multiply[2], bias)); coordinates[3] = TmxMath.AddPoints(coordinates[3], TmxMath.ScalePoints(multiply[3], bias)); } return(coordinates); }