示例#1
0
        /// <summary>
        /// Function to create a polygon object.
        /// </summary>
        /// <param name="name">Name of the polygon.</param>
        /// <param name="position">Position of the polygon.</param>
        /// <param name="color">Color of the polygon.</param>
        /// <param name="vertices">[Optional] Vertices for the polygon.</param>
        /// <param name="indices">[Optional] Indices for the polygon.</param>
        /// <param name="type">[Optional] The type of primitive to use when drawing the polygon.</param>
        /// <param name="useDynamicVertexBuffer">[Optional] TRUE to use a dynamic buffer to hold the vertices, FALSE to use a static buffer.</param>
        /// <param name="useDynamicIndexBuffer">[Optional] TRUE to use a dynamic buffer to hold the indices, FALSE to use a static buffer.</param>
        /// <returns>A new polygon object.</returns>
        /// <remarks>Passing NULL (Nothing in VB.Net) to the <paramref name="indices"/> parameter will disable the index buffer on the polygon.  An index buffer can help with performance by
        /// decreasing the required number of vertices to be sent to the video device.</remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net). </exception>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="name"/> parameter is empty.</exception>
        public GorgonPolygon CreatePolygon(string name,
                                           Vector2 position,
                                           GorgonColor color,
                                           GorgonPolygonPoint[] vertices = null,
                                           int[] indices               = null,
                                           PolygonType type            = PolygonType.Triangle,
                                           bool useDynamicVertexBuffer = false,
                                           bool useDynamicIndexBuffer  = false)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException(Resources.GOR2D_PARAMETER_MUST_NOT_BE_EMPTY, "name");
            }

            var result = new GorgonPolygon(_gorgon2D, name, type)
            {
                UseDynamicVertexBuffer = useDynamicVertexBuffer,
                UseDynamicIndexBuffer  = useDynamicIndexBuffer,
                Color    = color,
                Position = position
            };

            if (vertices != null)
            {
                result.SetVertexData(vertices);
            }

            if (indices != null)
            {
                result.SetIndexData(indices);
            }

            _gorgon2D.TrackedObjects.Add(result);

            return(result);
        }
示例#2
0
        public void TestPolygon()
        {
            _form.Show();
            _form.ClientSize = new Size(1280, 800);
            _form.Location   = new Point(Screen.PrimaryScreen.WorkingArea.Width / 2 - 640, Screen.PrimaryScreen.WorkingArea.Height / 2 - 400);
            _form.BringToFront();
            _form.WindowState = FormWindowState.Minimized;
            _form.WindowState = FormWindowState.Normal;

            GorgonPolygon polygon = _renderer.Renderables.CreatePolygon("Test", new Vector2(320, 240), Color.RosyBrown);

            polygon.SetVertexData(new GorgonPolygonPoint[]
            {
                new GorgonPolygonPoint(new Vector2(0, 20), GorgonColor.White),
                new GorgonPolygonPoint(new Vector2(20, 0), GorgonColor.White),
                new GorgonPolygonPoint(new Vector2(40, 20), GorgonColor.White),
                new GorgonPolygonPoint(new Vector2(10, 40), GorgonColor.White),
                new GorgonPolygonPoint(new Vector2(30, 40), GorgonColor.White)
            });

            polygon.SetIndexData(new []
            {
                0, 1, 2,
                2, 3, 0,
                3, 2, 4
            });

            GorgonPolygon polygon2 = _renderer.Renderables.CreatePolygon("Test", new Vector2(320, 240), Color.GreenYellow);

            polygon2.PolygonType = PolygonType.Line;
            polygon2.SetVertexData(new GorgonPolygonPoint[]
            {
                new GorgonPolygonPoint(new Vector2(0, 20), GorgonColor.White),
                new GorgonPolygonPoint(new Vector2(20, 0), GorgonColor.White),
                new GorgonPolygonPoint(new Vector2(40, 20), GorgonColor.White),
                new GorgonPolygonPoint(new Vector2(10, 40), GorgonColor.White),
                new GorgonPolygonPoint(new Vector2(30, 40), GorgonColor.White)
            });

            polygon2.SetIndexData(new[]
            {
                0, 1,
                1, 2,
                2, 4,
                4, 3,
                3, 0
            });

            Gorgon.Run(_form, () =>
            {
                _renderer.Clear(Color.Black);

                polygon.Draw();
                polygon2.Draw();

                _renderer.Render();

                return(true);
            });

            Assert.IsTrue(_form.TestResult == DialogResult.Yes);
        }