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


C# Vertices.Translate方法代码示例

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


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

示例1: ConvexHullTest2

        private ConvexHullTest2()
        {
            _pointCloud1 = new Vertices(32);

            for (int i = 0; i < 32; i++)
            {
                float x = Rand.RandomFloat(-10, 10);
                float y = Rand.RandomFloat(-10, 10);

                _pointCloud1.Add(new Vector2(x, y));
            }

            _pointCloud2 = new Vertices(_pointCloud1);
            _pointCloud3 = new Vertices(_pointCloud1);

            //Melkman DOES NOT work on point clouds. It only works on simple polygons.
            _pointCloud1.Translate(new Vector2(-20, 30));
            _melkman = Melkman.GetConvexHull(_pointCloud1);

            //Giftwrap works on point clouds

            _pointCloud2.Translate(new Vector2(20, 30));
            _giftWrap = GiftWrap.GetConvexHull(_pointCloud2);

            _pointCloud3.Translate(new Vector2(20, 10));
            _chainHull = ChainHull.GetConvexHull(_pointCloud3);
        }
开发者ID:boris2,项目名称:mmogameproject2,代码行数:27,代码来源:ConvexHullTest2.cs

示例2: TextureFromVertices

        public Texture2D TextureFromVertices(Vertices vertices, Texture2D material, Color fillColor, bool hasOutline, Color outlineColor, float materialScale)
        {
            Vertices verts = new Vertices(vertices);

            AABB vertsBounds = verts.GetCollisionBox();
            verts.Translate(-vertsBounds.Center);

            List<Vertices> decomposedVerts;
            if (!verts.IsConvex())
            {
                decomposedVerts = EarclipDecomposer.ConvexPartition(verts);
            }
            else
            {
                decomposedVerts = new List<Vertices>()
                    {
                        verts
                    };
            }

            //fill
            List<VertexPositionColorTexture[]> verticesFill = new List<VertexPositionColorTexture[]>(decomposedVerts.Count);
            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++)
                {
                    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 = fillColor;
                }
            }

            //outline
            VertexPositionColor[] verticesOutline;

            if (!hasOutline)
            {
                verticesOutline = new VertexPositionColor[0];
            }
            else
            {
                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 = outlineColor;
                }
            }

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

            return RenderTexture((int)System.Math.Ceiling(vertsSize.X), (int)System.Math.Ceiling(vertsSize.Y), material, verticesFill, hasOutline, verticesOutline);
        }
开发者ID:neaket,项目名称:Dragonfly,代码行数:59,代码来源:TextureGenerator.cs

示例3: 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

示例4: 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

示例5: 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

示例6: Update

        public override void Update(GameSettings settings, GameTime gameTime)
        {
            base.Update(settings, gameTime);

            DebugView.DrawString(50, TextLine, "Press: left mouse button to remove at mouse position.");
            TextLine += 15;
            DebugView.DrawString(50, TextLine, "Press: (A) to decrease the removal radius, (S) to increase it.");
            TextLine += 15;
            // Fighting against float decimals
            float radiusnumber = (float)((int)(Radius * 10)) / 10;
            DebugView.DrawString(50, TextLine, "Radius: " + radiusnumber);

            Color color = new Color(0.4f, 0.7f, 0.8f);

            //Transform shape to mouseposition and then draw
            Vertices tempshape = new Vertices(_clipCircle);
            tempshape.Translate(ref _mousePos);
            DebugView.BeginCustomDraw();
            DebugView.DrawPolygon(tempshape.ToArray(), _clipCircle.Count, color);
            DebugView.EndCustomDraw();
        }
开发者ID:eickegao,项目名称:cocos2d-xna,代码行数:21,代码来源:DestructibleTerrainYuPengTest.cs

