
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?



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 0.8.8.6 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)
{
geometry.InitializeBoundingSphere();
boundingSphere = BoundingSphere.CreateMerged(boundingSphere, geometry.BoundingSphere);
balderMesh.Children.Add(geometry);
}
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;
context.AllocateVertices(3);
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));
context.AllocateFaces(1);
geometry.GeometryContext.SetFace(0, new Face(0, 1, 2));
GeometryHelper.CalculateVertexNormals(context);
return new Balder.Core.Objects.Geometries.Geometry[] { geometry };
}

