public static void AddWays(this Polygon<OSMNode> polygon, IList<OSMWay> ways, OSMDB db)
        {
            if (ways.Count == 1) {
                // Check if the created polygon is closed
                if (ways[0].Nodes.Count > 0 && ways[0].Nodes.First() != ways[0].Nodes.Last()) {
                    throw new ArgumentException("Ways does not form a closed polygon");
                }

                for (int i = 0; i < ways[0].Nodes.Count - 1; i++) {
                    polygon.AddVertex(db.Nodes[ways[0].Nodes[i]]);
                }
            }
            else {
                int lastVertexID = 0;

                if (ways[0].Nodes.First() == ways.Last().Nodes.First() || ways[0].Nodes.Last() == ways.Last().Nodes.First()) {
                    lastVertexID = ways.Last().Nodes.First();
                }
                else {
                    lastVertexID = ways.Last().Nodes.Last();
                }
                //// Check orientation of the first way
                //if (ways[0].Nodes.First() == ways[1].Nodes.First() || ways[0].Nodes.First() == ways[1].Nodes.First()) {
                //  for (int ii = ways[0].; ii < verticesToAdd.Count - 1; ii++) {
                //    AddVertex(verticesToAdd[ii]);
                //  }
                //}

                for (int i = 0; i < ways.Count; i++) {
                    List<int> verticesToAdd = new List<int>();

                    // Checks the way orienatation and picks nodes in correct order
                    if (lastVertexID == ways[i].Nodes[0]) {
                        verticesToAdd.AddRange(ways[i].Nodes);
                    }
                    else if (lastVertexID == ways[i].Nodes.Last()) {
                        verticesToAdd.AddRange(ways[i].Nodes.Reverse());
                    }
                    else {
                        throw new ArgumentException("Can not create polygon, ways aren't connected");
                    }

                    for (int ii = 0; ii < verticesToAdd.Count - 1; ii++) {
                        polygon.AddVertex(db.Nodes[verticesToAdd[ii]]);
                    }

                    lastVertexID = verticesToAdd.Last();
                }

                // Check if the created polygon is closed
                if (polygon.VerticesCount > 0 && polygon.Vertices.First() != db.Nodes[lastVertexID]) {
                    throw new ArgumentException("Ways does not form a closed polygon");
                }
            }
        }
        public static void DrawFilledCircle(this PrimitiveBatch primitiveBatch, Vector2 position, float radius, Color color)
        {
            primitiveBatch.Begin(PrimitiveType.TriangleList);
            int steps = 20;
            float step = MathHelper.TwoPi / steps;

            for (int i = 0; i < (steps + 1); i++)
            {
                float x = radius * (float)Math.Cos(i * step);
                float y = radius * (float)Math.Sin(i * step);

                if (i != 0)
                {
                    primitiveBatch.AddVertex(position + new Vector2(x, y), color);
                }

                if (i != steps)
                {
                    primitiveBatch.AddVertex(position, color);
                    primitiveBatch.AddVertex(position + new Vector2(x, y), color);

                }

            }

            primitiveBatch.End();
        }
