/// <summary> /// Load a GAT file /// </summary> /// <param name="data">GAT file data</param> public static GAT Load(BinaryReader data) { string header = data.ReadBinaryString(4); //check for valid gat file if (!string.Equals(header, GAT.Header)) { throw new Exception("AltitudeLoader.Load: Header (" + header + ") is not \"GRAT\""); } //load parameters string version = Convert.ToString(data.ReadUByte()); string subversion = Convert.ToString(data.ReadUByte()); version += "." + subversion; uint width = data.ReadULong(); uint height = data.ReadULong(); GAT.Cell[] cells = new GAT.Cell[width * height]; //load the cells for (int i = 0; i < width * height; i++) { Vector4 heights = new Vector4(); heights[0] = data.ReadFloat() * 0.2f; // height 1 heights[1] = data.ReadFloat() * 0.2f; // height 2 heights[2] = data.ReadFloat() * 0.2f; // height 3 heights[3] = data.ReadFloat() * 0.2f; // height 4 cells[i].Heights = heights; cells[i].type = GAT.TYPE_TABLE[data.ReadULong()]; // type } //exports return(new GAT(width, height, cells, version)); }
/// <summary> /// Return cell height /// </summary> /// <param name="x">x position</param> /// <param name="y">y position</param> /// <returns>cell height</returns> public double GetCellHeight(double x, double y) { if (gat.cells == null) { return(0); } /* DIFF robrowser adds 0.5 to each coordinate here */ GAT.Cell cell = GetCell(x, y); // Should be at the middle of the cell x %= 1.0; y %= 1.0; double x1 = cell.Heights[0] + (cell.Heights[1] - cell.Heights[0]) * x; double x2 = cell.Heights[2] + (cell.Heights[3] - cell.Heights[2]) * x; return(-(x1 + (x2 - x1) * y)); }