Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Vector3
- {
- public float x;
- public float y;
- public float z;
- }
- public static class Bezier
- {
- public static void LoadProfile()
- {
- StreamWriter sw = new StreamWriter("C:\\test.xml");
- XmlDocument xml = new XmlDocument();
- xml.Load("1-5_dwarf_gnome.xml");
- XmlNodeList nodes = xml.DocumentElement.SelectNodes("/graph/nodes/node");
- int nodeCount = 0;
- for (int i = 0; i < nodes.Count - 1; i += 2)
- {
- if (i + 2 > nodes.Count - 1) break;
- Vector3 a;
- //MessageBox.Show(nodes[i].Attributes["x"].Value);
- a.x = float.Parse(nodes[i].Attributes["x"].Value.Replace('.', ','));
- a.y = float.Parse(nodes[i].Attributes["y"].Value.Replace('.', ','));
- a.z = float.Parse(nodes[i].Attributes["z"].Value.Replace('.', ','));
- Vector3 b;
- b.x = float.Parse(nodes[i + 1].Attributes["x"].Value.Replace('.', ','));
- b.y = float.Parse(nodes[i + 1].Attributes["y"].Value.Replace('.', ','));
- b.z = float.Parse(nodes[i + 1].Attributes["z"].Value.Replace('.', ','));
- Vector3 c;
- c.x = float.Parse(nodes[i + 2].Attributes["x"].Value.Replace('.', ','));
- c.y = float.Parse(nodes[i + 2].Attributes["y"].Value.Replace('.', ','));
- c.z = float.Parse(nodes[i + 2].Attributes["z"].Value.Replace('.', ','));
- Vector3 p;
- for (float f = 0.0f; f < 1.0f; f += 0.2f)
- {
- p = Bezier.QuadraticBezier(a, b, c, f);
- sw.WriteLine("<node id=\"" + nodeCount + "\" x=\"" + p.x.ToString().Replace(',', '.') + "\" y=\"" + p.y.ToString().Replace(',', '.') + "\" z=\"" + p.z.ToString().Replace(',', '.') + "\" />");
- nodeCount++;
- }
- }
- sw.Close();
- }
- static Vector3 LinearInterpolation(Vector3 a, Vector3 b, float t)
- {
- Vector3 p;
- p.x = a.x + (b.x - a.x) * t;
- p.y = a.y + (b.y - a.y) * t;
- p.z = a.z + (b.z - a.z) * t;
- return p;
- }
- // Create a quadratic bezier curve between a and c with b as control point
- static Vector3 QuadraticBezier(Vector3 a, Vector3 b, Vector3 c, float t)
- {
- Vector3 p, ab, bc;
- ab = LinearInterpolation(a, b, t);
- bc = LinearInterpolation(b, c, t);
- p = LinearInterpolation(ab, bc, t);
- return p;
- }
- }
Add Comment
Please, Sign In to add comment