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


C# Segment.ClosestPointTo方法代码示例

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


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

示例1: SweptTest

		public override void SweptTest(CollisionFunctor cf, Part partA, Part partB, Vector3 delta)
		{
			var a = (SpherePart)partA;
			var b = (CapsulePart)partB;

			Segment path;
			path.P1 = a.World.Center;
			Vector3.Add(ref path.P1, ref delta, out path.P2);

			Capsule cap = b.World;
			cap.Radius += a.World.Radius;
			Segment capSegment = new Segment(b.World.P1, b.World.P2);

			float k;
			Vector3 pa, pb, normal;
			cap.Intersect(ref path, out k, out pa);
			if (k <= 1f)
			{
				capSegment.ClosestPointTo(ref pa, out k, out pb);
				Vector3.Subtract(ref pa, ref pb, out normal);
				normal.Normalize();
				Vector3.Multiply(ref normal, b.World.Radius, out pa);
				Vector3.Add(ref pb, ref pa, out pb);
				Vector3.Multiply(ref normal, -a.World.Radius, out pa);
				Vector3.Add(ref a.World.Center, ref pa, out pa);

				cf.WritePoint(ref pa, ref pb, ref normal);
			}
		}
开发者ID:jdddog,项目名称:jengasimulatorp4p,代码行数:29,代码来源:SphereCapsule.cs

示例2: DoOverlapTest

		private static bool DoOverlapTest(CollisionFunctor cf, CapsulePart a, CapsulePart b, Vector3 offset)
		{
			Segment capa, capb = new Segment(b.World.P1, b.World.P2);
			Vector3.Add(ref a.World.P1, ref offset, out capa.P1);
			Vector3.Add(ref a.World.P2, ref offset, out capa.P2);

			Vector3 pa, pb, normal, v;
			float sa, sb, r2 = a.World.Radius + b.World.Radius;
			r2 *= r2;

			// find the closest point between the two capsules
			Segment.ClosestPoints(ref capa, ref capb, out sa, out pa, out sb, out pb);
			Vector3.Subtract(ref pa, ref pb, out normal);
			if (normal.LengthSquared() - r2 >= Constants.Epsilon)
				return false;
			if (normal.LengthSquared() < Constants.Epsilon)
				normal = Vector3.UnitZ;

			normal.Normalize();
			Vector3.Multiply(ref normal, -a.World.Radius, out v);
			Vector3.Add(ref pa, ref v, out pa);
			Vector3.Multiply(ref normal, b.World.Radius, out v);
			Vector3.Add(ref pb, ref v, out pb);
			Vector3.Subtract(ref pa, ref offset, out pa);
			cf.WritePoint(ref pa, ref pb, ref normal);

			// if the two capsules are nearly parallel, an additional support point provides stability
			if (sa == 0f || sa == 1f)
			{
				pa = sa == 0f ? capa.P2 : capa.P1;
				capb.ClosestPointTo(ref pa, out sa, out pb);
			}
			else if (sb == 0f || sb == 1f)
			{
				pb = sb == 0f ? capb.P2 : capb.P1;
				capa.ClosestPointTo(ref pb, out sb, out pa);
			}
			else
				return true;

			float dist;
			Vector3.DistanceSquared(ref pa, ref pb, out dist);
			if (dist - r2 < Constants.Epsilon)
			{
				Vector3.Multiply(ref normal, -a.World.Radius, out v);
				Vector3.Add(ref pa, ref v, out pa);
				Vector3.Multiply(ref normal, b.World.Radius, out v);
				Vector3.Add(ref pb, ref v, out pb);
				Vector3.Subtract(ref pa, ref offset, out pa);
				cf.WritePoint(ref pa, ref pb, ref normal);
			}
			return true;
		}
开发者ID:jdddog,项目名称:jengasimulatorp4p,代码行数:53,代码来源:CapsuleCapsule.cs

示例3: OverlapTest

		public override void OverlapTest(CollisionFunctor cf, Part partA, Part partB)
		{
			var a = (SpherePart)partA;
			var b = (CapsulePart)partB;

			Segment cap = new Segment(b.World.P1, b.World.P2);
			Vector3 pa, pb, normal, v;
			float r2 = a.World.Radius + b.World.Radius;
			r2 *= r2;

			float sb;
			cap.ClosestPointTo(ref a.World.Center, out sb, out pb);
			Vector3.Subtract(ref a.World.Center, ref pb, out normal);
			if (normal.LengthSquared() - r2 >= Constants.Epsilon)
				return;
			normal.Normalize();

			Vector3.Multiply(ref normal, -a.World.Radius, out v);
			Vector3.Add(ref a.World.Center, ref v, out pa);
			Vector3.Multiply(ref normal, b.World.Radius, out v);
			Vector3.Add(ref pb, ref v, out pb);
			cf.WritePoint(ref pa, ref pb, ref normal);
		}
开发者ID:jdddog,项目名称:jengasimulatorp4p,代码行数:23,代码来源:SphereCapsule.cs


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