当前位置: 首页>>代码示例>>C#>>正文


C# Vertices.GetAABB方法代码示例

本文整理汇总了C#中Vertices.GetAABB方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.GetAABB方法的具体用法?C# Vertices.GetAABB怎么用?C# Vertices.GetAABB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vertices的用法示例。


在下文中一共展示了Vertices.GetAABB方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        /// <summary>
        /// Implements "A new algorithm for Boolean operations on general polygons" 
        /// available here: http://liama.ia.ac.cn/wiki/_media/user:dong:dong_cg_05.pdf
        /// Merges two polygons, a subject and a clip with the specified operation. Polygons may not be 
        /// self-intersecting.
        /// 
        /// Warning: May yield incorrect results or even crash if polygons contain collinear points.
        /// </summary>
        /// <param name="subject">The subject polygon.</param>
        /// <param name="clip">The clip polygon, which is added, 
        /// substracted or intersected with the subject</param>
        /// <param name="clipType">The operation to be performed. Either
        /// Union, Difference or Intersection.</param>
        /// <param name="error">The error generated (if any)</param>
        /// <returns>A list of closed polygons, which make up the result of the clipping operation.
        /// Outer contours are ordered counter clockwise, holes are ordered clockwise.</returns>
        private static List<Vertices> Execute(Vertices subject, Vertices clip,
                                              PolyClipType clipType, out PolyClipError error)
        {
            Debug.Assert(subject.IsSimple() && clip.IsSimple(), "Non simple input!", "Input polygons must be simple (cannot intersect themselves).");

            // Copy polygons
            Vertices slicedSubject;
            Vertices slicedClip;
            // Calculate the intersection and touch points between
            // subject and clip and add them to both
            CalculateIntersections(subject, clip, out slicedSubject, out slicedClip);

            // Translate polygons into upper right quadrant
            // as the algorithm depends on it
            Vector2 lbSubject = subject.GetAABB().LowerBound;
            Vector2 lbClip = clip.GetAABB().LowerBound;
            Vector2 translate;
            Vector2.Min(ref lbSubject, ref lbClip, out translate);
            translate = Vector2.One - translate;
            if (translate != Vector2.Zero)
            {
                slicedSubject.Translate(ref translate);
                slicedClip.Translate(ref translate);
            }

            // Enforce counterclockwise contours
            slicedSubject.ForceCounterClockWise();
            slicedClip.ForceCounterClockWise();

            List<Edge> subjectSimplices;
            List<float> subjectCoeff;
            List<Edge> clipSimplices;
            List<float> clipCoeff;
            // Build simplical chains from the polygons and calculate the
            // the corresponding coefficients
            CalculateSimplicalChain(slicedSubject, out subjectCoeff, out subjectSimplices);
            CalculateSimplicalChain(slicedClip, out clipCoeff, out clipSimplices);

            List<Edge> resultSimplices;

            // Determine the characteristics function for all non-original edges
            // in subject and clip simplical chain and combine the edges contributing
            // to the result, depending on the clipType
            CalculateResultChain(subjectCoeff, subjectSimplices, clipCoeff, clipSimplices, clipType,
                                 out resultSimplices);

            List<Vertices> result;
            // Convert result chain back to polygon(s)
            error = BuildPolygonsFromChain(resultSimplices, out result);

            // Reverse the polygon translation from the beginning
            // and remove collinear points from output
            translate *= -1f;
            for (int i = 0; i < result.Count; ++i)
            {
                result[i].Translate(ref translate);
                SimplifyTools.CollinearSimplify(result[i]);
            }
            return result;
        }
开发者ID:netonjm,项目名称:Rube.Net,代码行数:76,代码来源:YuPengClipper.cs

示例2: GetSizeFromVertices

 /// <summary>
 /// Gets the size from vertices.
 /// </summary>
 /// <param name="vertices">The vertices.</param>
 /// <returns></returns>
 public static Vector2 GetSizeFromVertices( Vertices vertices )
 {
     Vertices verts = new Vertices( vertices );
     Vector2 scale = ConvertUnits.ToDisplayUnits( Vector2.One );
     verts.Scale( ref scale );
     AABB vertsBounds = verts.GetAABB();
     verts.Translate( -vertsBounds.Center );
     return new Vector2( vertsBounds.UpperBound.X - vertsBounds.LowerBound.X,
                                     vertsBounds.UpperBound.Y - vertsBounds.LowerBound.Y );
 }
开发者ID:headdetect,项目名称:Flux-XNA,代码行数:15,代码来源:VectorUtils.cs

