Creating Terrain Heightmap

Nov 1, 2010 at 4:11 PM

After a week of none stop looking for a way to create a Heightmap that I can use of a simple game I am unable to figure out how to use any of the code I have found to make a useible terrain for 3d using silverlight and balder.  Can anyone please point me in the right direction?  Here is what I am working with at the moment I have stripped all my heightmap code out as I was only able to get the sample to work provide by balder.codeplex but it seem I need more insight on how it works to do what I want.

    public class MyGame : Game
    {
        private Mesh _audi;
        private float _audiRotation;

        public override void OnInitialize()
        {
            OmniLight omniLight = new OmniLight();
            omniLight.Diffuse = Balder.Colors.Green;
            omniLight.Specular = Balder.Colors.Red;
            omniLight.Ambient = Balder.Colors.White;
            omniLight.Position.X = 0;
            omniLight.Position.Y = -7;
            omniLight.Position.Z = -1;
            Scene.AddNode(omniLight);

            Camera.Target = Balder.Math.Vector.Zero;
            Camera.Position.X = 0;
            Camera.Position.Y = -15;
            Camera.Position.Z = -175;

            base.OnInitialize();
        }

        public override void OnLoadContent()
        {
            //_audi = ContentManager.Load<Mesh>("ptank.ASE");
            //Scene.AddNode(_audi);

            base.OnLoadContent();
        }

        public override void OnUpdate()
        {
            //_audi.World = Balder.Math.Matrix.CreateRotationY(_audiRotation);
            //_audi.World = Balder.Math.Matrix.CreateRotationX(_audiRotation);
            //_audiRotation += 0.5f;
            base.OnUpdate();
        }
    }

Coordinator
Nov 1, 2010 at 9:45 PM

Hi,

the HeightMap is for now very limited. I've been meaning to create a proper Terrain object, but haven't gotten around to it. If you don't mind doing it yourself, there is quite a few samples on the InterWeb of terrain rendering using Xna - you could easily adopt one of those and make it work with Balder. 

Riemer has one : http://www.riemers.net/eng/Tutorials/XNA/Csharp/series4.php - you'd just need to translate things from Xna to Balder - create a new object like the HeightMap - or use Box as your reference.

 

Nov 2, 2010 at 2:25 AM

I'll give it a go and update this with in a week or two as to my progress.

Nov 9, 2010 at 8:48 PM

This is your Heightmap.cs file would just give me a brief overview what you are doing with each statement in your code?

#if(SILVERLIGHT)
#else
#if(!IOS)
using Colors = System.Drawing.Color;
#endif
#endif
#if(DEFAULT_CONSTRUCTOR)
using Ninject;
#endif
using Balder.Execution;
using Balder.Math;

namespace Balder.Objects.Geometries
{
    public class HeightmapOld : ArbitraryHeightmap
    {
        #if(DEFAULT_CONSTRUCTOR)
        public HeightmapOld()
            : this(Runtime.Instance.Kernel.Get<IGeometryContext>())
        {

        }
        #endif

        public HeightmapOld(IGeometryContext geometryContext) : base(geometryContext)
        {
        }

        public static Property<HeightmapOld, Dimension> DimensionProperty = Property<HeightmapOld, Dimension>.Register(p => p.Dimension);

        public Dimension Dimension
        {
            get { return DimensionProperty.GetValue(this); }
            set
            {
                DimensionProperty.SetValue(this, value);

                var halfWidth = (double)(value.Width / 2);
                var halfHeight = (double)(value.Height / 2);

                Point1 = new Coordinate(-halfWidth, 0, halfHeight);
                Point2 = new Coordinate(-halfWidth, 0, -halfHeight);
                Point3 = new Coordinate(halfWidth, 0, halfHeight);
                Point4 = new Coordinate(halfWidth, 0, -halfHeight);
                InvalidatePrepare();
            }
        }
    }
}
Coordinator
Nov 10, 2010 at 3:24 PM

Hi,

I'm not sure what you mean. 

The Heightmap inherits from ArbitraryHeightmap - all the Heightmap stuff is in that. The Heightmap only holds the definition of the Dimension, which translates into 4 arbitrary coordinates Points for the ArbitraryHeightmap to use. The Points are not that arbitrary, since you can't have anything with an Arbitrary plane for the regular Heightmap. 

So basically what it is saying is that use the base class but define the area that should contain the Height points to be based on the Dimensions given to it.