Beispiel #1
0
        public cpShape PointQueryNearest(cpVect point, float maxDistance, cpShapeFilter filter, ref cpPointQueryInfo output)
        {
            cpPointQueryInfo info = new cpPointQueryInfo(null, cpVect.Zero, maxDistance, cpVect.Zero);

            if (output == null)
            {
                output = info;
            }

            PointQueryContext context = new PointQueryContext(
                point, maxDistance,
                filter,
                null
                );

            cpBB bb = cpBB.cpBBNewForCircle(point, cp.cpfmax(maxDistance, 0.0f));

            object outp = (object)output;

            this.dynamicShapes.Query(context, bb,
                                     (o1, o2, s, o3) => NearestPointQueryNearest(o1, (cpShape)o2, s, ref outp)
                                     , null);

            this.staticShapes.Query(context, bb,
                                    (o1, o2, s, o3) => NearestPointQueryNearest(o1, (cpShape)o2, s, ref outp)
                                    , null);

            output = (cpPointQueryInfo)outp;

            return(output.shape);
        }
Beispiel #2
0
        public void PointQuery(cpVect point, float maxDistance, cpShapeFilter filter, cpSpacePointQueryFunc func, object data)
        {
            PointQueryContext context = new PointQueryContext(point, maxDistance, filter, func);
            cpBB bb = cpBB.cpBBNewForCircle(point, cp.cpfmax(maxDistance, 0.0f));

            Lock();
            {
                this.staticShapes.Query(context, bb, (ctx, shape, colid, o) => NearestPointQuery((PointQueryContext)ctx, shape as cpShape, colid, o), data);
                this.dynamicShapes.Query(context, bb, (ctx, shape, colid, o) => NearestPointQuery((PointQueryContext)ctx, shape as cpShape, colid, o), data);
            } Unlock(true);
        }
Beispiel #3
0
        public ulong NearestPointQuery(PointQueryContext context, cpShape shape, ulong id, object data)
        {
            if (
                !cpShapeFilter.Reject(shape.filter, context.filter)
                )
            {
                cpPointQueryInfo info = null;
                shape.PointQuery(context.point, ref info);

                if (info.shape != null && info.distance < context.maxDistance)
                {
                    context.func(shape, info.point, info.distance, info.gradient, data);
                }
            }
            return(id);
        }
Beispiel #4
0
        public ulong NearestPointQueryNearest(object ctx, cpShape shape, ulong id, ref object outp)
        {
            PointQueryContext context = (PointQueryContext)ctx;
            cpPointQueryInfo  output  = (cpPointQueryInfo)outp;

            if (
                !cpShapeFilter.Reject(shape.filter, context.filter) && !shape.sensor
                )
            {
                cpPointQueryInfo info = null;
                shape.PointQuery(context.point, ref info);

                if (info.distance < output.distance)
                {
                    outp = (object)info;
                }
            }

            return(id);
        }