Append() public method

Add a vertex to the array
public Append ( Vertex vertex ) : void
vertex Vertex Vertex to add
return void
Example #1
0
        public LineSegment(SFML.Window.Vector2f start, SFML.Window.Vector2f end, SFML.Graphics.Color color)
        {
            Start = start;
            End = end;

            linePoints = new VertexArray(PrimitiveType.Lines);
            linePoints.Append(new Vertex(start) { Color = color });
            linePoints.Append(new Vertex(end) { Color = color });
        }
Example #2
0
        public LineSegment(SFML.Window.Vector2f start, SFML.Window.Vector2f end)
        {
            Start = start;
            End = end;

            linePoints = new VertexArray(PrimitiveType.Lines);
            linePoints.Append(new Vertex(start));
            linePoints.Append(new Vertex(end));
        }
Example #3
0
        public void Draw(RenderTarget target, RenderStates states)
        {
            VertexArray vertices = new VertexArray(PrimitiveType.Lines);

            for (int x = 0; x < viewSize.X; x += size)
            {
                vertices.Append(new Vertex(sim.Window.MapPixelToCoords(new Vector2i(x - viewOffset.X, 0)), color));
                vertices.Append(new Vertex(sim.Window.MapPixelToCoords(new Vector2i(x - viewOffset.X, (int)viewSize.Y)), color));
            }

            for (int y = 0; y < viewSize.Y; y += size)
            {
                vertices.Append(new Vertex(sim.Window.MapPixelToCoords(new Vector2i(0, y - viewOffset.Y)), color));
                vertices.Append(new Vertex(sim.Window.MapPixelToCoords(new Vector2i((int)viewSize.X, y - viewOffset.Y)), color));
            }

            vertices.Draw(target, states);
        }
Example #4
0
        protected override void UpdateDrawable() {
            base.UpdateDrawable();

            Color nextColor = ColorA;
            Color rowColor = nextColor;
            SFMLVertices = new VertexArray(PrimitiveType.Quads);
            for (float j = 0; j < Height; j += GridHeight) {
                for (float i = 0; i < Width; i += GridWidth) {
                    var color = new Color(nextColor) * Color;
                    SFMLVertices.Append(new Vertex(new Vector2f(i, j), color.SFMLColor));
                    SFMLVertices.Append(new Vertex(new Vector2f(i + GridWidth, j), color.SFMLColor));
                    SFMLVertices.Append(new Vertex(new Vector2f(i + GridWidth, j + GridHeight), color.SFMLColor));
                    SFMLVertices.Append(new Vertex(new Vector2f(i, j + GridHeight), color.SFMLColor));
                    nextColor = nextColor == ColorA ? ColorB : ColorA;
                }
                rowColor = nextColor = rowColor == ColorA ? ColorB : ColorA;
            }
        }
Example #5
0
        public void DrawSimpleLine(int x1, int y1, int x2, int y2, Color color = new Color())
        {
            if (!ArePointsOnScreen(x1, y1, x2, y2))
            {
                return;
            }

            var zoom = GetZoom();

            int real_x1 = (int)(x1 * zoom);
            int real_x2 = (int)(x2 * zoom);
            int real_y1 = (int)(y1 * zoom);
            int real_y2 = (int)(y2 * zoom);


            SFML.Graphics.VertexArray line = new SFML.Graphics.VertexArray();
            line.PrimitiveType = SFML.Graphics.PrimitiveType.Lines;
            line.Append(new Vertex(new SFML.System.Vector2f(real_x1, real_y1), new SFML.Graphics.Color(color.R, color.G, color.B, color.A)));
            line.Append(new Vertex(new SFML.System.Vector2f(real_x2, real_y2), new SFML.Graphics.Color(color.R, color.G, color.B, color.A)));
            RenderWindow.Draw(line);
        }
