Heightmap differences between x8.8 and x8.9

Mar 19, 2011 at 10:22 AM

The ESRI sample you link to build a heightmap based on Terrain.  This all works in 8.8 but when you upgrade it to 8.9 it no longer functions (there is no longer a heightmap and the terrain is flat).  Seems the guy who wrote the sample noticed this because the GeometryHelper change is commented out and the old 8.8 methods are used.  Other than that, the Game now has an extra child (the Grid) compared to before which causes a code break in the sample.  This was easily fixed using LINQ instead of the hardcoded Children indexes.  I cannot see what would cause the Heightmap to seemingly not build anymore, the code all operates but gives a flat surface in the end

Any thoughts as to what could cause such a major differences in the output changing from 8.8 to 8.9.  I cannot see anything in the changes that seems it would impact this.  I would certainly prefer to be using the newest version, I am also requiring a strong name so building myself which adds to my prefernce not to step back


Mar 19, 2011 at 3:10 PM

Looking at the code a little deeper I believe I see the problem.  It seems the SetHeightForGridPoint may have an error.  The EventArgs is not set in this method so will always be 0 here.  If using an approach where one loops through the nodes and sets the height using this method (as the ESRI example does), it will never get anything but a flat Heightmap.  The Heightmap (or ArbitaryHeightmap more precisely) looks to be expecting updates to the heightmap to come by handling the HeightInput event.  I changed my code to set the height here and it seems to work properly.  Previously where the SetHeightForGridPoint calls were made a simple call to Heightmap::InvalidateHeights() is made and this fires off the HeightInput for each node in the grid.

 I do believe that the below method should be reviewed, it seems to me that EventArgs.Height should be replaced by the height parameter and this would fix the issue I was having earlier.

Thanks for putting this together, it is a really nice application


public void SetHeightForGridPoint(int gridX, int gridY, float height, Color color)
	var actualLength = LengthSegments + 1;
	var actualHeight = HeightSegments + 1;

	if (gridX >= actualLength || gridY >= actualHeight)
		throw new ArgumentException("Point outside grid");

	var index = (gridY * actualLength) + gridX;

	var vertex = _vertices[index];
	SetVectorHeightFromVertex(vertex, EventArgs.Height, index);
	vertex.Color = color;



Mar 21, 2011 at 9:58 PM
Edited Mar 21, 2011 at 9:58 PM

Thanks, and thanks for pointing this out. I'll put up a work item for it - there might be some changes for this API in the future, as the Heightmap is a bit primitive now, and with the work being done on Xna and OpenGL, Heightmaps can be done on Vertex shaders in the GPU.

Mar 21, 2011 at 9:58 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jun 4, 2011 at 12:38 AM

What is the purpose if SetVectorHeightFromVertex?  In debug I noticed that it was unnecessarily doubling input heights.