private void MouseLeftButtonDown(Vector2 position)
        {
            Vect mousePosition = MouseToSpace(position);

            // give the mouse click a little radius to make it easier to click small shapes.
            double radius = 5.0;

            PointQueryInfo info = space.PointQueryNearest(mousePosition, radius, GrabbableFilter);

            if (info == null)
            {
                return;
            }

            Shape shape = info.Shape;
            Body  body  = shape.Body;

            double mass = body.Mass;

            if (double.IsInfinity(mass))
            {
                return;
            }

            // Use the closest point on the surface if the click is outside of the shape.
            Vect nearest = info.Distance > 0.0 ? info.Point : mousePosition;

            cursorJoint           = new PivotJoint(cursorBody, body, Vect.Zero, body.WorldToLocal(nearest));
            cursorJoint.MaxForce  = 5000.0;
            cursorJoint.ErrorBias = Math.Pow(1.0 - 0.15, 60.0);

            space.AddConstraint(cursorJoint);

            demo[currentDemo].OnMouseLeftButtonDown(chipmunkDemoMouse);
        }
Ejemplo n.º 2
0
        public void PointQueryTest()
        {
            var body  = new Body(1, 1.66);
            var shape = new Box(body, 2, 2, 0);

            PointQueryInfo point = shape.PointQuery(new Vect(3, 4));

            Assert.AreEqual(-5, point.Distance, "#1");
            Assert.AreEqual(new Vect(0, 0), point.Point, "#2");
            Assert.AreSame(shape, point.Shape, "#3");
            Assert.AreEqual(-0.6, point.Gradient.X, 0.00000000001, "#4");
            Assert.AreEqual(-0.8, point.Gradient.Y, 0.00000000001, "#5");
        }
Ejemplo n.º 3
0
        public override void OnMouseRightButtonDown(Vect chipmunkDemoMouse)
        {
            PointQueryInfo info = space.PointQueryNearest(chipmunkDemoMouse, 0.0, ChipmunkDemoGame.GrabbableFilter);

            if (info == null || info.Shape == null)
            {
                return;
            }

            Body body = info.Shape.Body;

            if (body.Type == BodyType.Static)
            {
                body.Type   = BodyType.Dynamic;
                body.Mass   = pentagonMass;
                body.Moment = pentagonMoment;
            }
            else
            {
                body.Type = BodyType.Static;
            }
        }
Ejemplo n.º 4
0
        private void SliceQuery(Shape shape, Vect point, Vect normal, double alpha, SliceContext context)
        {
            Vect a = context.A;
            Vect b = context.B;

            // Check that the slice was complete by checking that the endpoints aren't in the sliced shape.
            PointQueryInfo infoA = shape.PointQuery(a);

            if (infoA == null || infoA.Distance <= 0.0)
            {
                return;
            }

            PointQueryInfo infoB = shape.PointQuery(b);

            if (infoB == null || infoB.Distance <= 0.0)
            {
                return;
            }

            // Can't modify the space during a query.
            // Must make a post-step callback to do the actual slicing.
            space.AddPostStepCallback(SliceShapePostStep, shape, context);
        }