Example #6
0
        //	TODO:	everything else



        public static void Rect(float x, float y, int width, int height, SFML.Graphics.Color color)
        {
            verts.Append(new SFML.Graphics.Vertex(new Vector2f(x, y), color));
            verts.Append(new SFML.Graphics.Vertex(new Vector2f(x + width, y), color));

            verts.Append(new SFML.Graphics.Vertex(new Vector2f(x + width, y), color));
            verts.Append(new SFML.Graphics.Vertex(new Vector2f(x + width, y + height), color));


            verts.Append(new SFML.Graphics.Vertex(new Vector2f(x + width, y + height), color));
            verts.Append(new SFML.Graphics.Vertex(new Vector2f(x, y + height), color));

            verts.Append(new SFML.Graphics.Vertex(new Vector2f(x, y + height), color));
            verts.Append(new SFML.Graphics.Vertex(new Vector2f(x, y), color));
        }
Example #7
0
        public void Draw(Texture tex, IntRect texRect, Vector2f ori,
                         Vector2f pos, Vector2f sca, Color col, float rot)
        {
            var x = texRect.Left;
            var y = texRect.Top;
            var w = texRect.Width;
            var h = texRect.Height;

            var tl = new Vertex((new Vector2f(0, 0) - ori) * sca + pos, col, new Vector2f(x, y));
            var tr = new Vertex((new Vector2f(w, 0) - ori) * sca + pos, col, new Vector2f(x + w, y));
            var br = new Vertex((new Vector2f(w, h) - ori) * sca + pos, col, new Vector2f(x + w, y + h));
            var bl = new Vertex((new Vector2f(0, h) - ori) * sca + pos, col, new Vector2f(x, y + h));

            if (rot != 0f)
            {
                rot = rot * (float)Math.PI / 180f;
                var cRot = (float)Math.Cos(rot);
                var sRot = (float)Math.Sin(rot);

                var tp = tl.Position;
                tl.Position = new Vector2f(tp.X * cRot - tp.Y * sRot + pos.X,
                                           tp.X * sRot + tp.Y * cRot + pos.Y);

                tp          = tr.Position;
                tl.Position = new Vector2f(tp.X * cRot - tp.Y * sRot + pos.X,
                                           tp.X * sRot + tp.Y * cRot + pos.Y);

                tp          = bl.Position;
                tl.Position = new Vector2f(tp.X * cRot - tp.Y * sRot + pos.X,
                                           tp.X * sRot + tp.Y * cRot + pos.Y);

                tp          = br.Position;
                tl.Position = new Vector2f(tp.X * cRot - tp.Y * sRot + pos.X,
                                           tp.X * sRot + tp.Y * cRot + pos.Y);
            }

            _vertices.Append(tl);
            _vertices.Append(tr);
            _vertices.Append(br);
            _vertices.Append(tl);
            _vertices.Append(bl);
            _vertices.Append(br);
        }
Example #8
0
        void DebugDraw(RenderWindow win)
        {
            debugGraphic.FillColor = Color.Red;
            debugGraphic.Position = Position - ((Vector2)debugGraphic.Size / 2F);
            win.Draw(debugGraphic);

            foreach (Rune adjacentRune in AdjacentRunes)
            {
                //if (this.GetType() == adjacentRune.GetType())
                {
                    VertexArray line = new VertexArray();
                    line.Append(new Vertex(Position));
                    for (float t = 0F; t < 1F; t += 0.01F)
                    {
                        line.Append(new Vertex(Vector2.lerp(Position, adjacentRune.Position, t)));
                    }
                    line.Append(new Vertex(adjacentRune.Position));
                    win.Draw(line);

                }
            }
        }
        public override void Draw(RenderTarget target, RenderStates states)
        {
            var corners = game.WindowBounds.Corners().Concat(game.World.Objects.SelectMany(o => o.Bounds.Corners()));
            var edges = game.WindowBounds.Edges().Concat(game.World.Objects.SelectMany(o => o.Bounds.Edges()));

            //foreach (var edge in edges)
            //    Debug.DrawLine(edge.start, edge.end);

            var hits =
                from c in corners
                let angle = Radians(c.Angle(Position))
                let hit = Raycast(Position, c, edges)
                let left = Raycast(Position, angle - 0.0001f, 10000f, edges)
                let right = Raycast(Position, angle + 0.0001f, 10000f, edges)
                where hit.HasValue && left.HasValue && right.HasValue
                from h in new[] {
                    new { Hit = hit, Angle = angle },
                    new { Hit = left, Angle = angle - 0.0001f },
                    new { Hit = right, Angle = angle + 0.0001f } }
                let a = NormalizeAngle(Position.Angle(h.Hit.Value.ClosestHit))
                orderby h.Angle
                select h.Hit.Value.ClosestHit;

            //foreach (var hit in hits)
            //{
            //    Debug.DrawLine(Position, hit, Color.Red);
            //    Debug.DrawCircle(hit, 5f, 8, Color.Red);
            //}

            var vertices = new VertexArray(PrimitiveType.Triangles);
            var center = new Vertex(Position, Color);

            foreach (var hit in hits.Pairs(Position))
                vertices.Append(new Vertex(hit, Color));

            target.Draw(vertices);
        }
Example #10
0
 public void DrawLine(RenderWindow win, Vector2 from, Vector2 to)
 {
     VertexArray line = new VertexArray();
     for (float t = 0F; t < 1F; t += 0.01F)
     {
         line.Append(new Vertex(Vector2.lerp(from, to, t)));
     }
     line.Append(new Vertex(to));
     win.Draw(line);
 }
Example #11
0
 internal void AppendVertices(VertexArray array) {
     if(!FlipX && !FlipY)
     {
         array.Append(CreateVertex(0, 0, 0, 0));
         array.Append(CreateVertex(Width, 0, Width, 0));
         array.Append(CreateVertex(Width, Height, Width, Height));
         array.Append(CreateVertex(0, Height, 0, Height));
     }
     if(FlipX && FlipY)
     {
         array.Append(CreateVertex(0, 0, Width, Height));
         array.Append(CreateVertex(Width, 0, 0, Height));
         array.Append(CreateVertex(Width, Height, 0, 0));
         array.Append(CreateVertex(0, Height, Width, 0));
     }
     if(FlipX & !FlipY)
     {
         array.Append(CreateVertex(0, 0, Width, 0));
         array.Append(CreateVertex(Width, 0, 0, 0));
         array.Append(CreateVertex(Width, Height, 0, Height));
         array.Append(CreateVertex(0, Height, Width, Height));
     }
     if (!FlipX & FlipY)
     {
         array.Append(CreateVertex(0, 0, 0, Height));
         array.Append(CreateVertex(Width, 0, Width, Height));
         array.Append(CreateVertex(Width, Height, Width, 0));
         array.Append(CreateVertex(0, Height, 0, 0));
     }
 }
Example #12
0
 void Append(VertexArray v, float x, float y, float tx, float ty) {
     v.Append(new Vertex(new Vector2f(x, y), new Vector2f(tx, ty)));
 }
Example #13
0
        void DrawQuad(VertexArray v, float x1, float y1, float x2, float y2, float u1, float v1, float u2, float v2) {
            float cx1 = x1, cx2 = x2, cy1 = y1, cy2 = y2;
            float cu1 = u1, cu2 = u2, cv1 = v1, cv2 = v2;

            if (usePanelClip) {
                cx1 = Util.Clamp(x1, ClippingRegion.Left, ClippingRegion.Right);
                cu1 = Util.ScaleClamp(cx1, x1, x2, u1, u2);

                cx2 = Util.Clamp(x2, ClippingRegion.Left, ClippingRegion.Right);
                cu2 = Util.ScaleClamp(cx2, x1, x2, u1, u2);

                cy1 = Util.Clamp(y1, ClippingRegion.Top, ClippingRegion.Bottom);
                cv1 = Util.ScaleClamp(cy1, y1, y2, v1, v2);

                cy2 = Util.Clamp(y2, ClippingRegion.Top, ClippingRegion.Bottom);
                cv2 = Util.ScaleClamp(cy2, y1, y2, v1, v2);
            }

            v.Append(cx1, cy1, Color, cu1, cv1);
            v.Append(cx2, cy1, Color, cu2, cv1);
            v.Append(cx2, cy2, Color, cu2, cv2);
            v.Append(cx1, cy2, Color, cu1, cv2);
        }
Example #14
0
 internal void AppendVertices(VertexArray array) {
     array.Append(CreateVertex());
     array.Append(CreateVertex(Width, 0, Width));
     array.Append(CreateVertex(Width, Height, Width, Height));
     array.Append(CreateVertex(0, Height, 0, Height));
 }
Example #15
0
        /// <summary>
        /// Draws a line with rounded ends.
        /// </summary>
        /// <param name="x1">The X position of the first point.</param>
        /// <param name="y1">The Y position of the first point.</param>
        /// <param name="x2">The X position of the second point.</param>
        /// <param name="y2">The Y position of the second point.</param>
        /// <param name="color">The color of the line.</param>
        /// <param name="thickness">The thickness of the line.</param>
        public static void RoundedLine(float x1, float y1, float x2, float y2, Color color, float thickness)
        {
            VertexArray vertices = new VertexArray(PrimitiveType.TrianglesFan);

            int rotationSteps = 10;

            var line = new Vector2(x2 - x1, y2 - y1);
            var normalUp = new Vector2(y1 - y2, x2 - x1);
            var normalDown = new Vector2(y2 - y1, x1 - x2);

            normalUp.Normalize(thickness * 0.5f);
            normalDown.Normalize(thickness * 0.5f);

            var nextPoint = new Vector2();

            float vx, vy;

            vx = x1;
            vy = y1;

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            vx = (float)(x1 + normalUp.X);
            vy = (float)(y1 + normalUp.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            nextPoint.X = normalUp.X;
            nextPoint.Y = normalUp.Y;

            for (int i = 0; i < rotationSteps; i++) {
                nextPoint = Util.Rotate(nextPoint, -180 / rotationSteps);

                vx = (float)(x1 + nextPoint.X);
                vy = (float)(y1 + nextPoint.Y);

                vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));
            }

            vx = (float)(x1 + normalDown.X);
            vy = (float)(y1 + normalDown.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            vx = (float)(x2 + normalDown.X);
            vy = (float)(y2 + normalDown.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            for (int i = 0; i < rotationSteps; i++) {
                nextPoint = Util.Rotate(nextPoint, -180 / rotationSteps);

                vx = (float)(x2 + nextPoint.X);
                vy = (float)(y2 + nextPoint.Y);

                vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));
            }

            vx = (float)(x2 + normalUp.X);
            vy = (float)(y2 + normalUp.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            vx = (float)(x1 + normalUp.X);
            vy = (float)(y1 + normalUp.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            Drawable(vertices, RenderStates.Default);
        }
Example #16
0
        protected override void UpdateDrawable() {
            base.UpdateDrawable();

            SFMLVertices = new VertexArray((SFML.Graphics.PrimitiveType)PrimitiveType);

            
            foreach (var v in Verts) {
                // Adjust texture for potential atlas offset.
                v.U += TextureLeft;
                v.V += TextureTop;
                v.U = Util.Clamp(v.U, TextureLeft, TextureRight);
                v.V = Util.Clamp(v.V, TextureTop, TextureBottom);

                //copy to new vert and apply color and alpha
                var vCopy = new Vert(v);
                vCopy.Color *= Color;
                vCopy.Color.A *= Alpha;

                SFMLVertices.Append(vCopy);
            }

            
        }
Example #17
0
 void Append(VertexArray v, float x, float y)
 {
     v.Append(x, y, Color);
 }
Example #18
0
        internal void Draw(Texture texture, float x, float y, float originX, float originY, int width, int height, float scaleX, float scaleY, float angle, Color color = null, BlendMode blend = BlendMode.Alpha, Shader shader = null)
        {
            states = new RenderStates(Texture.SFMLTexture);

            states.BlendMode = (SFML.Graphics.BlendMode)Blend;

            if (Shader != null) {
                states.Shader = Shader.shader;
            }

            states.Transform.Translate(x - OriginX, y - OriginY);
            states.Transform.Rotate(-Angle, OriginX, OriginY);
            states.Transform.Scale(ScaleX, ScaleY, OriginX, OriginY);

            var v = new VertexArray(PrimitiveType.Quads);

            if (color == null) color = Color.White;

            v.Append(x, y, color, 0, 0);
            v.Append(x + width, y, color, width, 0);
            v.Append(x + width, y + height, color, width, height);
            v.Append(x, y + height, color, 0, height);

            Draw(v, states);
        }
Example #19
0
        protected override void UpdateDrawable()
        {
            base.UpdateDrawable();

            if (prevCount != Verts.Count) {
                SFMLVertices = new VertexArray((SFML.Graphics.PrimitiveType)PrimitiveType, (uint)Verts.Count);
                prevCount = Verts.Count;

                foreach (var v in Verts) {
                    // Adjust texture for potential atlas offset.
                    v.U += TextureLeft;
                    v.V += TextureTop;
                    v.U = Util.Clamp(v.U, TextureLeft, TextureRight);
                    v.V = Util.Clamp(v.V, TextureTop, TextureBottom);
                    SFMLVertices.Append(v);
                }
            }
            else {
                uint i = 0;
                foreach (var v in Verts) {
                    SFMLVertices[i] = v.SFMLVertex;

                    i++;
                }
            }
        }
Example #20
0
        public StormBlink()
            : base("storm + blink")
        {
            Random random = new Random();

            // Create the points
            myPoints = new VertexArray(PrimitiveType.Points);
            for (int i = 0; i < 40000; ++i)
            {
                float x = (float)random.Next(0, 800);
                float y = (float)random.Next(0, 600);
                byte r = (byte)random.Next(0, 255);
                byte g = (byte)random.Next(0, 255);
                byte b = (byte)random.Next(0, 255);
                myPoints.Append(new Vertex(new Vector2f(x, y), new Color(r, g, b)));
            }

            // Load the shader
            myShader = new Shader("resources/storm.vert", "resources/blink.frag");
        }
Example #21
0
        /// <summary>
        /// Draws a line using an OpenGL line.
        /// </summary>
        /// <param name="x1">The X position of the first point.</param>
        /// <param name="y1">The Y position of the first point.</param>
        /// <param name="x2">The X position of the second point.</param>
        /// <param name="y2">The Y position of the second point.</param>
        /// <param name="color">The color of the line.</param>
        public static void Line(float x1, float y1, float x2, float y2, Color color)
        {
            VertexArray vertices = new VertexArray(PrimitiveType.Lines);

            vertices.Append(new Vertex(new Vector2f(x1, y1), color.SFMLColor));
            vertices.Append(new Vertex(new Vector2f(x2, y2), color.SFMLColor));
            Drawable(vertices, RenderStates.Default);
        }
Example #22
0
        /*
         * @param _funcType Style of the top line that generated
         * @param _res Size of mapunits for one linear segment
         * */
        public PolygonActor(World _world, Vector2 _position, uint _seed, FunctionType _funcType, int _res = 5)
            : base(_world, _position)
        {
            int lineCount = (int)Constants.worldSizeX / _res;

            //make sure to have an even number
            if (lineCount % 2 != 0) lineCount++;
            Vec2[] verts = new Vec2[(int)lineCount + 1 + 4];
            vertexBuffer = new VertexArray(PrimitiveType.LinesStrip);

            Vector2 posScreen = _position.toScreenCoord();

            //repeatable random sequenze
            Rand rnd = new Rand(_seed);

            //start and end have even ground
            verts[0] = new Vec2(0, 6);
            verts[1] = new Vec2(_res, 6);
            verts[2] = new Vec2(_res + _res, 6);

            verts[lineCount - 2] = new Vec2(_res * (lineCount - 2), 6);
            verts[lineCount-1] = new Vec2(_res * (lineCount-1), 6);
            verts[lineCount] = new Vec2(_res * lineCount, 6);

            vertexBuffer.Append(new Vertex(((Vector2)verts[0] + _position).toScreenCoord()));
            //create the function
            if (_funcType == FunctionType.Simple)
            {
                for (int i = 2; i <= lineCount; ++i)
                {
                    //Vector2 pos = new Vec2(i * 5, 10 + Rand.IntValue(10));
                    Vector2 pos = new Vec2(i * _res, System.Math.Max((verts[i - 1].Y + (int)rnd.next(6) - 3), 0));
                    verts[i] = pos;
                }
            }
            else if(_funcType == FunctionType.GradientNoise)
            {
                for (int i = 2; i < lineCount-3;)
                {
                    int nextGrad = i + 4;

                    if (nextGrad < lineCount - 2)
                    {
                        verts[nextGrad] = new Vec2(nextGrad * _res, rnd.next((int)maxHeight));
                    }
                    else nextGrad = lineCount - 2;

                    //interpolate between
                    float relativeA = verts[i].Y / maxHeight;
                    float relativeB = verts[nextGrad].Y / maxHeight;
                    for (int c = i + 1; c < nextGrad; ++c)
                    {
                        verts[c] = new Vec2(c * _res, maxHeight * interpolateCos(relativeA, relativeB, (float)(c - i) / 4));
                    }

                    i = nextGrad;
                }

            }

            Array.Resize<Body>(ref triangleBodys, lineCount);

            PolygonDef triangleDef = new PolygonDef();
            triangleDef.Density = 0.0f;
            triangleDef.Friction = 1.0f;
            triangleDef.VertexCount = 3;

            BodyDef bodydef = new BodyDef();
            bodydef.Position = _position;
            bodydef.Angle = 0.0f;

            //convert to triangles
            for (int i = 0; i < lineCount; ++i)
            {
                //always 3 points of the function form a triangle
                triangleDef.Vertices[0] = verts[i];
                triangleDef.Vertices[1] = verts[i] - new Vec2(0.0f, 50.0f);
                triangleDef.Vertices[2] = verts[i + 1];//.Y < verts[i+1].Y ? verts[i] : verts[i + 1]

                triangleBodys[i] = _world.CreateBody(bodydef);
                triangleBodys[i].CreateShape(triangleDef);

                vertexBuffer.Append(new Vertex(((Vector2)verts[i+1] + _position).toScreenCoord()));
            }
        }
Example #23
0
        /// <summary>
        /// Draws a line with a thickness using a quad.
        /// </summary>
        /// <param name="x1">The X position of the first point.</param>
        /// <param name="y1">The Y position of the first point.</param>
        /// <param name="x2">The X position of the second point.</param>
        /// <param name="y2">The Y position of the second point.</param>
        /// <param name="color">The color of the line.</param>
        /// <param name="thickness">The thickness of the line.</param>
        public static void Line(float x1, float y1, float x2, float y2, Color color, float thickness)
        {
            VertexArray vertices = new VertexArray(PrimitiveType.Quads);

            var line = new Vector2(x2 - x1, y2 - y1);
            var normalUp = new Vector2(y1 - y2, x2 - x1);
            var normalDown = new Vector2(y2 - y1, x1 - x2);

            normalUp.Normalize(thickness * 0.5f);
            normalDown.Normalize(thickness * 0.5f);

            float vx, vy;

            vx = (float)(x1 + normalUp.X);
            vy = (float)(y1 + normalUp.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            vx = (float)(x1 + normalDown.X);
            vy = (float)(y1 + normalDown.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            vx = (float)(x2 + normalDown.X);
            vy = (float)(y2 + normalDown.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            vx = (float)(x2 + normalUp.X);
            vy = (float)(y2 + normalUp.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            Drawable(vertices, RenderStates.Default);
        }