private void DrawRegions() { if (compactHeightfield == null) { return; } GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.NormalArray); GL.BindBuffer(BufferTarget.ArrayBuffer, squareVbo); GL.VertexPointer(3, VertexPointerType.Float, 6 * 4, 0); GL.NormalPointer(NormalPointerType.Float, 6 * 4, 3 * 4); GL.BindBuffer(BufferTarget.ElementArrayBuffer, squareIbo); int maxdist = compactHeightfield.MaxDistance; var cellSize = heightfield.CellSize; var halfCellSize = cellSize * 0.5f; Matrix4 squareScale, squareTrans; Vector3 squarePos; Matrix4.CreateScale(cellSize.X, 1, cellSize.Z, out squareScale); for (int i = 0; i < compactHeightfield.Length; i++) { for (int j = 0; j < compactHeightfield.Width; j++) { var cell = compactHeightfield.Cells[i * compactHeightfield.Width + j]; squarePos = new Vector3(j * cellSize.X + halfCellSize.X + heightfield.Bounds.Min.X, heightfield.Bounds.Min.Y, i * cellSize.Z + halfCellSize.Z + heightfield.Bounds.Min.Z); for (int k = cell.StartIndex, kEnd = cell.StartIndex + cell.Count; k < kEnd; k++) { GL.PushMatrix(); var span = compactHeightfield.Spans[k]; int region = span.Region.Id; //if (Region.IsBorder(region)) //region = Region.RemoveFlags(region); Color4 col = regionColors[region]; GL.Color4(col); var squarePosFinal = new OpenTK.Vector3(squarePos.X, squarePos.Y, squarePos.Z); squarePosFinal.Y += span.Minimum * cellSize.Y; Matrix4.CreateTranslation(ref squarePosFinal, out squareTrans); GL.MultMatrix(ref squareTrans); GL.MultMatrix(ref squareScale); GL.DrawElements(PrimitiveType.Triangles, squareInds.Length, DrawElementsType.UnsignedByte, 0); GL.PopMatrix(); } } } GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.NormalArray); }
private void DrawRegions() { if (compactHeightfield == null) return; GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.NormalArray); GL.BindBuffer(BufferTarget.ArrayBuffer, squareVbo); GL.VertexPointer(3, VertexPointerType.Float, 6 * 4, 0); GL.NormalPointer(NormalPointerType.Float, 6 * 4, 3 * 4); GL.BindBuffer(BufferTarget.ElementArrayBuffer, squareIbo); int maxdist = compactHeightfield.MaxDistance; var cellSize = heightfield.CellSize; var halfCellSize = cellSize * 0.5f; Matrix4 squareScale, squareTrans; Vector3 squarePos; Matrix4.CreateScale(cellSize.X, 1, cellSize.Z, out squareScale); for (int i = 0; i < compactHeightfield.Length; i++) { for (int j = 0; j < compactHeightfield.Width; j++) { var cell = compactHeightfield.Cells[i * compactHeightfield.Width + j]; squarePos = new Vector3(j * cellSize.X + halfCellSize.X + heightfield.Bounds.Min.X, heightfield.Bounds.Min.Y, i * cellSize.Z + halfCellSize.Z + heightfield.Bounds.Min.Z); for (int k = cell.StartIndex, kEnd = cell.StartIndex + cell.Count; k < kEnd; k++) { GL.PushMatrix(); var span = compactHeightfield.Spans[k]; int region = span.Region.Id; //if (Region.IsBorder(region)) //region = Region.RemoveFlags(region); Color4 col = regionColors[region]; GL.Color4(col); var squarePosFinal = new OpenTK.Vector3(squarePos.X, squarePos.Y, squarePos.Z); squarePosFinal.Y += span.Minimum * cellSize.Y; Matrix4.CreateTranslation(ref squarePosFinal, out squareTrans); GL.MultMatrix(ref squareTrans); GL.MultMatrix(ref squareScale); GL.DrawElements(PrimitiveType.Triangles, squareInds.Length, DrawElementsType.UnsignedByte, 0); GL.PopMatrix(); } } } GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.NormalArray); }
private void DrawCompactHeightfield() { if (compactHeightfield == null) { return; } GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.NormalArray); GL.BindBuffer(BufferTarget.ArrayBuffer, squareVbo); GL.VertexPointer(3, VertexPointerType.Float, 6 * 4, 0); GL.NormalPointer(NormalPointerType.Float, 6 * 4, 3 * 4); GL.BindBuffer(BufferTarget.ElementArrayBuffer, squareIbo); var cellSize = heightfield.CellSize; var halfCellSize = cellSize * 0.5f; Matrix4 squareScale, squareTrans; Vector3 squarePos; Matrix4.CreateScale(cellSize.X, 1, cellSize.Z, out squareScale); for (int i = 0; i < compactHeightfield.Length; i++) { for (int j = 0; j < compactHeightfield.Width; j++) { squarePos = new Vector3(j * cellSize.X + halfCellSize.X + heightfield.Bounds.Min.X, heightfield.Bounds.Min.Y, i * cellSize.Z + halfCellSize.Z + heightfield.Bounds.Min.Z); var cell = compactHeightfield[j, i]; foreach (var span in cell) { GL.PushMatrix(); int numCons = 0; for (var dir = Direction.West; dir <= Direction.South; dir++) { if (span.IsConnected(dir)) { numCons++; } } GL.Color4(numCons / 4f, numCons / 4f, numCons / 4f, 1f); var squarePosFinal = new OpenTK.Vector3(squarePos.X, squarePos.Y, squarePos.Z); squarePosFinal.Y += span.Minimum * cellSize.Y; Matrix4.CreateTranslation(ref squarePosFinal, out squareTrans); GL.MultMatrix(ref squareTrans); GL.MultMatrix(ref squareScale); GL.DrawElements(PrimitiveType.Triangles, squareInds.Length, DrawElementsType.UnsignedByte, 0); GL.PopMatrix(); } } } GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.NormalArray); }
private void DrawCompactHeightfield() { if (compactHeightfield == null) return; GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.NormalArray); GL.BindBuffer(BufferTarget.ArrayBuffer, squareVbo); GL.VertexPointer(3, VertexPointerType.Float, 6 * 4, 0); GL.NormalPointer(NormalPointerType.Float, 6 * 4, 3 * 4); GL.BindBuffer(BufferTarget.ElementArrayBuffer, squareIbo); var cellSize = heightfield.CellSize; var halfCellSize = cellSize * 0.5f; Matrix4 squareScale, squareTrans; Vector3 squarePos; Matrix4.CreateScale(cellSize.X, 1, cellSize.Z, out squareScale); for (int i = 0; i < compactHeightfield.Length; i++) { for (int j = 0; j < compactHeightfield.Width; j++) { squarePos = new Vector3(j * cellSize.X + halfCellSize.X + heightfield.Bounds.Min.X, heightfield.Bounds.Min.Y, i * cellSize.Z + halfCellSize.Z + heightfield.Bounds.Min.Z); var cell = compactHeightfield[j, i]; foreach (var span in cell) { GL.PushMatrix(); int numCons = 0; for (var dir = Direction.West; dir <= Direction.South; dir++) { if (span.IsConnected(dir)) numCons++; } GL.Color4(numCons / 4f, numCons / 4f, numCons / 4f, 1f); var squarePosFinal = new OpenTK.Vector3(squarePos.X, squarePos.Y, squarePos.Z); squarePosFinal.Y += span.Minimum * cellSize.Y; Matrix4.CreateTranslation(ref squarePosFinal, out squareTrans); GL.MultMatrix(ref squareTrans); GL.MultMatrix(ref squareScale); GL.DrawElements(PrimitiveType.Triangles, squareInds.Length, DrawElementsType.UnsignedByte, 0); GL.PopMatrix(); } } } GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.NormalArray); }