示例3: TextureFromVertices

		public Texture2D TextureFromVertices(Vertices vertices, MaterialType type, Color color, float materialScale)
		{
			// copy vertices
			Vertices verts = new Vertices(vertices);

			// scale to display units (i.e. pixels) for rendering to texture
			Vector2 scale = ConvertUnits.ToDisplayUnits(Vector2.One);
			verts.Scale(ref scale);

			// translate the boundingbox center to the texture center
			// because we use an orthographic projection for rendering later
			AABB vertsBounds = verts.GetAABB();
			verts.Translate(-vertsBounds.Center);

			List<Vertices> decomposedVerts;
			if (!verts.IsConvex())
			{
				decomposedVerts = Triangulate.ConvexPartition(verts, TriangulationAlgorithm.Earclip);
			}
			else
			{
				decomposedVerts = new List<Vertices>();
				decomposedVerts.Add(verts);
			}
			List<VertexPositionColorTexture[]> verticesFill = new List<VertexPositionColorTexture[]>(decomposedVerts.Count);

			materialScale /= _materials[type].Width;

			for (int i = 0; i < decomposedVerts.Count; ++i)
			{
				verticesFill.Add(new VertexPositionColorTexture[3 * (decomposedVerts[i].Count - 2)]);
				for (int j = 0; j < decomposedVerts[i].Count - 2; ++j)
				{
					// fill vertices
					verticesFill[i][3 * j].Position = new Vector3(decomposedVerts[i][0], 0f);
					verticesFill[i][3 * j + 1].Position = new Vector3(decomposedVerts[i].NextVertex(j), 0f);
					verticesFill[i][3 * j + 2].Position = new Vector3(decomposedVerts[i].NextVertex(j + 1), 0f);
					verticesFill[i][3 * j].TextureCoordinate = decomposedVerts[i][0] * materialScale;
					verticesFill[i][3 * j + 1].TextureCoordinate = decomposedVerts[i].NextVertex(j) * materialScale;
					verticesFill[i][3 * j + 2].TextureCoordinate = decomposedVerts[i].NextVertex(j + 1) * materialScale;
					verticesFill[i][3 * j].Color = verticesFill[i][3 * j + 1].Color = verticesFill[i][3 * j + 2].Color = color;
				}
			}

			// calculate outline
			VertexPositionColor[] verticesOutline = new VertexPositionColor[2 * verts.Count];
			for (int i = 0; i < verts.Count; ++i)
			{
				verticesOutline[2 * i].Position = new Vector3(verts[i], 0f);
				verticesOutline[2 * i + 1].Position = new Vector3(verts.NextVertex(i), 0f);
				verticesOutline[2 * i].Color = verticesOutline[2 * i + 1].Color = Color.Black;
			}

			Vector2 vertsSize = new Vector2(vertsBounds.UpperBound.X - vertsBounds.LowerBound.X, vertsBounds.UpperBound.Y - vertsBounds.LowerBound.Y);
			return RenderTexture((int)vertsSize.X, (int)vertsSize.Y, _materials[type], verticesFill, verticesOutline);
		}
开发者ID:ayls,项目名称:Ayls.Game.Framework,代码行数:56,代码来源:AssetCreator.cs

示例4: TextureFromVertices

        public Texture2D TextureFromVertices(IEnumerable<Vector2> vertices, string textureRef, Color color, float materialScale)
        {
            Texture2D texture = null;

            if (this.IsInitialized)
            {
                // copy vertices
                Vertices verts = new Vertices(vertices);

                // scale to display units (i.e. pixels) for rendering to texture
                Vector2 scale = ConvertUnits.ToDisplayUnits(Vector2.One);
                verts.Scale(ref scale);

                // translate the boundingbox center to the texture center
                // because we use an orthographic projection for rendering later
                AABB vertsBounds = verts.GetAABB();
                verts.Translate(-vertsBounds.Center);

                List<Vertices> decomposedVerts;
                if (!verts.IsConvex())
                {
                    decomposedVerts = Triangulate.ConvexPartition(verts, TriangulationAlgorithm.Delauny);
                }
                else
                {
                    decomposedVerts = new List<Vertices>();
                    decomposedVerts.Add(verts);
                }

                List<VertexPositionColorTexture[]> verticesFill = new List<VertexPositionColorTexture[]>(decomposedVerts.Count);
                Texture2D material = ContentController.Instance.GetTextureMaterial(this.device, textureRef);

                materialScale /= material.Width;

                for (int i = 0; i < decomposedVerts.Count; ++i)
                {
                    verticesFill.Add(new VertexPositionColorTexture[3 * (decomposedVerts[i].Count - 2)]);
                    for (int j = 0; j < decomposedVerts[i].Count - 2; ++j)
                    {
                        // fill vertices
                        verticesFill[i][3 * j].Position = new Vector3(decomposedVerts[i][0], 0f);
                        verticesFill[i][(3 * j) + 1].Position = new Vector3(decomposedVerts[i].NextVertex(j), 0f);
                        verticesFill[i][(3 * j) + 2].Position = new Vector3(decomposedVerts[i].NextVertex(j + 1), 0f);
                        verticesFill[i][3 * j].TextureCoordinate = decomposedVerts[i][0] * materialScale;
                        verticesFill[i][(3 * j) + 1].TextureCoordinate = decomposedVerts[i].NextVertex(j) * materialScale;
                        verticesFill[i][(3 * j) + 2].TextureCoordinate = decomposedVerts[i].NextVertex(j + 1) * materialScale;
                        verticesFill[i][3 * j].Color = verticesFill[i][(3 * j) + 1].Color = verticesFill[i][(3 * j) + 2].Color = color;
                    }
                }

                /* calculate outline
                VertexPositionColor[] verticesOutline = new VertexPositionColor[2 * verts.Count];
                for (int i = 0; i < verts.Count; ++i)
                {
                    verticesOutline[2 * i].Position = new Vector3(verts[i], 0f);
                    verticesOutline[(2 * i) + 1].Position = new Vector3(verts.NextVertex(i), 0f);
                    verticesOutline[2 * i].Color = verticesOutline[(2 * i) + 1].Color = Color.Black;
                }
                */

                Vector2 vertsSize = new Vector2(vertsBounds.UpperBound.X - vertsBounds.LowerBound.X, vertsBounds.UpperBound.Y - vertsBounds.LowerBound.Y);
                texture = this.RenderTexture((int)Math.Ceiling(vertsSize.X), (int)Math.Ceiling(vertsSize.Y), material, verticesFill);
            }

            return texture;
        }
