I currently read out XML data with the following scheme: Position x,y,z
I try to add one new Vertex for each position node and add it to a Vertex array.
Then I try to render this list of vertices so I get all those lines connected to represent a "path" through space. (Space is 3D)
What I tried so far:
[STAThread]
static void Main()
{
var form = new RenderForm("SlimDX - MiniTri Direct3D9 Sample");
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
{
BackBufferWidth = form.ClientSize.Width,
BackBufferHeight = form.ClientSize.Height
});
form.Height = 900;
form.Width = 900;
LineVertex[] waypoints = new LineVertex[1024];
XmlDocument paths = new XmlDocument();
paths.Load("data.xml");
XmlNode rootNode = paths.DocumentElement;
int index = 0;
foreach (XmlNode waypoint in rootNode)
{
foreach (XmlNode position in waypoint)
{
Console.WriteLine(position.ChildNodes[0].InnerText);
float b = 1000.0f;
float x, y, z;
x = (float.Parse(position.ChildNodes[0].InnerText) / (b * b));
y = (float.Parse(position.ChildNodes[1].InnerText) / (b * b);
z = (float.Parse(position.ChildNodes[2].InnerText) / (b * b));
Console.WriteLine(x.ToString() + " / " + y.ToString() + " / " + z.ToString());
if (index % 2 > 0)
waypoints[index].Color = Color.Yellow.ToArgb();
else
waypoints[index].Color = Color.Red.ToArgb();
waypoints[index].Position = new Vector3(x, y, 0.0f);
}
}
MessagePump.Run(form, () =>
{
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.CornflowerBlue.ToArgb(), 0f, 1);
// Since we don't have any lights in our scene, our lines won't receive
// any light and will therefore be black...
// ...but we want them golden as an asinus aureus, so let's disable lighting.
device.SetRenderState(RenderState.Lighting, true);
device.BeginScene();
// Our struct was meant to describe a position and a color,
// let's tell the device about it.
device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;
// In this particular case SlimDX does not need the
// vertex stride, it will be automatically calculated.
device.DrawUserPrimitives(PrimitiveType.LineList, 0, waypoints.Length / 2, waypoints);
device.EndScene();
device.Present();
});
foreach (var item in ObjectTable.Objects)
item.Dispose();
}
}
But this does not work, and I am sure it is the complete wrong approach!
EDIT: So far one solution worked out, but not very well. And I also need the Vertices to be changeable at runtime, so I locked at the documentation and samples, they always use VertexBuffer() to make it possible to dynamically change the Vertices by using a DataStream as Input for the VertexBuffer.
A question still open to me is, since I am used to "Update(Time time)" formats the procedural still of DX/OpenGL oftens confuses me. So I assume that MessagePump.Run() represents the drawing call that's repeated each frame. So if some values before the drawing call change like a Vertex, that's put into the datastream, I can instantly see the updated result on the screen. Is that assumption right?