Beispiel #1
0
        public static Shape Rectangle(Vector3D size)
        {
            Shape s = new Shape();
            Mesh m = s.CreateConvex();
            Face f = m.CreateFace(4);
            Vector3D halfsize = size*0.5;

            f.Vertices[0].Pos = new Point3D(-halfsize.X, -halfsize.Y, 0);
            f.Vertices[1].Pos = new Point3D(-halfsize.X,  halfsize.Y, 0);
            f.Vertices[2].Pos = new Point3D( halfsize.X,  halfsize.Y, 0);
            f.Vertices[3].Pos = new Point3D( halfsize.X, -halfsize.Y, 0);

            return s;
        }
Beispiel #2
0
        private void runTestButtonClick(object sender, RoutedEventArgs e)
        {
            mainViewport.Children.Clear();
            blacklines.Points.Clear();
            redlines.Points.Clear();

            //create new buffers for lines
            blacklines.Color   = Colors.Black;
            redlines.Color     = Colors.Red;
            redlines.Thickness = 4;

            resultBox.Text = "Testing...\n";

            try
            {
                Shapes.Shape s = Shapes.Primitives.Rectangle(new Vector3D(1, 2, 0));
                //create the main scene
                MeshGeometry3D triangleMesh = new MeshGeometry3D();
                s.BuildMeshGeometry3D(triangleMesh);

                Color c = Colors.Blue;
                c.A = 100;
                Material material = new DiffuseMaterial(new SolidColorBrush(c));

                GeometryModel3D triangleModel = new GeometryModel3D(triangleMesh, material);
                ModelVisual3D   model         = new ModelVisual3D();
                model.Content = triangleModel;

                //if (ShowFaces)
                mainViewport.Children.Add(model);

                //if (ShowConvexes)
                s.BuildScreenSpaceLines(redlines);

                resultBox.Text += "Done\n";
            }
            catch (System.ApplicationException ex)
            {
                resultBox.Text += ex.Message + "\n";
            }
            finally
            {
                mainViewport.Children.Add(redlines);
                mainViewport.Children.Add(blacklines);
            }
        }
Beispiel #3
0
        public Shape Copy()
        {
            //create a new shape and copy the vertices
            Shape shape = new Shape();
            foreach (Vertex v in Vertices)
            {
                Vertex copy = shape.CreateVertex();
                copy.Pos = v.Pos;
            }

            //put new vertices in a quick look up table
            Vertex[] newverts = shape.Vertices.ToArray();

            //go over each convex
            foreach (Mesh c in Convexes)
            {
                //create a new convex in the new shape
                Mesh convexcopy = shape.CreateConvex();

                //copy edges
                foreach (Edge e in c.Edges)
                {
                    //create the edge and use look up table to build new vertex list
                    Edge edgecopy = convexcopy.CreateEdge();
                    edgecopy.Vertices = e.Vertices.Select(a => newverts[a.Idx]).ToArray();

                    //add this edge to each of the vertices it uses
                    foreach (Vertex v in edgecopy.Vertices) 
                        v.OwnerEdges.Add(edgecopy);
                }

                //build look up table for the edges
                Edge[] newedges = convexcopy.Edges.ToArray();

                //copy faces
                foreach (Face f in c.Faces)
                {
                    //create the face and use look up tables to build new vertex/edge list
                    Face facecopy = convexcopy.CreateFace();
                    facecopy.Vertices = f.Vertices.Select(a => newverts[a.Idx]).ToList();
                    facecopy.Edges = f.Edges.Select(a => newedges[a.Idx]).ToList();

                    //add this face to each of the vertices it uses
                    foreach (Vertex v in facecopy.Vertices)
                        v.OwnerFaces.Add(facecopy);

                    //add this face to each of the edges it uses
                    foreach (Edge e in facecopy.Edges)
                        e.OwnerFaces.Add(facecopy);

                }
            }

            return shape;
        }