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


C# World.TestPoint方法代码示例

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


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

示例1: Update

 public void Update(GameTime gameTime, CameraOperator cameraOperator, World world)
 {
     _sprite.Body.Center = Input.Mouse.Position;
     if (_mouseJoint != null)
     {
         if (Input.Mouse.IsButtonDown(Input.Mouse.MouseButton.Left))
         {
             _mouseJoint.WorldAnchorB = cameraOperator.Camera.PositionOnWorld(Input.Mouse.Position);
         }
         else
         {
             world.RemoveJoint(_mouseJoint);
             _mouseJoint = null;
         }
     }
     else
     {
         Vector2 cursorWorldPosition = cameraOperator.Camera.PositionOnWorld(Input.Mouse.Position);
         if (Input.Mouse.IsButtonClicked(Input.Mouse.MouseButton.Left))
         {
             Fixture fixture;
             float radiusMeters = _sprite.Body.Projection.BoundingBox.Dimensions.X.ToMeters();
             if ((fixture =
                 world.TestPoint(cursorWorldPosition - new Vector2(radiusMeters))) != null ||
                 (fixture =
                     world.TestPoint(cursorWorldPosition + new Vector2(radiusMeters))) != null ||
                 (fixture =
                     world.TestPoint(cursorWorldPosition + new Vector2(radiusMeters, -radiusMeters))) != null ||
                 (fixture =
                     world.TestPoint(cursorWorldPosition - new Vector2(radiusMeters, -radiusMeters))) != null)
             {
                 if (fixture.UserData is Coin)
                 {
                     _mouseJoint = new FixedMouseJoint(fixture.Body, cursorWorldPosition)
                     {
                         MaxForce = 200*fixture.Body.Mass
                     };
                     world.AddJoint(_mouseJoint);
                 }
             }
         }
     }
 }
开发者ID:victorMoneratto,项目名称:infinite-island,代码行数:43,代码来源:Cursor.cs

示例2: 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)
        {
            List<Fixture> fixtures = new List<Fixture>();
            List<Vector2> entryPoints = new List<Vector2>();
            List<Vector2> 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:Alexz18z35z,项目名称:Gibbo2D,代码行数:75,代码来源:CuttingTools.cs

示例3: MouseHoverEventProcessing

        public void MouseHoverEventProcessing(World world)
        {
            var selectedFixture = world.TestPoint(ConvertUnits.ToSimUnits(MouseVector2)) as Fixture;

            if (selectedFixture != null)
                if (OnMouseHover != null)
                {
                    selectedItemID = selectedFixture.Body.BodyId;
                    OnMouseHover(selectedItemID, mouseState);
                }
                else
                    selectedItemID = -1;
        }
开发者ID:zfogg,项目名称:Bounce,代码行数:13,代码来源:Input.cs

示例4: rayCast

        /// <summary>
        /// returns false if there are no CollisionCategorie 2 objects between startPosition and endPosition, else return true
        /// less accuracy is more accuracy ;)
        /// </summary>
        /// <param name="aPlayer"></param>
        /// <param name="world"></param>
        /// <returns></returns>
        private bool rayCast(Vector2 startPosition, Vector2 endPosition, int accuracy, World world)
        {
            Vector2 startRay = startPosition;
            Vector2 endRay = endPosition;
            Vector2 direction = new Vector2(endRay.X - startRay.X, endRay.Y - startRay.Y);
            direction.Normalize();

            while (new Vector2((int)startRay.X, (int)startRay.Y) != new Vector2((int)endRay.X, (int)endRay.Y))
            {
                startRay = startRay + direction * accuracy;

                Fixture fixture = world.TestPoint(ConvertUnits.ToSimUnits(startRay));

                if (fixture != null && fixture.CollisionCategories == Category.Cat2)
                {
                    return true;
                }
            }
            return false;
        }
开发者ID:settrbrg,项目名称:ethanolpunk,代码行数:27,代码来源:AI.cs


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