Example #1
0
        public void Draw(AngularShape shape)
        {
            if (!(shape is ShadedRectangle rectangle))
            {
                return;
            }

            float xMin = rectangle.Vertices.Vertices[0].X;
            float yMin = rectangle.Vertices.Vertices[0].Y;

            float xMax = rectangle.Vertices.Vertices[2].X;
            float yMax = rectangle.Vertices.Vertices[2].Y;

            Point p1, p2;

            for (int i = (int)xMin; i < xMax; i += 4)
            {
                p1 = new Point(i, (int)yMin);
                p2 = new Point(i, (int)yMax);

                Graphics.DrawLine(Pen, p1, p2);
            }

            for (int j = (int)yMin; j < yMax; j += 4)
            {
                p1 = new Point((int)xMin, j);
                p2 = new Point((int)xMax, j);

                Graphics.DrawLine(Pen, p1, p2);
            }

            TwoDimensionalDrawer.Draw(shape);
        }
Example #2
0
        public void Draw(AngularShape shape)
        {
            if (!(shape is ITwoDimensionalShape))
            {
                return;
            }

            var verticesConnections = shape.Vertices;
            var vertices            = verticesConnections.Vertices;
            var connections         = verticesConnections.Connections;

            PointF p1, p2;
            Vertex v1, v2;

            for (byte i = 0; i < vertices.Count; i++)
            {
                // retrieve vertex
                v1 = vertices[i];

                // draw a line
                // to connect v1 with all other vertices
                foreach (var connection in connections[i])
                {
                    v2 = vertices[connection];
                    p1 = new PointF(v1.X, v1.Y);
                    p2 = new PointF(v2.X, v2.Y);

                    Graphics.DrawLine(Pen, p1, p2);
                }
            }
        }
Example #3
0
        public void Draw(AngularShape shape)
        {
            if (!(shape is IThreeDimensionalShape))
            {
                return;
            }

            var vertices    = shape.Vertices.Vertices;
            var connections = shape.Vertices.Connections;

            PointF p1, p2;
            Vertex v1, v2;

            for (byte i = 0; i < vertices.Count; i++)
            {
                v1 = vertices[i];

                foreach (var connection in connections[i])
                {
                    v2 = vertices[connection];

                    p1 = new PointF((v1.X * COS_ALPHA * 0.9f + v1.Y), ((v1.X * SIN_ALPHA * 0.35f - v1.Z)));
                    p2 = new PointF((v2.X * COS_ALPHA * 0.9f + v2.Y), ((v2.X * SIN_ALPHA * 0.35f - v2.Z)));

                    Graphics.DrawLine(Pen, p1, p2);
                }
            }
        }
Example #4
0
        public Image Deserialize(string path)
        {
            var xDoc = new XmlDocument();

            xDoc.Load(path);
            var root   = xDoc.DocumentElement;
            var width  = float.Parse(root.GetAttribute("width"));
            var height = float.Parse(root.GetAttribute("height"));
            var image  = new Image(height, width);

            foreach (XmlElement child in root.ChildNodes[0].ChildNodes)
            {
                var          fullTypeName = child.GetAttribute("type");
                var          type         = Type.GetType(fullTypeName, true, false);
                AngularShape shape        = (AngularShape)Activator.CreateInstance(type);

                var vertexConnections = new VertexConnections()
                {
                    Vertices    = new List <Vertex>(),
                    Connections = new Dictionary <byte, List <byte> >()
                };

                shape.Vertices = vertexConnections;

                foreach (XmlElement vertexNode in child.FirstChild.ChildNodes)
                {
                    var vertex = new Vertex {
                        X = float.Parse(vertexNode.GetAttribute("X")),
                        Y = float.Parse(vertexNode.GetAttribute("Y")),
                        Z = float.Parse(vertexNode.GetAttribute("Z"))
                    };

                    shape.Vertices.Vertices.Add(vertex);
                }

                foreach (XmlElement connectionNode in child.LastChild.ChildNodes)
                {
                    var vNum      = byte.Parse(connectionNode.GetAttribute("vertex"));
                    var bytesList = new List <byte>();

                    var text = connectionNode.FirstChild.Value;
                    text = text.Replace("[", "").Replace("]", "");
                    var bytes = text.Split(',');

                    foreach (var b in bytes)
                    {
                        bytesList.Add(byte.Parse(b));
                    }

                    shape.Vertices.Connections.Add(vNum, bytesList);
                }

                image.AddShape(shape);
            }

            return(image);
        }
Example #5
0
 public void MoveShape(AngularShape shape, float x, float y)
 {
     shape.Move(shape.OffsetX + x, shape.OffsetY + y, shape.OffsetZ);
 }
Example #6
0
 public void AddShape(AngularShape shape)
 {
     Shapes.Add(shape);
 }