Triangle, line ...

Apr 7, 2010 at 3:30 PM

In tutorial I have found how to add cube or sphere into my "game". But how to use even simpler primitives like line or triangle? 

Apr 7, 2010 at 5:48 PM
For now there is no simple way of doing this, you'd have to go and create your own Geometry type and use the GeometryContext on the Geometry base class and add Vertices, Faces and Lines to it manually. This is a feature that will come at a later stage though, so one can create geometries in Xaml.
Apr 8, 2010 at 10:34 AM
Edited Apr 8, 2010 at 10:38 AM

With Balder you can create a single Triangle in CodeBehind if you want it. It's a pitty Balder is documented somewhat bad, but it is possible.

        Mesh GenerateTriangleMesh()
            Mesh balderMesh = new Mesh();
            var geo = GenerateTriangleGeo();
            var boundingSphere = new BoundingSphere(Vector.Zero, 0);
            foreach (var geometry in geo)
                boundingSphere = BoundingSphere.CreateMerged(boundingSphere, geometry.BoundingSphere);
            balderMesh.BoundingSphere = boundingSphere;
            return balderMesh;

        Balder.Core.Objects.Geometries.Geometry[] GenerateTriangleGeo()
            var format = CultureInfo.InvariantCulture.NumberFormat;
            var geometry = new Balder.Core.Objects.Geometries.Geometry();
            var context = geometry.GeometryContext;

            geometry.GeometryContext.SetVertex(0, new Vertex(-0.9549f, -1.4842f, 0.7448f));
            geometry.GeometryContext.SetVertex(1, new Vertex(-0.9549f, -1.6274f, 0.7162f));
            geometry.GeometryContext.SetVertex(2, new Vertex(-0.6920f, -1.4842f, 0.7448f));

            geometry.GeometryContext.SetFace(0, new Face(0, 1, 2));

            return new Balder.Core.Objects.Geometries.Geometry[] { geometry };