예제 #1
0
        /// Add a collision shape to the simulation.
        /// If the shape is attached to a static body, it will be added as a static shape.
        public cpShape AddShape(cpShape shape)
        {
            var body = shape.body;

            cp.AssertHard(shape.space != this, "You have already added this shape to this space. You must not add it a second time.");
            cp.AssertHard(shape.space == null, "You have already added this shape to another space. You cannot add it to a second.");
            cp.AssertSpaceUnlocked(this);

            bool isStatic = body.bodyType == cpBodyType.STATIC;

            if (!isStatic)
            {
                body.Activate();
            }

            body.AddShape(shape);

            shape.hashid = cp.shapeIDCounter++;

            shape.Update(body.transform);

            (isStatic ? this.staticShapes : this.dynamicShapes).Insert(shape.hashid, shape);
            shape.space = this;

            return(shape);
        }
예제 #2
0
        public bool ShapeQuery(cpShape shape, Action <cpShape, cpContactPointSet, object> func, object data)
        {
            cpBody            body    = shape.body;
            cpBB              bb      = (body != null ? shape.Update(body.transform) : shape.bb);
            ShapeQueryContext context = new ShapeQueryContext(func, data, false);

            object ctx = (object)context;

            Lock();
            {
                this.staticShapes.Query(shape, bb,
                                        (o1, o2, s, o3) => ShapeQueryFunc(o1 as cpShape, o2 as cpShape, s, (ShapeQueryContext)o3)
                                        , ctx);

                this.dynamicShapes.Query(shape, bb,
                                         (o1, o2, s, o3) => ShapeQueryFunc(o1 as cpShape, o2 as cpShape, s, (ShapeQueryContext)o3)
                                         , ctx);
            } Unlock(true);

            return(((ShapeQueryContext)ctx).anyCollision);
        }
예제 #3
0
        public bool ShapeQuery(cpShape shape, Action<cpShape, cpContactPointSet, object> func, object data)
        {
            cpBody body = shape.body;
            cpBB bb = (body != null ? shape.Update(body.transform) : shape.bb);
            ShapeQueryContext context = new ShapeQueryContext(func, data, false);

            object ctx = (object)context;

            Lock();
            {

                this.staticShapes.Query(shape, bb,
                    (o1, o2, s, o3) => ShapeQueryFunc(o1 as cpShape, o2 as cpShape, s, (ShapeQueryContext)o3)
                , ctx);

                this.dynamicShapes.Query(shape, bb,
                    (o1, o2, s, o3) => ShapeQueryFunc(o1 as cpShape, o2 as cpShape, s, (ShapeQueryContext)o3)
                , ctx);

            } Unlock(true);

            return ((ShapeQueryContext)ctx).anyCollision;
        }
예제 #4
0
파일: cpSpace.cs 프로젝트: kfazi/AgarIo
        /// Add a collision shape to the simulation.
        /// If the shape is attached to a static body, it will be added as a static shape.
        public cpShape AddShape(cpShape shape)
        {
            var body = shape.body;

            cp.AssertHard(shape.space != this, "You have already added this shape to this space. You must not add it a second time.");
            cp.AssertHard(shape.space == null, "You have already added this shape to another space. You cannot add it to a second.");
            cp.AssertSpaceUnlocked(this);

            bool isStatic = body.bodyType == cpBodyType.STATIC;
            if (!isStatic)
                body.Activate();

            body.AddShape(shape);

            shape.hashid = cp.shapeIDCounter++;

            shape.Update(body.transform);

            (isStatic ? this.staticShapes : this.dynamicShapes).Insert(shape.hashid, shape);
            shape.space = this;

            return shape;
        }