Example #3
0
        public static void DrawLine(this PrimitiveBatch primBatch, Line line, Color color)
        {
            primBatch.Begin(PrimitiveType.LineList);

            primBatch.AddVertex((Vector2)line.Start, color);
            primBatch.AddVertex((Vector2)line.End, color);

            primBatch.End();
        }
		public unsafe static void AddVertex(this BuSimplex1To4 obj, ref OpenTK.Vector3 pt)
		{
			fixed (OpenTK.Vector3* ptPtr = &pt)
			{
				obj.AddVertex(ref *(BulletSharp.Math.Vector3*)ptPtr);
			}
		}
        public static void AddSolidRectangle(this DynamicPrimitive dynamicPrimitive, Vector2 min, Vector2 max, Color color, TextureId? texture = null, Matrix4x4? world = null)
        {
            dynamicPrimitive.BeginPrimitive(PrimitiveType.Triangles, texture, world);
            {
                dynamicPrimitive.AddVertex(new Vector3(min.X, min.Y, 0), color, new Vector2(0, 0));
                dynamicPrimitive.AddVertex(new Vector3(min.X, max.Y, 0), color, new Vector2(0, 1));
                dynamicPrimitive.AddVertex(new Vector3(max.X, max.Y, 0), color, new Vector2(1, 1));
                dynamicPrimitive.AddVertex(new Vector3(max.X, min.Y, 0), color, new Vector2(1, 0));

                dynamicPrimitive.AddIndex(0);
                dynamicPrimitive.AddIndex(1);
                dynamicPrimitive.AddIndex(2);

                dynamicPrimitive.AddIndex(2);
                dynamicPrimitive.AddIndex(3);
                dynamicPrimitive.AddIndex(0);
            }
            dynamicPrimitive.EndPrimitive();
        }
        // TODO: Add more advanced texture rectangles
        //       Like texture region and texture rotation

        public static void AddRectangle(this DynamicPrimitive dynamicPrimitive, Vector2 min, Vector2 max, Color color, Matrix4x4? world = null, float lineWidth = 1)
        {
            dynamicPrimitive.BeginPrimitive(PrimitiveType.Lines, null, world, lineWidth);
            {
                dynamicPrimitive.AddVertex(new Vector3(min.X, min.Y, 0), color);
                dynamicPrimitive.AddVertex(new Vector3(min.X, max.Y, 0), color);
                dynamicPrimitive.AddVertex(new Vector3(max.X, max.Y, 0), color);
                dynamicPrimitive.AddVertex(new Vector3(max.X, min.Y, 0), color);

                dynamicPrimitive.AddIndex(0);
                dynamicPrimitive.AddIndex(1);
                dynamicPrimitive.AddIndex(1);
                dynamicPrimitive.AddIndex(2);
                dynamicPrimitive.AddIndex(2);
                dynamicPrimitive.AddIndex(3);
                dynamicPrimitive.AddIndex(3);
                dynamicPrimitive.AddIndex(0);
            }
            dynamicPrimitive.EndPrimitive();
        }
        public static void AddRectangle(this DynamicPrimitive dynamicPrimitive, Vector2 min, Vector2 max, Vector3 up, Color color, Matrix4x4? world = null, float lineWidth = 1)
        {
            var transform = MathHelper.CreateRotation(new Vector3(0, 1, 0), up);

            dynamicPrimitive.BeginPrimitive(PrimitiveType.Lines, null, world, lineWidth);
            {
                dynamicPrimitive.AddVertex(Vector3.TransformNormal(new Vector3(min.X, min.Y, 0), transform), color);
                dynamicPrimitive.AddVertex(Vector3.TransformNormal(new Vector3(min.X, max.Y, 0), transform), color);
                dynamicPrimitive.AddVertex(Vector3.TransformNormal(new Vector3(max.X, max.Y, 0), transform), color);
                dynamicPrimitive.AddVertex(Vector3.TransformNormal(new Vector3(max.X, min.Y, 0), transform), color);

                dynamicPrimitive.AddIndex(0);
                dynamicPrimitive.AddIndex(1);
                dynamicPrimitive.AddIndex(1);
                dynamicPrimitive.AddIndex(2);
                dynamicPrimitive.AddIndex(2);
                dynamicPrimitive.AddIndex(3);
                dynamicPrimitive.AddIndex(3);
                dynamicPrimitive.AddIndex(0);
            }
            dynamicPrimitive.EndPrimitive();
        }
		public unsafe static void AddVertex(this VoronoiSimplexSolver obj, ref OpenTK.Vector3 w, ref OpenTK.Vector3 p, ref OpenTK.Vector3 q)
		{
			fixed (OpenTK.Vector3* wPtr = &w)
			{
				fixed (OpenTK.Vector3* pPtr = &p)
				{
					fixed (OpenTK.Vector3* qPtr = &q)
					{
						obj.AddVertex(ref *(BulletSharp.Math.Vector3*)wPtr, ref *(BulletSharp.Math.Vector3*)pPtr, ref *(BulletSharp.Math.Vector3*)qPtr);
					}
				}
			}
		}
        /// <summary>
        /// Let the side with X to the right and Y up be the front.
        /// The texture is supposed to contain six (probably square) parts like this:
        ///     [ Left | Front | Right | Back | Top | Bottom ]
        /// Where the first four transition into each other
        /// and front and bottom transition into front.
        /// </summary>
        /// <param name="texRect">The texture coordinates for the first side only</param>
        public static void AddBox(this KModel model, BoundingBox bb, Rectangle texRect, bool sixSides)
        {
            //    6*----*7
            //    /    /|
            //  2*----*3|     Y
            //   |    | *5    |
            //   |    |/      |
            //  0*----*1      *---X
            //               /
            //              Z
            //
            int ve0 = model.AddVertex(new Vector3(bb.Min.X, bb.Min.Y, bb.Max.Z));
            int ve1 = model.AddVertex(new Vector3(bb.Max.X, bb.Min.Y, bb.Max.Z));
            int ve2 = model.AddVertex(new Vector3(bb.Min.X, bb.Max.Y, bb.Max.Z));
            int ve3 = model.AddVertex(new Vector3(bb.Max.X, bb.Max.Y, bb.Max.Z));
            int ve4 = model.AddVertex(new Vector3(bb.Min.X, bb.Min.Y, bb.Min.Z));
            int ve5 = model.AddVertex(new Vector3(bb.Max.X, bb.Min.Y, bb.Min.Z));
            int ve6 = model.AddVertex(new Vector3(bb.Min.X, bb.Max.Y, bb.Min.Z));
            int ve7 = model.AddVertex(new Vector3(bb.Max.X, bb.Max.Y, bb.Min.Z));

            // Left
            model.AddQuad(ve4, ve0, ve6, ve2, texRect);

            // Front
            if (sixSides) texRect.X += texRect.Width;
            model.AddQuad(ve0, ve1, ve2, ve3, texRect);

            // Right
            if (sixSides) texRect.X += texRect.Width;
            model.AddQuad(ve1, ve5, ve3, ve7, texRect);

            // Back
            if (sixSides) texRect.X += texRect.Width;
            model.AddQuad(ve5, ve4, ve7, ve6, texRect);

            // Top
            if (sixSides) texRect.X += texRect.Width;
            model.AddQuad(ve2, ve3, ve6, ve7, texRect);

            // Bottom
            if (sixSides) texRect.X += texRect.Width;
            model.AddQuad(ve4, ve5, ve0, ve1, texRect);
        }
        public static void AddCircle(this DynamicPrimitive dynamicPrimitive, Vector3 center, float radius, int tessellation, Color color, Matrix4x4? world = null, float lineWidth = 1)
        {
            dynamicPrimitive.BeginPrimitive(PrimitiveType.LineStrip, null, world, lineWidth);
            {
                if (tessellation < 3)
                    throw new ArgumentOutOfRangeException("tessellation");

                int horizontalSegments = tessellation;

                // Create a single ring of vertices at this latitude.
                for (int j = 0; j <= horizontalSegments; j++)
                {
                    float longitude = j * MathHelper.TwoPI / horizontalSegments;

                    float dx = (float)Math.Cos(longitude);
                    float dy = (float)Math.Sin(longitude);

                    Vector3 normal = new Vector3(dx, dy, 0);

                    dynamicPrimitive.AddVertex(normal * radius + center, color);
                }
            }
            dynamicPrimitive.EndPrimitive();
        }
 public static void AddLine(this DynamicPrimitive dynamicPrimitive, IEnumerable<Vector3> lineStrip, Color color, Matrix4x4? world = null, float lineWidth = 1)
 {
     dynamicPrimitive.BeginPrimitive(PrimitiveType.LineStrip, null, world, lineWidth);
     {
         foreach (Vector3 position in lineStrip)
         {
             dynamicPrimitive.AddVertex(position, color);
         }
     }
     dynamicPrimitive.EndPrimitive();
 }
 public static void AddLine(this DynamicPrimitive dynamicPrimitive, Vector3 v1, Vector3 v2, Color color, Matrix4x4? world = null, float lineWidth = 1)
 {
     dynamicPrimitive.BeginPrimitive(PrimitiveType.Lines, null, world, lineWidth);
     {
         dynamicPrimitive.AddVertex(v1, color);
         dynamicPrimitive.AddVertex(v2, color);
     }
     dynamicPrimitive.EndPrimitive();
 }
        public static void AddGrid(this DynamicPrimitive dynamicPrimitive, float x, float y, float z, float width, float height, int countX, int countZ, Color color, Matrix4x4? world = null, float lineWidth = 1)
        {
            dynamicPrimitive.BeginPrimitive(PrimitiveType.Lines, null, world, lineWidth);
            {
                float incU = width / countX;
                float incV = height / countZ;

                for (int u = 0; u <= countX; u++)
                {
                    dynamicPrimitive.AddVertex(new Vector3(x + 0, y, z + u * incU), color);
                    dynamicPrimitive.AddVertex(new Vector3(x + height, y, z + u * incU), color);
                }

                for (int v = 0; v <= countZ; v++)
                {
                    dynamicPrimitive.AddVertex(new Vector3(x + v * incV, y, z + 0), color);
                    dynamicPrimitive.AddVertex(new Vector3(x + v * incV, y, z + width), color);
                }
            }
            dynamicPrimitive.EndPrimitive();
        }
        public static void DrawRectangle(this PrimitiveBatch primitiveBatch, bool filled, Vector2 centre, Vector2 size, float rotation, Color color)
        {
            //Quaternion quat = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, rotation);
            //size = Vector2.Transform(size, quat);

            Vector2 halfSize = size / 2;
            Vector2 altHalfSize = new Vector2(halfSize.X, -halfSize.Y);

            Quaternion quat = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, rotation);
            halfSize = Vector2.Transform(halfSize, quat);
            altHalfSize = Vector2.Transform(altHalfSize, quat);
            //Vector2 topLeft = centre - halfSize;

            //Matrix rot = Matrix.CreateRotationZ(rotation);

            //size = Vector2.Transform(halfSize, quat);

            if (filled)
            {
                primitiveBatch.Begin(PrimitiveType.TriangleList);

                primitiveBatch.AddVertex(centre - halfSize, color);
                primitiveBatch.AddVertex(centre + altHalfSize, color);
                primitiveBatch.AddVertex(centre - altHalfSize, color);

                primitiveBatch.AddVertex(centre + halfSize, color);
                primitiveBatch.AddVertex(centre - altHalfSize, color);
                primitiveBatch.AddVertex(centre + altHalfSize, color);

                primitiveBatch.End();
            }
            else
            {
                primitiveBatch.Begin(PrimitiveType.LineList);
                //top
                primitiveBatch.AddVertex(centre - halfSize, color);
                primitiveBatch.AddVertex(centre + altHalfSize, color);

                primitiveBatch.AddVertex(centre + altHalfSize, color);
                primitiveBatch.AddVertex(centre + halfSize, color);

                primitiveBatch.AddVertex(centre + halfSize, color);
                primitiveBatch.AddVertex(centre - altHalfSize, color);

                primitiveBatch.AddVertex(centre - altHalfSize, color);
                primitiveBatch.AddVertex(centre - halfSize, color);

                primitiveBatch.End();
            }
        }
Example #15
0
        public static MeshBuilderIterator Triangle(this MeshBuilderIterator mesh)
        {
            mesh.AddVertex(Vector3.up);
            mesh.AddVertex(Vector3.right.Rotate(new Vector3(0, 0, 30)));

            return mesh;
        }