Beispiel #1
0
        public IBody CreateBody(Blob blob, float radius, float mass, bool isStatic)
        {
            lock (UpdateLock)
            {
                var body = isStatic ? cpBody.NewStatic() : cpBody.New(mass, float.PositiveInfinity);
                body.SetUserData(blob);

                var shape = new cpCircleShape(body, radius, cpVect.Zero);
                shape.SetCollisionType(GenerateCollisionType(blob.GetType()));

                lock (ShapesListLock)
                {
                    _shapesToAdd.Add(shape);
                }

                if (_space.IsLocked)
                {
                    _space.AddPostStepCallback(OnPostStep, null, null);
                }
                else
                {
                    AddShapes();
                }

                _reindexStatic |= isStatic;

                return(new ChipmunkBody(shape, isStatic));
            }
        }
Beispiel #2
0
        bool HookCrate(cpArbiter arb, cpSpace space, object data)
        {
            if (hookJoint == null)
            {
                // Get pointers to the two bodies in the collision pair and define local variables for them.
                // Their order matches the order of the collision types passed
                // to the collision handler this function was defined for
                cpBody hook  = arb.body_a;
                cpBody crate = arb.body_b;

                // additions and removals can't be done in a normal callback.
                // Schedule a post step callback to do it.
                // Use the hook as the key and pass along the arbiter.
                //cpSpaceAddPostStepCallback(space, (cpPostStepFunc)AttachHook, hook, crate);
                space.AddPostStepCallback((s, o1, o2) => AttachHook(o1 as cpBody, o2 as cpBody), hook, crate);
            }
            return(true); // return value is ignored for sensor callbacks anyway
        }