예제 #1
0
파일: AABB.cs 프로젝트: Nomad1/sharpbox2d
        public static bool testOverlap(AABB a, AABB b)
        {
            if (b.lowerBound.x - a.upperBound.x > 0.0f || b.lowerBound.y - a.upperBound.y > 0.0f)
            {
                return false;
            }

            if (a.lowerBound.x - b.upperBound.x > 0.0f || a.lowerBound.y - b.upperBound.y > 0.0f)
            {
                return false;
            }

            return true;
        }
예제 #2
0
        /**
           * @see org.jbox2d.testbed.framework.TestbedTest#step(org.jbox2d.testbed.framework.TestbedSettings)
           */
        public override void step(TestbedSettings settings)
        {
            base.step(settings);

            PolyShapesCallback callback = new PolyShapesCallback(getWorld().getPool());
            callback.m_circle.m_radius = 2.0f;
            callback.m_circle.m_p.set(0.0f, 2.1f);
            callback.m_transform.setIdentity();
            callback.debugDraw = getDebugDraw();

            AABB aabb = new AABB();
            callback.m_circle.computeAABB(aabb, callback.m_transform, 0);

            getWorld().queryAABB(callback, aabb);

            Color4f color = new Color4f(0.4f, 0.7f, 0.8f);
            getDebugDraw().drawCircle(callback.m_circle.m_p, callback.m_circle.m_radius, color);

            addTextLine("Press 1-5 to drop stuff");
            addTextLine("Press 'a' to (de)activate some bodies");
            addTextLine("Press 'd' to destroy a body");
            addTextLine("Up to 30 bodies in the target circle are highlighted");
        }
예제 #3
0
파일: World.cs 프로젝트: Nomad1/sharpbox2d
 /**
    * Query the world for all particles that potentially overlap the provided AABB.
    *
    * @param particleCallback callback for particles.
    * @param aabb the query box.
    */
 public void queryAABB(ParticleQueryCallback particleCallback, AABB aabb)
 {
     m_particleSystem.queryAABB(particleCallback, aabb);
 }
예제 #4
0
파일: World.cs 프로젝트: Nomad1/sharpbox2d
 /**
    * Query the world for all fixtures and particles that potentially overlap the provided AABB.
    *
    * @param callback a user implemented callback class.
    * @param particleCallback callback for particles.
    * @param aabb the query box.
    */
 public void queryAABB(QueryCallback callback, ParticleQueryCallback particleCallback, AABB aabb)
 {
     wqwrapper.broadPhase = m_contactManager.m_broadPhase;
     wqwrapper.callback = callback;
     m_contactManager.m_broadPhase.query(wqwrapper, aabb);
     m_particleSystem.queryAABB(particleCallback, aabb);
 }
예제 #5
0
파일: World.cs 프로젝트: Nomad1/sharpbox2d
 /**
    * Query the world for all fixtures that potentially overlap the provided AABB.
    *
    * @param callback a user implemented callback class.
    * @param aabb the query box.
    */
 public void queryAABB(QueryCallback callback, AABB aabb)
 {
     wqwrapper.broadPhase = m_contactManager.m_broadPhase;
     wqwrapper.callback = callback;
     m_contactManager.m_broadPhase.query(wqwrapper, aabb);
 }
예제 #6
0
파일: AABB.cs 프로젝트: Nomad1/sharpbox2d
 /**
    * Sets this object from the given object
    *
    * @param aabb the object to copy from
    */
 public void set(AABB aabb)
 {
     Vec2 v = aabb.lowerBound;
     lowerBound.x = v.x;
     lowerBound.y = v.y;
     Vec2 v1 = aabb.upperBound;
     upperBound.x = v1.x;
     upperBound.y = v1.y;
 }
예제 #7
0
파일: AABB.cs 프로젝트: Nomad1/sharpbox2d
 /**
    * Copies from the given object
    *
    * @param copy the object to copy from
    */
 public AABB(AABB copy)
     : this(copy.lowerBound, copy.upperBound)
 {
 }
예제 #8
0
파일: AABB.cs 프로젝트: Nomad1/sharpbox2d
 /**
    * Combines another aabb with this one
    *
    * @param aabb
    */
 public void combine(AABB aabb)
 {
     lowerBound.x = lowerBound.x < aabb.lowerBound.x ? lowerBound.x : aabb.lowerBound.x;
     lowerBound.y = lowerBound.y < aabb.lowerBound.y ? lowerBound.y : aabb.lowerBound.y;
     upperBound.x = upperBound.x > aabb.upperBound.x ? upperBound.x : aabb.upperBound.x;
     upperBound.y = upperBound.y > aabb.upperBound.y ? upperBound.y : aabb.upperBound.y;
 }