示例7: ConstructFromVertices

        /// <summary>
        /// 
        /// </summary>
        /// <param name="world"></param>
        /// <param name="vertices">The collection in vertices in display units (pixels)</param>
        /// <param name="density"></param>
        private void ConstructFromVertices(World world, Vertices vertices, float density)
        {
            //We need to find the real center (centroid) of the vertices for 2 reasons:

            //1. To translate the vertices so the polygon is centered around the centroid.
            var centroid = -vertices.GetCentroid();
            vertices.Translate(ref centroid);

            //2. To draw the texture the correct place.
            Center = -centroid;

            //We simplify the vertices found in the texture.
            vertices = SimplifyTools.ReduceByDistance(vertices, 4f);

            //Since it is a concave polygon, we need to partition it into several smaller convex polygons
            List<Vertices> list = BayazitDecomposer.ConvexPartition(vertices);
            //List<Vertices> list = EarclipDecomposer.ConvexPartition(vertices);

            //Now we need to scale the vertices (result is in pixels, we use meters)
            Vector2 vertScale = new Vector2(ConvertUnits.SimUnitsToDisplayUnitsRatio);// new Vector2(ConvertUnits.ToSimUnits(1)) * _scale;

            foreach (Vertices newVertices in list)
            {

                newVertices.Scale(ref vertScale);
            }

            Body = BodyFactory.CreateCompoundPolygon(world, list, density);
        }
开发者ID:dreasgrech,项目名称:FarseerPhysicsBaseFramework,代码行数:35,代码来源:PhysicsGameEntity.cs

示例8: Initialize

        public override void Initialize()
        {
            base.Initialize();

            GameInstance.ViewCenter = Vector2.Zero;

            _twoShape = new Vertices
            {
                new Vector2(5.510646f,-6.312136f),
                new Vector2(5.510646f,-9.534955f),
                new Vector2(-6.016356f,-9.534955f),
                new Vector2(-6.016356f,-6.837597f),
                new Vector2(-1.933609f,-0.7320573f),
                new Vector2(-0.6714239f,1.242431f),
                new Vector2(0.07130214f,2.498066f),
                new Vector2(0.4939168f,3.344996f),
                new Vector2(0.7957863f,4.093408f),
                new Vector2(0.9769094f,4.743301f),
                new Vector2(1.037288f,5.294677f),
                new Vector2(0.9643505f,5.967545f),
                new Vector2(0.7455474f,6.44485f),
                new Vector2(0.5806286f,6.610869f),
                new Vector2(0.3776243f,6.729462f),
                new Vector2(0.1365345f,6.80062f),
                new Vector2(-0.1426414f,6.824349f),
                new Vector2(-0.4218241f,6.798073f),
                new Vector2(-0.6629166f,6.719252f),
                new Vector2(-0.8659183f,6.587883f),
                new Vector2(-1.030829f,6.403981f),
                new Vector2(-1.158469f,6.141973f),
                new Vector2(-1.249639f,5.776335f),
                new Vector2(-1.32257f,4.734189f),
                new Vector2(-1.32257f,2.935948f),
                new Vector2(-6.016356f,2.935948f),
                new Vector2(-6.016356f,3.624884f),
                new Vector2(-5.970973f,5.045072f),
                new Vector2(-5.834826f,6.129576f),
                new Vector2(-5.710837f,6.586056f),
                new Vector2(-5.520398f,7.0389f),
                new Vector2(-5.263501f,7.488094f),
                new Vector2(-4.940154f,7.933653f),
                new Vector2(-4.556844f,8.350358f),
                new Vector2(-4.120041f,8.71307f),
                new Vector2(-3.629755f,9.02178f),
                new Vector2(-3.085981f,9.276493f),
                new Vector2(-2.487104f,9.475718f),
                new Vector2(-1.8315f,9.618026f),
                new Vector2(-1.119165f,9.703418f),
                new Vector2(-0.3501012f,9.731889f),
                new Vector2(1.117107f,9.644661f),
                new Vector2(1.779295f,9.535644f),
                new Vector2(2.393876f,9.383026f),
                new Vector2(2.960846f,9.186799f),
                new Vector2(3.480206f,8.946972f),
                new Vector2(3.951957f,8.663539f),
                new Vector2(4.376098f,8.336502f),
                new Vector2(5.076675f,7.592458f),
                new Vector2(5.577088f,6.755733f),
                new Vector2(5.877342f,5.82633f),
                new Vector2(5.977431f,4.804249f),
                new Vector2(5.921109f,3.981021f),
                new Vector2(5.752138f,3.134446f),
                new Vector2(5.470524f,2.264521f),
                new Vector2(5.076274f,1.371247f),
                new Vector2(4.406482f,0.2123121f),
                new Vector2(3.298271f,-1.454563f),
                new Vector2(1.751642f,-3.629379f),
                new Vector2(-0.233405f,-6.312136f),
            };

            int beforeCount = _twoShape.Count;
            _twoShape.AddRange(_twoShape); //Duplicate the points
            _twoShape = SimplifyTools.MergeIdenticalPoints(_twoShape);

            Debug.Assert(beforeCount == _twoShape.Count); //The merge should have removed all duplicate points.

            const int xOffset = 18;
            const int yOffset = 18;

            _upperLeft = new Vertices(_twoShape);
            _upperLeft.Translate(new Vector2(-xOffset, yOffset));
            _upperLeft = SimplifyTools.ReduceByArea(_upperLeft, 0.1f);

            _upperRight = new Vertices(_twoShape);
            _upperRight.Translate(new Vector2(xOffset, yOffset));
            _upperRight = SimplifyTools.ReduceByNth(_upperRight, 3);

            _lowerLeft = new Vertices(_twoShape);
            _lowerLeft.Translate(new Vector2(-xOffset, -yOffset));
            _lowerLeft = SimplifyTools.ReduceByDistance(_lowerLeft, 0.5f);

            _lowerRight = new Vertices(_twoShape);
            _lowerRight.Translate(new Vector2(xOffset, -yOffset));
            _lowerRight = SimplifyTools.DouglasPeuckerSimplify(_lowerRight, 0.5f);
        }
开发者ID:RCGame,项目名称:FarseerPhysics,代码行数:95,代码来源:SimplificationTest.cs

示例9: 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

示例10: CreatePolygonGeom

        /// <summary>
        /// Creates a polygon geom.
        /// </summary>
        /// <param name="body">The body.</param>
        /// <param name="vertices">The vertices.</param>
        /// <param name="positionOffset">The offset.</param>
        /// <param name="rotationOffset">The rotation offset.</param>
        /// <param name="collisionGridSize">Size of the collision grid. - not used with SAT
        /// Put in 0 or less to make the engine calculate a grid cell size.</param>
        /// <returns></returns>
        public Geom CreatePolygonGeom(Body body, Vertices vertices, Vector2 positionOffset, float rotationOffset, float collisionGridSize)
        {
            if (body == null)
                throw new ArgumentNullException("body", "Body must not be null");

            if (vertices == null)
                throw new ArgumentNullException("vertices", "Vertices must not be null");
            
            //Adjust the verts to be relative to the centroid.
            Vector2 centroid = vertices.GetCentroid();

            Vector2.Multiply(ref centroid, -1, out centroid);

            vertices.Translate(ref centroid);

            Geom geometry = new Geom(body, vertices, positionOffset, rotationOffset, collisionGridSize);
            return geometry;
        }
开发者ID:elefantstudio-se,项目名称:todesesser,代码行数:28,代码来源:GeomFactory.cs

示例11: findShadowHull

        public void findShadowHull(Texture2D texture)
        {
            //Create an array to hold the data from the texture
            uint[] data = new uint[texture.Width * texture.Height];

            //Transfer the texture data to the array
            texture.GetData(data);

            //Find the vertices that makes up the outline of the shape in the texture
            textureVertices = PolygonTools.CreatePolygon(data, texture.Width, false);

            //The tool return vertices as they were found in the texture.
            //We need to find the real center (centroid) of the vertices for 2 reasons:

            //1. To translate the vertices so the polygon is centered around the centroid.
            Vector2 centroid = -textureVertices.GetCentroid();
            textureVertices.Translate(ref centroid);

            //2. To draw the texture the correct place.
            _origin = -centroid;

            //We simplify the vertices found in the texture.
            textureVertices = SimplifyTools.CollinearSimplify(textureVertices, 0f);

            //Since it is a concave polygon, we need to partition it into several smaller convex polygons
            list = BayazitDecomposer.ConvexPartition(textureVertices);

            //Adjust the scale of the object for WP7's lower resolution
            //Adjust the scale of the object for WP7's lower resolution
            #if WINDOWS_PHONE
                _scale = 0.6f;
            #else
            _scale = 1f;
            #endif

            //scale the vertices from graphics space to sim space
            Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1)) * _scale;
            foreach (Vertices vertices in list)
            {
                vertices.Scale(ref vertScale);
                Vector2[] verticesArray = vertices.ToArray();
                var hull = ShadowHull.CreateConvex(ref verticesArray);
                hulls.Add(hull);
                krypton.Hulls.Add(hull);
            }
        }
开发者ID:CharlesMicou,项目名称:Projects,代码行数:46,代码来源:Sprite.cs

示例12: CreatePolygonGeom

        /// <summary>
        /// 
        /// </summary>
        /// <param name="body"></param>
        /// <param name="vertices"></param>
        /// <param name="offset"></param>
        /// <param name="rotationOffset"></param>
        /// <param name="collisionGridCellSize">Pass in 0 or less to make Farseer calculate the grid cell size</param>
        /// <returns></returns>
        public Geom CreatePolygonGeom(Body body, Vertices vertices, Vector2 offset, float rotationOffset,
                                      float collisionGridCellSize)
        {
            //adjust the verts to be relative to 0,0
            Vector2 centroid = vertices.GetCentroid();
            vertices.Translate(-centroid);

            if (collisionGridCellSize <= 0)
            {
                collisionGridCellSize = CalculateGridCellSizeFromAABB(vertices);
            }
            Geom geometry = new Geom(body, vertices, offset, rotationOffset, collisionGridCellSize);
            return geometry;
        }
开发者ID:amwaterston,项目名称:paradux,代码行数:23,代码来源:GeomFactory.cs

示例13: InitOuterWall

        private void InitOuterWall(Vertices vertices)
        {
            if (vertices.Count < 3)
            {
                Console.WriteLine("Too few vertices " + vertices.Count);
                return;
            }

            Vertices drawingVertices = new Vertices(vertices);
            float scale = _thickness / drawingVertices.GetRadius() + 1;
            Vector2 scaleVector = new Vector2(scale);
            Vector2 translation = drawingVertices.GetCentroid();
            drawingVertices.Translate(-translation);
            drawingVertices.Scale(ref scaleVector);
            drawingVertices.Translate(translation);

            _wallVerts = new VertexPositionTexture[vertices.Count * 2 + 2];
            for (int i = 0; i < vertices.Count; ++i)
            {
                int j = i * 2;
                _wallVerts[j].Position.X = vertices[i].X;
                _wallVerts[j].Position.Y = vertices[i].Y;
                _wallVerts[j].Position.Z = 0;
                _wallVerts[j].TextureCoordinate = vertices[i] / _textureScaling;

                _wallVerts[j + 1].Position.X = drawingVertices[i].X;
                _wallVerts[j + 1].Position.Y = drawingVertices[i].Y;
                _wallVerts[j + 1].Position.Z = 0;
                _wallVerts[j + 1].TextureCoordinate = drawingVertices[i] / _textureScaling;

            }
            int lastIndex = vertices.Count * 2;
            _wallVerts[lastIndex].Position.X = vertices[0].X;
            _wallVerts[lastIndex].Position.Y = vertices[0].Y;
            _wallVerts[lastIndex].Position.Z = 0;
            _wallVerts[lastIndex].TextureCoordinate = vertices[0] / _textureScaling;

            _wallVerts[lastIndex + 1].Position.X = drawingVertices[0].X;
            _wallVerts[lastIndex + 1].Position.Y = drawingVertices[0].Y;
            _wallVerts[lastIndex + 1].Position.Z = 0;
            _wallVerts[lastIndex + 1].TextureCoordinate = drawingVertices[0] / _textureScaling;
        }
开发者ID:em-mo,项目名称:sommarhack,代码行数:42,代码来源:Wall.cs


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