Here is your answer on the second problem….
Look at your content processor, and what values you have for 'bumpiness' and 'scale' for your terrain. I'm talking about the Properties window in Visual Studio when you click on the image that is your height map.
Since both of those are set at compile time, you are probably not dealing with those values in your code, but you need to be.
Your problem might be, that the HeightMapObject from JigLibX assumed a default value for bumpiness and scale and position that probably does NOT match what you have set in the content processor properties.
Experiment with drawing the collision skin of the height map, and see if it matches your generated model of terrain. Look at the way the DebugDrawer draws other collision skins, and do that with the HeghtMapObject.
Or, you can use my modified version of the class, which works perfectly for me. I actually use a different component to draw which is why you might notice i set visibility to false.
I modified the HeightmapObject in the JigLibX sample game to use scale and some values from the HeightMapInfo object differently.
Using this new constructor, it will always make sure the heightMap collsion skin that JigLibX makes, will match the HeightMap model that is generated from the HeightMap processor. Scale and position AND bumpiness.
The original code is basically saying "Pass me an object that might or might not have the info i need, and if it doesn't, i won't know what to do"…….. So i fixed it.
#region Using Statements
public class HeightmapObject : PhysicObject
public HeightmapObject(Game game, HeightMapInfo info, float scale)
this.Visible = false;
body = new Body();
collision = new CollisionSkin(null);
collision.CollisionType = (int)CollisionTypes.Terrain;
Array2D field = new Array2D(info.Heights.GetUpperBound(0), info.Heights.GetUpperBound(1));
for (int x = 0; x < info.Heights.GetUpperBound(0); x++)
for (int z = 0; z < info.Heights.GetUpperBound(1); z++)
field.SetAt(x, z, info.Heights[x, z]);
body.MoveTo(new Vector3(info.HeightmapPosition.X, info.HeightmapPosition.Y, info.HeightmapPosition.Y), Matrix.Identity);
collision.AddPrimitive(new Heightmap(field, info.HeightmapPosition.X, info.HeightmapPosition.Y, scale, scale), (int)MaterialTable.MaterialID.NotBouncyRough);
body.Immovable = true;
Notice the parts MoveTo and AddPrimitive. That is the main difference (and i apply scale).
the original version is this:
body.MoveTo(new Vector3(shift.X,0,shift.Y), Matrix.Identity);
collision.AddPrimitive(new Heightmap(field, shift.X, shift.Y, 1, 1), new MaterialProperties(0.7f,0.7f,0.6f));
the part "1, 1" is what was messing you up. The scale is HARD CODED. Yuck. Also, in mine, you can position it anywhere but in the original, you are stuck to 0 on the Y coord. I have no idea why and seems to serve no purpose.