Пример #1
0
 public Wrapper(Body body)
 {
     this.body = body;
     this.node = new LinkedListNode2 <Wrapper>(this);
     xBegin    = new Stub(this, true);
     xEnd      = new Stub(this, false);
     yBegin    = new Stub(this, true);
     yEnd      = new Stub(this, false);
 }
Пример #2
0
        private void DetectInternal(TimeStep step, bool doX)
        {
            List <Stub>           stubs         = (doX) ? (xStubs) : (yStubs);
            LinkedList2 <Wrapper> currentBodies = new LinkedList2 <Wrapper>();

            for (int index = 0; index < stubs.Count; index++)
            {
                Stub    stub     = stubs[index];
                Wrapper wrapper1 = stub.wrapper;
                if (stub.begin)
                {
                    //set the min and max values
                    if (doX)
                    {
                        wrapper1.SetY();
                    }
                    else
                    {
                        wrapper1.SetX();
                    }

                    Body body1 = wrapper1.body;
                    for (LinkedListNode2 <Wrapper> node = currentBodies.First;
                         node != null;
                         node = node.Next)
                    {
                        Wrapper wrapper2 = node.Value;
                        Body    body2    = wrapper2.body;
                        if (wrapper1.min <= wrapper2.max && //tests the other axis
                            wrapper2.min <= wrapper1.max &&
                            Body.CanCollide(body1, body2))
                        {
                            OnCollision(step, body1, body2);
                        }
                    }
                    if (wrapper1.shouldAddNode)
                    {
                        currentBodies.AddLast(wrapper1.node);
                    }
                }
                else
                {
                    if (wrapper1.shouldAddNode)
                    {
                        currentBodies.Remove(wrapper1.node);
                    }
                }
            }
        }