This code creates a heightmap using a TVLandscape. Useful if you want to export your terrain data, or if you’re using dynamic terrains. By Rynus_Rein.
Public Function DrawHeightMap(ByVal TVLandscape As TrueVision3D.TVLandscape) As Bitmap Dim x As Single Dim z As Single Dim posX as single, posZ as single Dim LandscapeWidth As Single, LandscapeHeight As Single Dim MaxHeight As Single Dim PointHeight As Single Dim PointColor As Single For x = posX To (LandscapeWidth * 256) + posX For z = TposZ To (LandscapeHeight * 256) + posZ If TVLandscape.GetHeight(x, z) > MaxHeight Then MaxHeight = TVLandscape.GetHeight(x, z) End If Next z Next x LandscapeWidth = LandscapeWidth * 256 LandscapeHeight = LandscapeHeight * 256 Dim bit As New Bitmap(CInt(LandscapeWidth), CInt(LandscapeHeight)) Dim g As Graphics = Graphics.FromImage(bit) Dim myPen As Pen = New Pen(Color.Blue, 1) For x = posX To LandscapeWidth + posX For z = posZ To LandscapeHeight + posZ DoEvents() PointHeight = TVLandscape.GetHeight(x, z) PointColor = CInt(255 / MaxHeight * PointHeight) myPen.Color = Color.FromArgb(255, PointColor, PointColor, PointColor) g.DrawLine(myPen, x, z, x + 1, z + 1) Next z Next x Return bit End Function
And I converted it to C# for the C#-eners
public Bitmap DrawHeightMap(TrueVision3D.TVLandscape TVLandscape) { float x; float z; float posX; float posZ; float LandscapeWidth; float LandscapeHeight; float MaxHeight; float PointHeight; float PointColor; for (int x = posX; x <= (LandscapeWidth * 256) + posX; x++) { for (int z = TposZ; z <= (LandscapeHeight * 256) + posZ; z++) { if (TVLandscape.GetHeight(x, z) > MaxHeight) { MaxHeight = TVLandscape.GetHeight(x, z); } } } LandscapeWidth = LandscapeWidth * 256; LandscapeHeight = LandscapeHeight * 256; Bitmap bit = new Bitmap(System.Convert.ToInt32(LandscapeWidth), System.Convert.ToInt32(LandscapeHeight)); Graphics g = Graphics.FromImage(bit); Pen myPen = new Pen(Color.Blue, 1); for (int x = posX; x <= LandscapeWidth + posX; x++) { for (int z = posZ; z <= LandscapeHeight + posZ; z++) { DoEvents(); PointHeight = TVLandscape.GetHeight(x, z); PointColor = System.Convert.ToInt32(255 / MaxHeight * PointHeight); myPen.Color = Color.FromArgb(255, PointColor, PointColor, PointColor); g.DrawLine(myPen, x, z, x + 1, z + 1); } } return bit; }