예제 #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);
        }
예제 #2
0
        //public static cpShapeFilter FILTER_ALL = new cpShapeFilter(cp.NO_GROUP, (int)cpShapeFilterMask.All, (int)cpShapeFilterMask.All);
        //public static cpShapeFilter FILTER_NONE = new cpShapeFilter(cp.NO_GROUP, (int)cpShapeFilterMask.None, (int)cpShapeFilterMask.None);


        public cpShape(cpBody body, cpShapeMassInfo massInfo)
        {
            /// The rigid body this collision shape is attached to.
            this.body = body;

            this.massInfo = massInfo;

            /// The current bounding box of the shape.
            /// The current bounding box of the shape.
            ///
            //this.bb_l = this.bb_b = this.bb_r = this.bb_t = 0;
            this.bb = new cpBB(0, 0, 0, 0);

            //this.hashid = (cp.shapeIDCounter++).ToString();

            /// Sensor flag.
            /// Sensor shapes call collision callbacks but don't produce collisions.
            this.sensor = false;

            filter = new cpShapeFilter(cp.NO_GROUP, (int)cpShapeFilterMask.Default, (int)cpShapeFilterMask.Default);


            /// Coefficient of restitution. (elasticity)
            this.e = 0;
            /// Coefficient of friction.
            this.u = 0;
            /// Surface velocity used when solving for friction.
            this.surfaceV = cpVect.Zero;

            /// Collision type of this shape used when picking collision handlers.
            this.type = 0;

            this.space = null;
        }
예제 #3
0
 public BBQueryContext(cpBB bb1, cpShapeFilter filter1, cpSpaceBBQueryFunc func1)
 {
     // TODO: Complete member initialization
     this.bb     = bb1;
     this.filter = filter1;
     this.func   = func1;
 }
예제 #4
0
        public cpShape SegmentQueryFirst(cpVect start, cpVect end, float radius, cpShapeFilter filter, ref cpSegmentQueryInfo output)
        {
            cpSegmentQueryInfo info = new cpSegmentQueryInfo(null, end, cpVect.Zero, 1.0f);

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

            SegmentQueryContext context = new SegmentQueryContext(
                start, end,
                radius,
                filter,
                null);

            this.staticShapes.SegmentQuery(context, start, end, 1.0f,
                                           (o1, o2, o3) => SegmentQueryFirstFunc((SegmentQueryContext)o1, o2 as cpShape, (cpSegmentQueryInfo)o3)
                                           , output);
            //		this.dynamicShapes.SegmentQuery(context, start, end, output.alpha , SegmentQueryFirst, ref output);
            this.dynamicShapes.SegmentQuery(context, start, end, output.alpha,
                                            (o1, o2, o3) => SegmentQueryFirstFunc((SegmentQueryContext)o1, o2 as cpShape, (cpSegmentQueryInfo)o3)
                                            , output);

            return(output.shape);
        }
예제 #5
0
 public PointQueryContext(cpVect point1, float maxDistance1, cpShapeFilter filter1, cpSpacePointQueryFunc func1)
 {
     // TODO: Complete member initialization
     this.point       = point1;
     this.maxDistance = maxDistance1;
     this.filter      = filter1;
     this.func        = func1;
 }
예제 #6
0
 public SegmentQueryContext(cpVect start1, cpVect end1, float radius1, cpShapeFilter filter1, cpSpacePointQueryFunc func1)
 {
     // TODO: Complete member initialization
     this.start  = start1;
     this.end    = end1;
     this.radius = radius1;
     this.filter = filter1;
     this.func   = func1;
 }
예제 #7
0
 public static bool Reject(cpShapeFilter a, cpShapeFilter b)
 {
     // Reject the collision if:
     return(
         // They are in the same non-zero group.
         (a.group != 0 && a.group == b.group) ||
         // One of the category/mask combinations fails.
         (a.categories & b.mask) == 0 ||
         (b.categories & a.mask) == 0
         );
 }
예제 #8
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);
        }
예제 #9
0
        public void BBQuery(cpBB bb, cpShapeFilter filter, cpSpaceBBQueryFunc func, object data)
        {
            BBQueryContext context = new BBQueryContext(bb, filter, func);

            Lock();
            {
                this.staticShapes.Query(context, bb, (o1, o2, s, o3) =>

                                        BBQueryFunc((BBQueryContext)o1, o2 as cpShape, s, o3)
                                        , data);

                this.dynamicShapes.Query(context, bb, (o1, o2, s, o3) =>

                                         BBQueryFunc((BBQueryContext)o1, o2 as cpShape, s, o3)
                                         , data);
            } Unlock(true);
        }
예제 #10
0
        public void SegmentQuery(cpVect start, cpVect end, float radius, cpShapeFilter filter, cpSpacePointQueryFunc func, object data)
        {
            SegmentQueryContext context = new SegmentQueryContext(
                start, end,
                radius,
                filter,
                func
                );

            Lock();
            {
                this.staticShapes.SegmentQuery(context, start, end, 1.0f,
                                               (o1, o2, o3) => SegmentQueryFunc((SegmentQueryContext)o1, o2 as cpShape, o3)
                                               , data);
                this.dynamicShapes.SegmentQuery(context, start, end, 1.0f,
                                                (o1, o2, o3) => SegmentQueryFunc((SegmentQueryContext)o1, o2 as cpShape, o3)
                                                , data);
            } Unlock(true);
        }
예제 #11
0
 public bool Reject(cpShapeFilter b)
 {
     return(Reject(this, b));
 }
예제 #12
0
 public void SetFilter(cpShapeFilter filter)
 {
     body.Activate();
     this.filter = filter;
 }