Exemplo n.º 1
0
        public virtual void MouseUp(Vec2 p)
        {
            if (m_mouseJoint != null)
            {
                m_world.DestroyJoint(m_mouseJoint);
                m_mouseJoint = null;
            }

            if (m_bombSpawning)
                CompleteBombSpawn(p);
        }
Exemplo n.º 2
0
        public Test()
        {
            Vec2 gravity;
            gravity = new Vec2(0.0f, -10.0f);
            bool doSleep = true;
            m_world = new World(gravity, doSleep);
            m_bomb = null;
            m_textLine = 30;
            m_mouseJoint = null;
            m_pointCount = 0;

            m_destructionListener.test = this;
            m_world.DestructionListener = m_destructionListener;
            m_world.ContactListener = this;
            m_world.DebugDraw = m_debugDraw;

            m_bombSpawning = false;

            m_stepCount = 0;

            BodyDef bodyDef = new BodyDef();
            m_groundBody = m_world.CreateBody(bodyDef);
            m_groundBody.UserData = "Ground";
        }
Exemplo n.º 3
0
        public virtual void MouseDown(Vec2 p)
        {
            m_mouseWorld = p;

            if (m_mouseJoint != null)
                return;

            // Make a small box.
            AABB aabb = new AABB();
            Vec2 d = new Vec2(0.001f, 0.001f);
            aabb.LowerBound = p - d;
            aabb.UpperBound = p + d;

            // Query the world for overlapping shapes.
            Fixture m_fixture = null;

            m_world.QueryAABB(
            delegate(Fixture fixture)
            {
                Body body = fixture.Body;
                if (body.BodyType == BodyType.Dynamic)
                {
                    bool inside = fixture.TestPoint(p);
                    if (inside)
                    {
                        m_fixture = fixture;

                        // We are done, terminate the query.
                        return false;
                    }
                }

                // Continue the query.
                return true;
            },
            aabb);

            if (m_fixture != null)
            {
                Body body = m_fixture.Body;
                MouseJointDef md = new MouseJointDef();
                {
                    md.BodyA = m_groundBody;
                    md.BodyB = body;
                    md.Target = p;
                    md.MaxForce = 1000.0f * body.Mass;
                    m_mouseJoint = (MouseJoint)m_world.CreateJoint(md);
                }
                body.IsAwake = true;
            }
        }