public void Example() { this.Name = "Elements_ModelArrows"; // <example> // Create some arrow locations. var vectors = new List <(Vector3 location, Vector3 direction, double magnitude, Color?color)>(); var target = new Vector3(15, 20); var squareSize = 25.0; var maxDistance = Math.Sqrt(Math.Pow(squareSize, 2) + Math.Pow(squareSize, 2)); for (var x = 0.0; x < squareSize; x += 1.0) { for (var y = 0.0; y < squareSize; y += 1.0) { var l = new Vector3(x, y); var d = (target - l).Unitized(); var distance = target.DistanceTo(l); var r = distance / maxDistance; var c = new Color(x / squareSize, y / squareSize, 0.0, 1.0); vectors.Add((l, d, r, c)); } } // Create a model arrows object. var modelArrows = new ModelArrows(vectors, false, true); // </example> this.Model.AddElement(modelArrows); }
public void TessellatorProducesCorrectVertexNormals() { Name = nameof(TessellatorProducesCorrectVertexNormals); var shape = new Polygon((4.96243, 50.58403), (5.78472, 50.58403), (5.78472, 65.83403), (-7.05727, 65.83403), (-7.05727, 50.57403), (4.96243, 50.57403)); var geoElem = new GeometricElement(representation: new Extrude(shape, 1, Vector3.ZAxis, false)); Model.AddElement(geoElem); var solid = geoElem.GetFinalCsgFromSolids(); var mgb = new MockGraphicsBuffer(); var arrows = new ModelArrows(); Tessellation.Tessellate(new Csg.Solid[] { solid }.Select(s => new CsgTessellationTargetProvider(solid)), mgb); for (int i = 0; i < mgb.Indices.Count; i += 3) { var a = mgb.Indices[i]; var b = mgb.Indices[i + 1]; var c = mgb.Indices[i + 2]; var verts = new[] { mgb.Vertices[a], mgb.Vertices[b], mgb.Vertices[c] }; verts.ToList().ForEach((v) => { arrows.Vectors.Add((v.position, v.normal, 0.2, Colors.Blue)); }); var triangle = new Polygon(verts.Select(v => v.position).ToList()); var normal = verts[0].normal; Assert.True(triangle.Normal().Dot(normal.Unitized()) > 0, "The vertex normals are pointing in the opposite direction as their triangles' winding should suggest"); Model.AddElement(triangle.TransformedPolygon(new Transform(normal * 0.2))); } Model.AddElement(arrows); }