コード例 #1
0
ファイル: sliceLayer.cs プロジェクト: foobit/ChipmunkSharp
        public void SliceShapePostStep(cpSpace space, cpShape shape, SliceContext context)
        {
            cpVect a = context.a;
            cpVect b = context.b;

            // Clipping plane normal and distance.
            cpVect n    = cpVect.cpvnormalize(cpVect.cpvperp(cpVect.cpvsub(b, a)));
            float  dist = cpVect.cpvdot(a, n);

            ClipPoly(space, shape, n, dist);
            ClipPoly(space, shape, cpVect.cpvneg(n), -dist);

            cpBody body = shape.GetBody();

            space.RemoveShape(shape);
            space.RemoveBody(body);
        }
コード例 #2
0
ファイル: Slice.cs プロジェクト: mistajuliax/ChipmunkBinding
        private void SliceObject(Vect from, Vect to)
        {
            var context = new SliceContext {
                A = from,
                B = to
            };

            SegmentQueryInfo[] infos = space.SegmentQuery(sliceStart, context.B, 0.0, ChipmunkDemoGame.GrabbableFilter).ToArray();

            if (infos.Length == 0)
            {
                return;
            }

            foreach (SegmentQueryInfo info in infos)
            {
                SliceQuery(info.Shape, info.Point, info.Normal, info.Alpha, context);
            }
        }
コード例 #3
0
ファイル: sliceLayer.cs プロジェクト: foobit/ChipmunkSharp
        public void SliceQuery(cpShape shape, float t, cpVect n, SliceContext context)
        {
            cpVect a = context.a;
            cpVect b = context.b;

            // Check that the slice was complete by checking that the endpoints aren't in the sliced shape.

            cpPointQueryInfo inf1 = null;
            cpPointQueryInfo inf2 = null;

            if (shape.PointQuery(a, ref inf1) > 0 && shape.PointQuery(b, ref inf2) > 0)
            {
                // Can't modify the space during a query.
                // Must make a post-step callback to do the actual slicing.
                context.space.AddPostStepCallback(
                    (s, o1, o2) => SliceShapePostStep(s, (cpShape)o1, (SliceContext)o2),
                    shape, context);
            }
        }
コード例 #4
0
ファイル: Slice.cs プロジェクト: mistajuliax/ChipmunkBinding
        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);
        }
コード例 #5
0
ファイル: sliceLayer.cs プロジェクト: foobit/ChipmunkSharp
        public override void Update(float dt)
        {
            base.Update(dt);

            space.Step(dt);


            bool lastClickState = false;

            sliceStart = cpVect.Zero;

            // Annoying state tracking code that you wouldn't need
            // in a real event driven system.
            if (CCMouse.Instance.rightclick != lastClickState)
            {
                if (CCMouse.Instance.rightclick)
                {
                    // MouseDown
                    sliceStart = CCMouse.Instance.Position;
                }
                else
                {
                    // MouseUp
                    SliceContext context = new SliceContext(sliceStart, CCMouse.Instance.Position, space);

                    space.SegmentQuery(sliceStart,
                                       CCMouse.Instance.Position, 0, GRAB_FILTER, (shape, v1, v2, d, o) =>
                                       SliceQuery(shape, d, v1, (SliceContext)o),
                                       context);
                }

                lastClickState = CCMouse.Instance.rightclick;
            }

            write = CCMouse.Instance.rightclick;
        }
コード例 #6
0
 public override object VisitSlice([NotNull] SliceContext context)
 {
     return((string)Visit(context.GetChild(0)));
 }