Exemplo n.º 1
0
        public Test()
        {
            m_destructionListener = new DestructionListener();
            m_debugDraw           = new CCBox2dDraw("fonts/arial-12");

            b2Vec2 gravity = new b2Vec2();

            gravity.Set(0.0f, -10.0f);
            m_world      = new b2World(gravity);
            m_bomb       = null;
            m_textLine   = 30;
            m_mouseJoint = null;
            m_pointCount = 0;

            m_destructionListener.test = this;
            m_world.SetDestructionListener(m_destructionListener);
            m_world.SetContactListener(this);
            m_world.SetDebugDraw(m_debugDraw);
            m_world.SetContinuousPhysics(true);
            m_world.SetWarmStarting(true);

            m_bombSpawning = false;

            m_stepCount = 0;

            b2BodyDef bodyDef = new b2BodyDef();

            m_groundBody = m_world.CreateBody(bodyDef);
        }
Exemplo n.º 2
0
 void OnDestroy()
 {
     if (_mj != null)
     {
         _world.DestroyJoint(_mj);
     }
     _mj = null;
 }
Exemplo n.º 3
0
        public virtual void MouseUp(b2Vec2 p)
        {
            if (m_mouseJoint != null)
            {
                m_world.DestroyJoint(m_mouseJoint);
                m_mouseJoint = null;
            }

            if (m_bombSpawning)
            {
                CompleteBombSpawn(p);
            }
        }
Exemplo n.º 4
0
        /** 开始拖动刚体*/
        private void startDragBody(b2Body b, float x, float y)
        {
            if (b == null || b.GetType() != b2Body.b2_dynamicBody)
            {
                return;
            }
            if (_mj != null)
            {
                _world.DestroyJoint(_mj);
            }
            b2MouseJointDef jointDef = new b2MouseJointDef();

            jointDef.bodyA = _world.GetGroundBody();
            jointDef.bodyB = b;
            jointDef.target.Set(x, y);
            jointDef.maxForce = 1e6f;
            _mj = _world.CreateJoint(jointDef) as b2MouseJoint;
        }
Exemplo n.º 5
0
        public virtual bool MouseDown(b2Vec2 p)
        {
            m_mouseWorld = p;

            if (m_mouseJoint != null)
            {
                return(false);
            }

            // Make a small box.
            b2AABB aabb = new b2AABB();
            b2Vec2 d    = new b2Vec2();

            d.Set(0.001f, 0.001f);
            aabb.LowerBound = p - d;
            aabb.UpperBound = p + d;

            // Query the world for overlapping shapes.
            QueryCallback callback = new QueryCallback(p);

            m_world.QueryAABB(callback, aabb);

            if (callback.m_fixture != null)
            {
                b2Body          body = callback.m_fixture.Body;
                b2MouseJointDef md   = new b2MouseJointDef();
                md.BodyA     = m_groundBody;
                md.BodyB     = body;
                md.target    = p;
                md.maxForce  = 1000.0f * body.Mass;
                m_mouseJoint = (b2MouseJoint)m_world.CreateJoint(md);
                body.SetAwake(true);
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
    internal static b2Joint Create(b2JointDef def)
    {
        b2Joint joint = null;

        switch (def.type)
        {
        case b2JointType.e_distanceJoint:
        {
            joint = new b2DistanceJoint((b2DistanceJointDef)def);
        }
        break;

        case b2JointType.e_mouseJoint:
        {
            joint = new b2MouseJoint((b2MouseJointDef)def);
        }
        break;

        case b2JointType.e_prismaticJoint:
        {
            joint = new b2PrismaticJoint((b2PrismaticJointDef)def);
        }
        break;

        case b2JointType.e_revoluteJoint:
        {
            joint = new b2RevoluteJoint((b2RevoluteJointDef)def);
        }
        break;

        case b2JointType.e_pulleyJoint:
        {
            joint = new b2PulleyJoint((b2PulleyJointDef)def);
        }
        break;

        case b2JointType.e_gearJoint:
        {
            joint = new b2GearJoint((b2GearJointDef)def);
        }
        break;

        case b2JointType.e_wheelJoint:
        {
            joint = new b2WheelJoint((b2WheelJointDef)def);
        }
        break;

        case b2JointType.e_weldJoint:
        {
            joint = new b2WeldJoint((b2WeldJointDef)def);
        }
        break;

        case b2JointType.e_frictionJoint:
        {
            joint = new b2FrictionJoint((b2FrictionJointDef)def);
        }
        break;

        case b2JointType.e_ropeJoint:
        {
            joint = new b2RopeJoint((b2RopeJointDef)def);
        }
        break;

        case b2JointType.e_motorJoint:
        {
            joint = new b2MotorJoint((b2MotorJointDef)def);
        }
        break;

        default:
            Debug.Assert(false);
            break;
        }

        return(joint);
    }
Exemplo n.º 7
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(b2MouseJoint obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }