Esempio n. 1
0
        /// <summary>
        /// An array getter, optimized by reusing mappings.
        /// </summary>
        /// <param name="lineIndex">The  line index offset.</param>
        /// <param name="positionComponent">The position component.</param>
        /// <param name="storage">Where to store result.</param>
        public void Get(string positionComponent, uint lineIndex, LineSegment2f[] storage)
        {
            if (lineIndex + storage.Length >= shapeCount)
            {
                throw new ArgumentException("Index out of range, not that many triangles.");
            }

            if (indexBuffer != null)
            {
                uint[]     indices = indexBuffer.Getui(lineIndex * 2, (uint)storage.Length * 2);
                Vector2f[] data    = query.Get2f(positionComponent, indices);

                for (int i = 0; i < storage.Length; i++)
                {
                    storage[i] = new LineSegment2f(data[i * 2], data[i * 2 + 1]);
                }
            }
            else
            {
                Vector2f[] data = query.Get2f(positionComponent, lineIndex * 2, (uint)storage.Length * 2);

                for (int i = 0; i < storage.Length; i++)
                {
                    storage[i] = new LineSegment2f(data[i * 2], data[i * 2 + 1]);
                }
            }
        }
Esempio n. 2
0
        //#endfor instanced to 'Double3'

        //#foreach instanced to 'Float2'


        /// <summary>
        /// Gets line.
        /// </summary>
        /// <param name="index">The line index.</param>
        /// <remarks>This is not performance wise getter.</remarks>
        /// <returns></returns>
        public LineSegment2f Get2f(uint index)
        {
            LineSegment2f t = new LineSegment2f();

            Get(CommonComponents.Position, index, t);
            return(t);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets line.
        /// </summary>
        /// <param name="index">The line index.</param>
        /// <param name="positionComponent">The component where we look for position, must be
        /// correct format.</param>
        /// <remarks>This is not performance wise getter.</remarks>
        public LineSegment2f Get2f(string positionComponent, uint index)
        {
            LineSegment2f t = new LineSegment2f();

            Get(positionComponent, index, t);
            return(t);
        }
Esempio n. 4
0
        LineSegment2f[] GenerateLineList(Vector2f[] list)
        {
            LineSegment2f[] seg = new LineSegment2f[list.Length - 1];
            for (int i = 1; i < list.Length; i++)
            {
                seg[i - 1] = new LineSegment2f(list[i - 1], list[i]);
            }

            return(seg);
        }
Esempio n. 5
0
        //#endfor instanced to 'Vector2d'

        //#foreach instanced to 'Vector2f'


        /// <summary>
        /// Returns true, if p0 is upper point, p1, p2 are lower, false otherwise.
        /// </summary>
        static bool CalcPathIntersection(Vector2f a, Vector2f b, Vector2f c, float width,
                                         out Vector2f p0, out Vector2f p1, out Vector2f p2)
        {
            // We first generate two vectors.
            Vector2f dir1 = b - a;
            Vector2f dir2 = c - b;

            // We generate two perpendicular vectors.
            Vector2f grad1 = new Vector2f(-dir1.Y, dir1.X).Normal;
            Vector2f grad2 = new Vector2f(-dir2.Y, dir2.X).Normal;

            // We now generate 4 line segments.
            LineSegment2f seg1Up   = new LineSegment2f(a + grad1 * width, b + grad1 * width);
            LineSegment2f seg1Down = new LineSegment2f(a - grad1 * width, b - grad1 * width);
            LineSegment2f seg2Up   = new LineSegment2f(b + grad2 * width, c + grad2 * width);
            LineSegment2f seg2Down = new LineSegment2f(b - grad2 * width, c - grad2 * width);


            // We calculate intersections.
            float t1, t2;

            if (Intersection.Intersect(seg1Up, seg2Up, out t1, out t2))
            {
                // If they intersect, we have point 0.
                p0 = seg1Up.Sample(t1);

                p1 = seg1Down.B;
                p2 = seg2Down.A;

                return(true);
            }
            else if (Intersection.Intersect(seg1Down, seg2Down, out t1, out t2))
            {
                p0 = seg1Down.Sample(t1);

                p1 = seg1Up.B;
                p2 = seg2Up.A;

                return(false);
            }
            else
            {
                // If result is this, we have no intersections, numeric error. We use variables of one.
                p0 = seg1Up.B;

                p1 = p2 = seg1Down.B;

                return(true);
            }
        }
Esempio n. 6
0
        public void PenVG(GraphicsDevice device)
        {
            ICanvas canvas = new GraphicsCanvas(device, device.SwapChain, new Vector2f(1.0f, 1.0f));

            // We first create all needed fills.
            SolidFill solidFill = new SolidFill(Colour.Red);
            Pen       pen       = new Pen(solidFill, 0.003f, 0.0f, OutlineEnd.Square);
            Bezier2f  line      = new Bezier2f(new Vector2f(0.1f, 0.5f), new Vector2f(0.3f, 1.0f),
                                               new Vector2f(0.9f, 0.5f));

            Bezier2f line2 = new Bezier2f(new Vector2f(0.1f, 0.5f), new Vector2f(0.3f, 0.0f),
                                          new Vector2f(0.9f, 0.5f));

            LineSegment2f seg = new LineSegment2f(new Vector2f(0, 0.5f), new Vector2f(0.7f, 0.6f));

            bool exit = false;

            device.SwapChain.Window.Closed += delegate(Window w) { exit = true; };

            float a = 0;

            while (!exit)
            {
                device.SwapChain.Window.DoEvents();

                using (DeviceLock l = device.Lock())
                {
                    device.Clear(device.SwapChain, Colour.Green);

                    device.SetViewports(new Region2i(0, 0, (int)device.SwapChain.Width, (int)device.SwapChain.Height));

                    line.A  = 0.5f * new Vector2f(1, 1) + new Vector2f(1, 1) * 0.5f * MathHelper.Cos(a);
                    line2.B = 0.5f * new Vector2f(1, 1) + new Vector2f(1, 1) * 0.5f * MathHelper.Sin(a);

                    // We render.
                    canvas.Begin(CanvasRenderFlags.None);

                    canvas.DrawShape(pen, line, null);
                    canvas.DrawShape(pen, seg, null);
                    canvas.DrawShape(pen, line2, null);

                    canvas.End();
                }

                device.SwapChain.Present();

                a += 0.01f;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Gets triangle.
        /// </summary>
        /// <param name="index">The line index.</param>
        /// <remarks>This accessor is not to be used in performance critical parts of applications.</remarks>
        /// <returns></returns>
        public void Get(string positionComponent, uint index, LineSegment2f storage)
        {
            if (index >= shapeCount)
            {
                throw new ArgumentException("Index out of range, not that many triangles.");
            }

            if (indexBuffer != null)
            {
                uint[] indices = indexBuffer.Getui(index * 2, 2);

                storage.A = query.Get2f(positionComponent, indices[0]);
                storage.B = query.Get2f(positionComponent, indices[1]);
            }
            else
            {
                storage.A = query.Get2f(positionComponent, index * 2);
                storage.B = query.Get2f(positionComponent, index * 2 + 1);
            }
        }
Esempio n. 8
0
 /// <summary>
 /// An array getter, optimized by reusing mappings.
 /// </summary>
 /// <param name="lineIndex">The line index offset.</param>
 /// <param name="positionComponent">The position component.</param>
 /// <param name="count">Number of triangles.</param>
 public LineSegment2f[] Get2f(string positionComponent, uint lineIndex, uint count)
 {
     LineSegment2f[] data = new LineSegment2f[count];
     Get(positionComponent, lineIndex, data);
     return(data);
 }
Esempio n. 9
0
 /// <summary>
 /// Gets line.
 /// </summary>
 /// <param name="index">The line index.</param>
 /// <param name="positionComponent">The component where we look for position, must be
 /// Vector2f format.</param>
 /// <remarks>This is not performance wise getter.</remarks>
 public void Get(uint index, LineSegment2f storage)
 {
     Get(CommonComponents.Position, index, storage);
 }
Esempio n. 10
0
 /// <summary>
 /// Fills a line at index.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <param name="line">The triangle to be filled.</param>
 public void Get(uint index, [NotNull] LineSegment2f line)
 {
     throw new NotImplementedException();
 }
Esempio n. 11
0
 /// <summary>
 /// Attempt to intersect two line segments.
 /// </summary>
 /// <remarks>
 /// Even if the line segments do not intersect, <paramref name="t"/> and <paramref name="u"/> will be set.
 /// If the lines are parallel, <paramref name="t"/> and <paramref name="u"/> are set to <see cref="float.NaN"/>.
 /// </remarks>
 /// <param name="other">The line to attempt intersection of this line with.</param>
 /// <param name="intersectionPoint">The point of intersection if within the line segments, or empty..</param>
 /// <param name="t">The distance along this line at which intersection would occur, or NaN if lines are collinear/parallel.</param>
 /// <param name="u">The distance along the other line at which intersection would occur, or NaN if lines are collinear/parallel.</param>
 /// <returns><c>true</c> if the line segments intersect, otherwise <c>false</c>.</returns>
 public bool TryIntersect(LineSegment2f other, out Vector2f intersectionPoint, out float t, out float u)
 {