/** 开始拖动刚体*/ 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; }
// friend class b2Joint; // p = attached point, m = mouse point // C = p - m // Cdot = v // = v + cross(w, r) // J = [I r_skew] // Identity used: // w k % (rx i + ry j) = w * (-ry i + rx j) internal b2MouseJoint(b2MouseJointDef def) : base(def) { Debug.Assert(def.target.IsValid()); Debug.Assert(Utils.b2IsValid(def.maxForce) && def.maxForce >= 0.0f); Debug.Assert(Utils.b2IsValid(def.frequencyHz) && def.frequencyHz >= 0.0f); Debug.Assert(Utils.b2IsValid(def.dampingRatio) && def.dampingRatio >= 0.0f); m_targetA = def.target; m_localAnchorB = Utils.b2MulT(m_bodyB.GetTransform(), m_targetA); m_maxForce = def.maxForce; m_impulse.SetZero(); m_frequencyHz = def.frequencyHz; m_dampingRatio = def.dampingRatio; m_beta = 0.0f; m_gamma = 0.0f; }
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); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(b2MouseJointDef obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }