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


C# Collision.RayCastInput类代码示例

本文整理汇总了C#中FarseerPhysics.Collision.RayCastInput的典型用法代码示例。如果您正苦于以下问题:C# RayCastInput类的具体用法?C# RayCastInput怎么用?C# RayCastInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RayCastInput类属于FarseerPhysics.Collision命名空间,在下文中一共展示了RayCastInput类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RayCastCallbackWrapper

        private float RayCastCallbackWrapper(ref RayCastInput input, int proxyId)
        {
            FixtureProxy proxy = ContactManager.BroadPhase.GetUserData(proxyId);
            Fixture fixture = proxy.Fixture;
            int index = proxy.ChildIndex;
            RayCastOutput output;
            bool hit = fixture.RayCast(out output, ref input, index);

            if (hit)
            {
                float fraction = output.Fraction;
                Vector2 point = (1.0f - fraction)*input.Point1 + fraction*input.Point2;
                return _rayCastCallback(fixture, point, output.Normal, fraction);
            }

            return input.MaxFraction;
        }
开发者ID:dvgamer,项目名称:GhostLegend-XNA,代码行数:17,代码来源:World.cs

示例2: RayCast

        // From Real-time Collision Detection, p179.
        public bool RayCast(out RayCastOutput output, ref RayCastInput input)
        {
            output = new RayCastOutput();

            float tmin = -Settings.MaxFloat;
            float tmax = Settings.MaxFloat;

            Vector2 p = input.Point1;
            Vector2 d = input.Point2 - input.Point1;
            Vector2 absD = MathUtils.Abs(d);

            Vector2 normal = Vector2.Zero;

            for (int i = 0; i < 2; ++i)
            {
                float absD_i = i == 0 ? absD.X : absD.Y;
                float lowerBound_i = i == 0 ? LowerBound.X : LowerBound.Y;
                float upperBound_i = i == 0 ? UpperBound.X : UpperBound.Y;
                float p_i = i == 0 ? p.X : p.Y;

                if (absD_i < Settings.Epsilon)
                {
                    // Parallel.
                    if (p_i < lowerBound_i || upperBound_i < p_i)
                    {
                        return false;
                    }
                }
                else
                {
                    float d_i = i == 0 ? d.X : d.Y;

                    float inv_d = 1.0f / d_i;
                    float t1 = (lowerBound_i - p_i) * inv_d;
                    float t2 = (upperBound_i - p_i) * inv_d;

                    // Sign of the normal vector.
                    float s = -1.0f;

                    if (t1 > t2)
                    {
                        MathUtils.Swap(ref t1, ref t2);
                        s = 1.0f;
                    }

                    // Push the min up
                    if (t1 > tmin)
                    {
                        if (i == 0)
                        {
                            normal.X = s;
                        }
                        else
                        {
                            normal.Y = s;
                        }

                        tmin = t1;
                    }

                    // Pull the max down
                    tmax = Math.Min(tmax, t2);

                    if (tmin > tmax)
                    {
                        return false;
                    }
                }
            }

            // Does the ray start inside the box?
            // Does the ray intersect beyond the max fraction?
            if (tmin < 0.0f || input.MaxFraction < tmin)
            {
                return false;
            }

            // Intersection.
            output.Fraction = tmin;
            output.Normal = normal;
            return true;
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:83,代码来源:Collision.cs

示例3: RayCast

        /// <summary>
        /// Ray-cast the world for all fixtures in the path of the ray. Your callback
        /// controls whether you get the closest point, any point, or n-points.
        /// The ray-cast ignores shapes that contain the starting point.
        /// </summary>
        /// <param name="callback">A user implemented callback class.</param>
        /// <param name="point1">The ray starting point.</param>
        /// <param name="point2">The ray ending point.</param>
        public void RayCast(RayCastCallback callback, Vector2 point1, Vector2 point2)
        {
            RayCastInput input = new RayCastInput();
            input.MaxFraction = 1.0f;
            input.Point1 = point1;
            input.Point2 = point2;

            _rayCastCallback = callback;
            ContactManager.BroadPhase.RayCast(_rayCastCallbackWrapper, ref input);
            _rayCastCallback = null;
        }
开发者ID:dvgamer,项目名称:GhostLegend-XNA,代码行数:19,代码来源:World.cs

示例4: CheckOnGround

 public void CheckOnGround()
 {
     RayCastInput input = new RayCastInput();
     input.Point1 = player.PhysObj.Position;
     input.Point2 = input.Point1 + 10 * new Vector2((float)Math.Sin(0), (float)Math.Cos(0));
     input.MaxFraction = 1;
     float closest = 1;
     foreach (Body b in world.world.BodyList)
     {
         if (b.Enabled)
             foreach (Fixture f in b.FixtureList)
             {
                 if (f.CollisionCategories == Category.Cat16 || f.CollisionCategories == Category.Cat25)
                     continue;
                 RayCastOutput output;
                 if (!f.RayCast(out output, ref input, 0))
                     continue;
                 if (output.Fraction < closest)
                 {
                     closest = output.Fraction;
                 }
             }
     }
     onGround = closest < 0.8f;
 }
开发者ID:WebFreak001,项目名称:LD-30,代码行数:25,代码来源:GameEventListener.cs

示例5: RayCast

        /// <summary>
        /// Ray-cast the world for all fixtures in the path of the ray. Your callback
        /// controls whether you get the closest point, any point, or n-points.
        /// The ray-cast ignores shapes that contain the starting point.
        /// 
        /// Inside the callback:
        /// return -1: ignore this fixture and continue
        /// return 0: terminate the ray cast
        /// return fraction: clip the ray to this point
        /// return 1: don't clip the ray and continue
        /// </summary>
        /// <param name="callback">A user implemented callback class.</param>
        /// <param name="point1">The ray starting point.</param>
        /// <param name="point2">The ray ending point.</param>
        public void RayCast(RayCastCallback callback, Vector2 point1, Vector2 point2)
        {
            RayCastInput input = new RayCastInput();
            input.MaxFraction = 1.0f;
            input.Point1 = point1;
            input.Point2 = point2;

            ContactManager.BroadPhase.RayCast((rayCastInput, proxyId) =>
                                                  {
                                                      FixtureProxy proxy = ContactManager.BroadPhase.GetProxy(proxyId);
                                                      Fixture fixture = proxy.Fixture;
                                                      int index = proxy.ChildIndex;
                                                      RayCastOutput output;
                                                      bool hit = fixture.RayCast(out output, ref rayCastInput, index);

                                                      if (hit)
                                                      {
                                                          float fraction = output.Fraction;
                                                          Vector2 point = (1.0f - fraction) * input.Point1 +
                                                                          fraction * input.Point2;
                                                          return callback(fixture, point, output.Normal, fraction);
                                                      }

                                                      return input.MaxFraction;
                                                  }, ref input);
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:40,代码来源:World.cs

示例6: RayCast

 /// <summary>
 /// Cast a ray against this Shape.
 /// </summary>
 /// <param name="output">The ray-cast results.</param>
 /// <param name="input">The ray-cast input parameters.</param>
 /// <param name="childIndex">Index of the child.</param>
 /// <returns></returns>
 public bool RayCast(out RayCastOutput output, ref RayCastInput input, int childIndex)
 {
     return Shape.RayCast(out output, ref input, ref Body.Xf, childIndex);
 }
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:11,代码来源:Fixture.cs

示例7: RayCast

 public void RayCast(Func<RayCastInput, int, float> callback, ref RayCastInput input)
 {
     _quadTree.RayCast(TransformRayCallback(callback), ref input);
 }
开发者ID:kyallbarrows,项目名称:Cinch_4-3,代码行数:4,代码来源:QuadTreeBroadPhase.cs

示例8: RayCastCallback

        public float RayCastCallback(ref RayCastInput input, int proxyId)
        {
            FixtureProxy proxy = ContactManager.BroadPhase.GetProxy(proxyId);
            Fixture fixture = proxy.Fixture;
            int index = proxy.ChildIndex;
            RayCastOutput output;
            bool hit = fixture.RayCast(out output, ref input, index);

            if (hit)
            {
                float fraction = output.Fraction;
                Vector2 point = (1.0f - fraction) * input.Point1 + fraction * input.Point2;
                if (rayCastCallback != null)
                {
                    return rayCastCallback(fixture, point, output.Normal, fraction);
                }
                return PressPlay.FFWD.RaycastHelper.rayCastCallback(fixture, point, output.Normal, fraction);
            }

            return input.MaxFraction;
        }
开发者ID:Joelone,项目名称:FFWD,代码行数:21,代码来源:World.cs

示例9: RayCastCallback

        private float RayCastCallback(ref RayCastInput input, int proxyid)
        {
            Actor actor = _tree.GetUserData(proxyid);

            RayCastOutput output;
            bool hit = actor.AABB.RayCast(out output, ref input);

            if (hit)
            {
                _rayCastOutput = output;
                _rayActor = actor;
                actor.Fraction = output.Fraction;
                return output.Fraction;
            }

            return input.MaxFraction;
        }
开发者ID:danielselnick,项目名称:Geometric-Replication,代码行数:17,代码来源:DynamicTreeTest.cs

示例10: rayCastCallbackWrapper

		float rayCastCallbackWrapper( RayCastInput rayCastInput, int proxyId )
		{
			var proxy = contactManager.broadPhase.getProxy( proxyId );
			var fixture = proxy.fixture;
			int index = proxy.childIndex;
			RayCastOutput output;
			bool hit = fixture.rayCast( out output, ref rayCastInput, index );

			if( hit )
			{
				var fraction = output.Fraction;
				var point = ( 1.0f - fraction ) * rayCastInput.Point1 + fraction * rayCastInput.Point2;
				return _rayCastCallback( fixture, point, output.Normal, fraction );
			}

			return rayCastInput.MaxFraction;
		}
开发者ID:prime31,项目名称:Nez,代码行数:17,代码来源:World.cs

示例11: rayCast

		/// <summary>
		/// Ray-cast the world for all fixtures in the path of the ray. Your callback
		/// controls whether you get the closest point, any point, or n-points.
		/// The ray-cast ignores shapes that contain the starting point.
		/// 
		/// Inside the callback:
		/// return -1: ignore this fixture and continue
		/// return 0: terminate the ray cast
		/// return fraction: clip the ray to this point
		/// return 1: don't clip the ray and continue
		/// </summary>
		/// <param name="callback">A user implemented callback class.</param>
		/// <param name="point1">The ray starting point.</param>
		/// <param name="point2">The ray ending point.</param>
		public void rayCast( Func<Fixture, Vector2, Vector2, float, float> callback, Vector2 point1, Vector2 point2 )
		{
			var input = new RayCastInput();
			input.MaxFraction = 1.0f;
			input.Point1 = point1;
			input.Point2 = point2;

			_rayCastCallback = callback;
			contactManager.broadPhase.rayCast( _rayCastCallbackWrapper, ref input );
			_rayCastCallback = null;
		}
开发者ID:prime31,项目名称:Nez,代码行数:25,代码来源:World.cs

示例12: Raycast

 internal static bool Raycast(Body body, Ray ray, out RaycastHit hitInfo, float distance)
 {
     RayCastOutput output;
     RayCastInput input = new RayCastInput() { Point1 = ray.origin, Point2 = ray.origin + ray.direction, MaxFraction = distance };
     hitInfo = new RaycastHit() { body = body };
     for (int i = 0; i < body.FixtureList.Count; i++)
     {
         if (body.FixtureList[i].RayCast(out output, ref input, 0))
         {
             hitInfo.collider = body.UserData;
             hitInfo.transform = body.UserData.transform;
             hitInfo.normal = VectorConverter.Convert(output.Normal, body.UserData.to2dMode);
             hitInfo.distance = output.Fraction;
             hitInfo.point = ray.GetPoint(output.Fraction);
             return true;
         }
     }
     return false;
 }
开发者ID:Elideb,项目名称:FFWD,代码行数:19,代码来源:Physics.cs

示例13: RayCast

 /// <summary>
 /// Cast a ray against this Shape.
 /// </summary>
 /// <param name="output">The ray-cast results.</param>
 /// <param name="input">The ray-cast input parameters.</param>
 /// <param name="childIndex">Index of the child.</param>
 /// <returns></returns>
 public bool RayCast(out RayCastOutput output, ref RayCastInput input, int childIndex)
 {
     Transform xf;
     Body.GetTransform(out xf);
     return Shape.RayCast(out output, ref input, ref xf, childIndex);
 }
开发者ID:HaKDMoDz,项目名称:Lunar-Development-Kit,代码行数:13,代码来源:Fixture.cs

示例14: RayCast

 public void RayCast(Func<RayCastInput, int, float> callback, ref RayCastInput input, Category categories)
 {
     for (int i = 0, categoryBits = (int)categories; categoryBits != 0; i++, categoryBits >>= 1)
         if ((categoryBits & 1) != 0)
             _quadTrees[i].RayCast(TransformRayCallback(callback), ref input);
 }
开发者ID:vvnurmi,项目名称:assaultwing,代码行数:6,代码来源:QuadTreeBroadPhase.cs


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