예제 #9
0
파일: AABB.cs 프로젝트: Nomad1/sharpbox2d
 /**
    * Does this aabb contain the provided AABB.
    *
    * @return
    */
 public bool contains(AABB aabb)
 {
     /*
      * bool result = true; result = result && lowerBound.x <= aabb.lowerBound.x; result = result
      * && lowerBound.y <= aabb.lowerBound.y; result = result && aabb.upperBound.x <= upperBound.x;
      * result = result && aabb.upperBound.y <= upperBound.y; return result;
      */
     // djm: faster putting all of them together, as if one is false we leave the logic
     // early
     return lowerBound.x <= aabb.lowerBound.x && lowerBound.y <= aabb.lowerBound.y
            && aabb.upperBound.x <= upperBound.x && aabb.upperBound.y <= upperBound.y;
 }
예제 #10
0
파일: AABB.cs 프로젝트: Nomad1/sharpbox2d
 /**
    * Combine two AABBs into this one.
    *
    * @param aabb1
    * @param aab
    */
 public void combine(AABB aabb1, AABB aab)
 {
     lowerBound.x = aabb1.lowerBound.x < aab.lowerBound.x ? aabb1.lowerBound.x : aab.lowerBound.x;
     lowerBound.y = aabb1.lowerBound.y < aab.lowerBound.y ? aabb1.lowerBound.y : aab.lowerBound.y;
     upperBound.x = aabb1.upperBound.x > aab.upperBound.x ? aabb1.upperBound.x : aab.upperBound.x;
     upperBound.y = aabb1.upperBound.y > aab.upperBound.y ? aabb1.upperBound.y : aab.upperBound.y;
 }
예제 #11
0
        public void MoveProxy()
        {
            for (int i = 0; i < _e_actorCount; ++i)
            {
                int j = MathUtils.abs(_random.Next()%_e_actorCount);
                Actor actor = m_actors[j];
                if (actor.proxyId == -1)
                {
                    continue;
                }

                AABB aabb0 = new AABB(actor.aabb);
                MoveAABB(actor.aabb);
                Vec2 displacement = actor.aabb.getCenter().sub(aabb0.getCenter());
                m_tree.moveProxy(actor.proxyId, new AABB(actor.aabb), displacement);
                return;
            }
        }
예제 #12
0
        public void MoveAABB(AABB aabb)
        {
            Vec2 d = new Vec2();
            d.x = MathUtils.randomFloat(rand, -0.5f, 0.5f);
            d.y = MathUtils.randomFloat(rand, -0.5f, 0.5f);
            // d.x = 2.0f;
            // d.y = 0.0f;
            aabb.lowerBound.addLocal(d);
            aabb.upperBound.addLocal(d);
            aabb.lowerBound.add(aabb.upperBound);
            aabb.lowerBound.mulLocal(.5f);
            Vec2 c0 = aabb.lowerBound;
            Vec2 min = new Vec2();
            min.set(-worldExtent, 0.0f);
            Vec2 max = new Vec2();
            max.set(worldExtent, 2.0f*worldExtent);
            Vec2 c = MathUtils.clamp(c0, min, max);

            aabb.lowerBound.addLocal(c.sub(c0));
            aabb.upperBound.addLocal(c.sub(c0));
        }
예제 #13
0
        public override void initTest(bool argDeserialized)
        {
            worldExtent = 15.0f;
            m_proxyExtent = 0.5f;

            m_tree = new DynamicTree();

            for (int i = 0; i < _e_actorCount; ++i)
            {
                Actor actor = m_actors[i] = new Actor();
                GetRandomAABB(actor.aabb);
                actor.proxyId = m_tree.createProxy(actor.aabb, actor);
            }

            m_stepCount = 0;

            float h = worldExtent;
            m_queryAABB = new AABB();
            m_queryAABB.lowerBound.set(-3.0f, -4.0f + h);
            m_queryAABB.upperBound.set(5.0f, 6.0f + h);

            m_rayCastInput = new RayCastInput();
            m_rayCastInput.p1.set(-5.0f, 5.0f + h);
            m_rayCastInput.p2.set(7.0f, -4.0f + h);
            // m_rayCastInput.p1.set(0.0f, 2.0f + h);
            // m_rayCastInput.p2.set(0.0f, -2.0f + h);
            m_rayCastInput.maxFraction = 1.0f;

            m_rayCastOutput = new RayCastOutput();

            m_automated = false;
        }
예제 #14
0
 public void GetRandomAABB(AABB aabb)
 {
     Vec2 w = new Vec2();
     w.set(2.0f*m_proxyExtent, 2.0f*m_proxyExtent);
     // aabb.lowerBound.x = -m_proxyExtent;
     // aabb.lowerBound.y = -m_proxyExtent + worldExtent;
     aabb.lowerBound.x = MathUtils.randomFloat(rand, -worldExtent,
         worldExtent);
     aabb.lowerBound.y = MathUtils.randomFloat(rand, 0.0f,
         2.0f*worldExtent);
     aabb.upperBound.set(aabb.lowerBound);
     aabb.upperBound.addLocal(w);
 }