Mouse joint definition. This requires a world target point, tuning parameters, and the time step.
Inheritance: JointDef
Exemple #1
0
        public MouseJoint(MouseJointDef def)
            : base(def)
        {
            _target      = def.Target;
            _localAnchor = Common.Math.MulT(_body2.GetXForm(), _target);

            _maxForce = Settings.FORCE_INV_SCALE(def.MaxForce);
            _impulse.SetZero();

            float mass = _body2._mass;

            // Frequency
            float omega = 2.0f * Settings.Pi * def.FrequencyHz;

            // Damping coefficient
            float d = 2.0f * mass * def.DampingRatio * omega;

            // Spring stiffness
            float k = (def.TimeStep * mass) * (omega * omega);

            // magic formulas
            Box2DXDebug.Assert(d + k > Settings.FLT_EPSILON);
            _gamma = 1.0f / (d + k);
            _beta  = k / (d + k);
        }
Exemple #2
0
 public MouseJoint(MouseJointDef def) : base(def)
 {
     this._target      = def.Target;
     this._localAnchor = Box2DX.Common.Math.MulT(this._body2.GetXForm(), this._target);
     this._maxForce    = def.MaxForce;
     this._impulse.SetZero();
     this._frequencyHz  = def.FrequencyHz;
     this._dampingRatio = def.DampingRatio;
     this._beta         = 0f;
     this._gamma        = 0f;
 }
Exemple #3
0
 public MouseJoint(MouseJointDef def)
     : base(def)
 {
     this._target = def.Target;
     this._localAnchor = Box2DX.Common.Math.MulT(this._body2.GetXForm(), this._target);
     this._maxForce = def.MaxForce;
     this._impulse.SetZero();
     this._frequencyHz = def.FrequencyHz;
     this._dampingRatio = def.DampingRatio;
     this._beta = 0f;
     this._gamma = 0f;
 }
        public MouseJoint(MouseJointDef def)
            : base(def)
        {
            _target = def.Target;
            _localAnchor = _body2.GetTransform().InverseTransformPoint(_target);

            _maxForce = def.MaxForce;
            _impulse = Vector2.zero;

            _frequencyHz = def.FrequencyHz;
            _dampingRatio = def.DampingRatio;

            _beta = 0.0f;
            _gamma = 0.0f;
        }
Exemple #5
0
        public MouseJoint(MouseJointDef def)
            : base(def)
        {
            _target      = def.Target;
            _localAnchor = Math.MulT(_bodyB.GetTransform(), _target);

            _maxForce = def.MaxForce;
            _impulse.SetZero();

            _frequencyHz  = def.FrequencyHz;
            _dampingRatio = def.DampingRatio;

            _beta  = 0.0f;
            _gamma = 0.0f;
        }
        public MouseJoint(MouseJointDef def)
            : base(def)
        {
            _target = def.Target;
            _localAnchor = Common.Math.MulT(_body2.GetXForm(), _target);

            _maxForce = def.MaxForce;
            _impulse.SetZero();

            _frequencyHz = def.FrequencyHz;
            _dampingRatio = def.DampingRatio;

            _beta = 0.0f;
            _gamma = 0.0f;
        }
        public MouseJoint(MouseJointDef def)
            : base(def)
        {
            _target      = def.Target;
            _localAnchor = _body2.GetTransform().InverseTransformPoint(_target);

            _maxForce = def.MaxForce;
            _impulse  = Vector2.Zero;

            _frequencyHz  = def.FrequencyHz;
            _dampingRatio = def.DampingRatio;

            _beta  = 0.0f;
            _gamma = 0.0f;
        }
        /// <summary>
        /// Mouse interaction event.
        /// </summary>
		public void MouseDown(Vec2 p)
		{
			if (_mouseJoint != null)
			{
				return;
			}

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

			// Query the world for overlapping shapes.
			int k_maxCount = 10;
			Shape[] shapes = new Shape[k_maxCount];
			int count = _world.Query(aabb, shapes, k_maxCount);
			Body body = null;
			for (int i = 0; i < count; ++i)
			{
				Body shapeBody = shapes[i].GetBody();
				if (shapeBody.IsStatic() == false && shapeBody.GetMass() > 0.0f)
				{
					bool inside = shapes[i].TestPoint(shapeBody.GetXForm(), p);
					if (inside)
					{
						body = shapes[i].GetBody();
						break;
					}
				}
			}

			if (body != null)
			{
				MouseJointDef md = new MouseJointDef();
				md.Body1 = _world.GetGroundBody();
				md.Body2 = body;
				md.Target = p;
                md.MaxForce = 1000.0f * body.GetMass();
                md.FrequencyHz = 30f;
				_mouseJoint = (MouseJoint)_world.CreateJoint(md);
				body.WakeUp();
			}
		}
