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


C# World.rayCast方法代码示例

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


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

示例1: cut

		/// <summary>
		/// This is a high-level function to cuts fixtures inside the given world, using the start and end points.
		/// Note: We don't support cutting when the start or end is inside a shape.
		/// </summary>
		/// <param name="world">The world.</param>
		/// <param name="start">The startpoint.</param>
		/// <param name="end">The endpoint.</param>
		/// <returns>True if the cut was performed.</returns>
		public static bool cut( World world, Vector2 start, Vector2 end )
		{
			var fixtures = new List<Fixture>();
			var entryPoints = new List<Vector2>();
			var exitPoints = new List<Vector2>();

			//We don't support cutting when the start or end is inside a shape.
			if( world.testPoint( start ) != null || world.testPoint( end ) != null )
				return false;

			//Get the entry points
			world.rayCast( ( f, p, n, fr ) =>
							   {
								   fixtures.Add( f );
								   entryPoints.Add( p );
								   return 1;
							   }, start, end );

			//Reverse the ray to get the exitpoints
			world.rayCast( ( f, p, n, fr ) =>
							   {
								   exitPoints.Add( p );
								   return 1;
							   }, end, start );

			//We only have a single point. We need at least 2
			if( entryPoints.Count + exitPoints.Count < 2 )
				return false;

			for( int i = 0; i < fixtures.Count; i++ )
			{
				// can't cut circles or edges yet !
				if( fixtures[i].shape.shapeType != ShapeType.Polygon )
					continue;

				if( fixtures[i].body.bodyType != BodyType.Static )
				{
					//Split the shape up into two shapes
					Vertices first;
					Vertices second;
					splitShape( fixtures[i], entryPoints[i], exitPoints[i], out first, out second );

					//Delete the original shape and create two new. Retain the properties of the body.
					if( first.checkPolygon() == PolygonError.NoError )
					{
						Body firstFixture = BodyFactory.CreatePolygon( world, first, fixtures[i].shape.density, fixtures[i].body.position );
						firstFixture.rotation = fixtures[i].body.rotation;
						firstFixture.linearVelocity = fixtures[i].body.linearVelocity;
						firstFixture.angularVelocity = fixtures[i].body.angularVelocity;
						firstFixture.bodyType = BodyType.Dynamic;
					}

					if( second.checkPolygon() == PolygonError.NoError )
					{
						Body secondFixture = BodyFactory.CreatePolygon( world, second, fixtures[i].shape.density, fixtures[i].body.position );
						secondFixture.rotation = fixtures[i].body.rotation;
						secondFixture.linearVelocity = fixtures[i].body.linearVelocity;
						secondFixture.angularVelocity = fixtures[i].body.angularVelocity;
						secondFixture.bodyType = BodyType.Dynamic;
					}

					world.removeBody( fixtures[i].body );
				}
			}

			return true;
		}
开发者ID:prime31,项目名称:Nez,代码行数:75,代码来源:CuttingTools.cs


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