internal static Joint Create(JointDef def) { Joint result = null; switch (def.Type) { case JointType.RevoluteJoint: { result = new RevoluteJoint((RevoluteJointDef)def); break; } case JointType.PrismaticJoint: { result = new PrismaticJoint((PrismaticJointDef)def); break; } case JointType.DistanceJoint: { result = new DistanceJoint((DistanceJointDef)def); break; } case JointType.PulleyJoint: { result = new PulleyJoint((PulleyJointDef)def); break; } case JointType.MouseJoint: { result = new MouseJoint((MouseJointDef)def); break; } case JointType.GearJoint: { result = new GearJoint((GearJointDef)def); break; } case JointType.LineJoint: { result = new LineJoint((LineJointDef)def); break; } default: { Box2DXDebug.Assert(false); break; } } return(result); }
internal static Joint Create(JointDef def) { Joint joint = null; switch (def.Type) { case JointType.DistanceJoint: { joint = new DistanceJoint((DistanceJointDef)def); } break; case JointType.MouseJoint: { joint = new MouseJoint((MouseJointDef)def); } break; case JointType.PrismaticJoint: { joint = new PrismaticJoint((PrismaticJointDef)def); } break; case JointType.RevoluteJoint: { joint = new RevoluteJoint((RevoluteJointDef)def); } break; case JointType.PulleyJoint: { joint = new PulleyJoint((PulleyJointDef)def); } break; case JointType.GearJoint: { joint = new GearJoint((GearJointDef)def); } break; default: Box2DXDebug.Assert(false); break; } return(joint); }
internal static Joint Create(JointDef def) { Joint result = null; switch (def.Type) { case JointType.RevoluteJoint: { result = new RevoluteJoint((RevoluteJointDef)def); break; } case JointType.PrismaticJoint: { result = new PrismaticJoint((PrismaticJointDef)def); break; } case JointType.DistanceJoint: { result = new DistanceJoint((DistanceJointDef)def); break; } case JointType.PulleyJoint: { result = new PulleyJoint((PulleyJointDef)def); break; } case JointType.MouseJoint: { result = new MouseJoint((MouseJointDef)def); break; } case JointType.GearJoint: { result = new GearJoint((GearJointDef)def); break; } case JointType.LineJoint: { result = new LineJoint((LineJointDef)def); break; } default: { Box2DXDebug.Assert(false); break; } } return result; }
/// <summary> /// Mouse interaction event. /// </summary> public void MouseUp() { if (_mouseJoint != null) { _world.DestroyJoint(_mouseJoint); _mouseJoint = null; } }
/// <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(); } }
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(); } }
public Test() { _worldAABB = new AABB(); _worldAABB.LowerBound.Set(-200.0f, -100.0f); _worldAABB.UpperBound.Set(200.0f, 200.0f); Vec2 gravity = new Vec2(); gravity.Set(0.0f, -10.0f); bool doSleep = true; _world = new World(_worldAABB, gravity, doSleep); _bomb = null; _textLine = 30; _mouseJoint = null; _pointCount = 0; _destructionListener.test = this; _boundaryListener.test = this; //_contactListener.test = this; _world.SetDestructionListener(_destructionListener); _world.SetBoundaryListener(_boundaryListener); //_world.SetContactListener(_contactListener); _world.SetDebugDraw(_debugDraw); }
public void MouseUp(Vec2 p) { if (_mouseJoint != null) { _world.DestroyJoint(_mouseJoint); _mouseJoint = null; } if (_bombSpawning) { CompleteBombSpawn(p); } }
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(); } }
public Test() { Vec2 gravity = new Vec2(); gravity.Set(0.0f, -10.0f); bool doSleep = true; _world = new World(gravity, doSleep); _bomb = null; _textLine = 30; _mouseJoint = null; _pointCount = 0; _destructionListener.test = this; _world.SetDestructionListener(_destructionListener); _world.SetContactListener(this); _world.SetDebugDraw(_debugDraw); _bombSpawning = false; _stepCount = 0; BodyDef bodyDef = new BodyDef(); _groundBody = _world.CreateBody(bodyDef); }