Exemple #9
0
		public void MouseDown(Vec2 p)
		{
			if (_mouseJoint != null)
			{
				return;
			}

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

			// Query the world for overlapping shapes.
			int k_maxCount = 10;
			Fixture[] shapes = new Fixture[k_maxCount];
			int count = _world.Query(aabb, shapes, k_maxCount);
			Body body = null;
			for (int i = 0; i < count; ++i)
			{
				Body shapeBody = shapes[i].Body;
				if (shapeBody.IsStatic() == false && shapeBody.GetMass() > 0.0f)
				{
					bool inside = shapes[i].TestPoint(p);
					if (inside)
					{
						body = shapes[i].Body;
						break;
					}
				}
			}

			if (body != null)
			{
				MouseJointDef md = new MouseJointDef();
				md.Body1 = _world.GetGroundBody();
				md.Body2 = body;
				md.Target = p;
#if TARGET_FLOAT32_IS_FIXED
				md.MaxForce = (body.GetMass() < 16.0f)? 
					(1000.0f * body.GetMass()) : 16000.0f;
#else
				md.MaxForce = 1000.0f * body.GetMass();
#endif
				_mouseJoint = (MouseJoint)_world.CreateJoint(md);
				body.WakeUp();
			}
		}
Exemple #10
0
 private void Events_MouseButtonDown(object sender, MouseButtonEventArgs e)
 {
     foreach (var worldObject in worldObjects)
     {
         var vec3 = Helper.Foo(e.X, e.Y);
         if (worldObject.HitTest(vec3.X, vec3.Y))
         {
             MouseJointDef mouseJointDef = new MouseJointDef();
             mouseJointDef.Body1 = ((Box)worldObject).Body;
             this.mouseJoint = this.world.CreateJoint(mouseJointDef);
         }
     }
 }
Exemple #11
0
        public void MouseDown(Vec2 p)
        {
            _mouseWorld = p;

            if (_mouseJoint != null)
            {
                return;
            }

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

            // Query the world for overlapping shapes.
            MyQueryCallback callback = new MyQueryCallback(p);
            _world.QueryAABB(callback, aabb);

            if (callback._fixture != null)
            {
                Body body = callback._fixture.GetBody();
                MouseJointDef md = new MouseJointDef();
                md.Body1 = _groundBody;
                md.Body2 = body;
                md.Target = p;
            #if TARGET_FLOAT32_IS_FIXED
                md.maxForce = (body->GetMass() < 16.0)? (1000.0f * body->GetMass()) : float32(16000.0);
            #else
                md.MaxForce = 1000.0f * body.GetMass();
            #endif
                _mouseJoint = (MouseJoint)_world.CreateJoint(md);
                body.WakeUp();
            }
        }
Exemple #12
0
		public MouseJoint(MouseJointDef def)
			: base(def)
		{
			_target = def.Target;
			_localAnchor = Common.Math.MulT(_body2.GetXForm(), _target);

			_maxForce = Settings.FORCE_INV_SCALE(def.MaxForce);
			_impulse.SetZero();

			float mass = _body2._mass;

			// Frequency
			float omega = 2.0f * Settings.Pi * def.FrequencyHz;

			// Damping coefficient
			float d = 2.0f * mass * def.DampingRatio * omega;

			// Spring stiffness
			float k = (def.TimeStep * mass) * (omega * omega);

			// magic formulas
			Box2DXDebug.Assert(d + k > Settings.FLT_EPSILON);
			_gamma = 1.0f / (d + k);
			_beta = k / (d + k);
		}