开发者ID:00erik2,项目名称:Physicist,代码行数:66,代码来源:AssetCreator.cs

示例5: PolygonTexture

        public static Texture2D PolygonTexture(Vertices vertices, string pattern, Color mainColor, Color patternColor, Color outlineColor, float materialScale)
        {
            if (_contentWrapper != null)
            {
                // copy vertices
                Vertices scaledVertices = new Vertices(vertices);

                // scale to display units (i.e. pixels) for rendering to texture
                Vector2 scale = ConvertUnits.ToDisplayUnits(Vector2.One);
                scaledVertices.Scale(ref scale);

                // translate the boundingbox center to the texture center
                // because we use an orthographic projection for rendering later
                AABB verticesBounds = scaledVertices.GetAABB();
                scaledVertices.Translate(-verticesBounds.Center);

                List<Vertices> decomposedVertices;
                if (!scaledVertices.IsConvex())
                {
                    decomposedVertices = Triangulate.ConvexPartition(scaledVertices, TriangulationAlgorithm.Earclip);
                }
                else
                {
                    decomposedVertices = new List<Vertices>();
                    decomposedVertices.Add(scaledVertices);
                }

                List<VertexPositionColorTexture[]> verticesFill = new List<VertexPositionColorTexture[]>(decomposedVertices.Count);

                if (_textureList.ContainsKey(pattern))
                {
                    materialScale /= _textureList[pattern].Width;
                }
                else
                {
                    materialScale = 1f;
                }

                for (int i = 0; i < decomposedVertices.Count; i++)
                {
                    verticesFill.Add(new VertexPositionColorTexture[3 * (decomposedVertices[i].Count - 2)]);
                    for (int j = 0; j < decomposedVertices[i].Count - 2; j++)
                    {
                        // fill vertices
                        verticesFill[i][3 * j].Position = new Vector3(decomposedVertices[i][0], 0f);
                        verticesFill[i][3 * j + 1].Position = new Vector3(decomposedVertices[i].NextVertex(j), 0f);
                        verticesFill[i][3 * j + 2].Position = new Vector3(decomposedVertices[i].NextVertex(j + 1), 0f);
                        verticesFill[i][3 * j].TextureCoordinate = decomposedVertices[i][0] * materialScale;
                        verticesFill[i][3 * j + 1].TextureCoordinate = decomposedVertices[i].NextVertex(j) * materialScale;
                        verticesFill[i][3 * j + 2].TextureCoordinate = decomposedVertices[i].NextVertex(j + 1) * materialScale;
                        verticesFill[i][3 * j].Color = verticesFill[i][3 * j + 1].Color = verticesFill[i][3 * j + 2].Color = mainColor;
                    }
                }

                // calculate outline
                VertexPositionColor[] verticesOutline = new VertexPositionColor[2 * scaledVertices.Count];
                for (int i = 0; i < scaledVertices.Count; i++)
                {
                    verticesOutline[2 * i].Position = new Vector3(scaledVertices[i], 0f);
                    verticesOutline[2 * i + 1].Position = new Vector3(scaledVertices.NextVertex(i), 0f);
                    verticesOutline[2 * i].Color = verticesOutline[2 * i + 1].Color = outlineColor;
                }

                Vector2 vertsSize = new Vector2(verticesBounds.UpperBound.X - verticesBounds.LowerBound.X, verticesBounds.UpperBound.Y - verticesBounds.LowerBound.Y);

                return _contentWrapper.RenderTexture((int)vertsSize.X, (int)vertsSize.Y, _textureList.ContainsKey(pattern) ? _textureList[pattern] : null, patternColor, verticesFill, verticesOutline);
            }
            return null;
        }
开发者ID:RCGame,项目名称:FarseerPhysics,代码行数:69,代码来源:ContentWrapper.cs


注:本文中的Vertices.GetAABB方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。