/// Does this aabb contain the provided AABB. public bool Contains(AABB aabb) { bool result = true; result = result && LowerBound.X <= aabb.LowerBound.X; result = result && LowerBound.Y <= aabb.LowerBound.Y; result = result && aabb.UpperBound.X <= UpperBound.X; result = result && aabb.UpperBound.Y <= UpperBound.Y; return result; }
public void DrawAABB(AABB aabb, ColorF c) { Gl.glColor3f(c.R, c.G, c.B); Gl.glBegin(Gl.GL_LINE_LOOP); Gl.glVertex2f(aabb.LowerBound.X, aabb.LowerBound.Y); Gl.glVertex2f(aabb.UpperBound.X, aabb.LowerBound.Y); Gl.glVertex2f(aabb.UpperBound.X, aabb.UpperBound.Y); Gl.glVertex2f(aabb.LowerBound.X, aabb.UpperBound.Y); Gl.glEnd(); }
public static bool TestOverlap(AABB a, AABB b) { var d1 = b.LowerBound - a.UpperBound; var d2 = a.LowerBound - b.UpperBound; if (d1.X > 0.0f || d1.Y > 0.0f) return false; if (d2.X > 0.0f || d2.Y > 0.0f) return false; return true; }
/// Combine two AABBs into this one. public void Combine(AABB aabb1, AABB aabb2) { LowerBound = Vec2.Min(aabb1.LowerBound, aabb2.LowerBound); UpperBound = Vec2.Min(aabb1.UpperBound, aabb2.UpperBound); }
public bool Overlaps(AABB b) { return TestOverlap(this, b); }
public virtual void Step() { float timeStep = TestSettings.hz > 0.0f ? 1.0f / TestSettings.hz : 0.0f; if (TestSettings.pause) { if (TestSettings.singleStep) { TestSettings.singleStep = false; } else { timeStep = 0.0f; } } DebugFlags flags = 0; if (TestSettings.drawShapes) flags |= DebugFlags.Shapes; if (TestSettings.drawJoints) flags |= DebugFlags.Joints; if (TestSettings.drawAABBs) flags |= DebugFlags.AABBs; if (TestSettings.drawPairs) flags |= DebugFlags.Pairs; if (TestSettings.drawCOMs) flags |= DebugFlags.CenterOfMasses; m_debugDraw.Flags = flags; m_world.WarmStarting = TestSettings.enableWarmStarting; m_world.ContinuousPhysics = TestSettings.enableContinuous; m_pointCount = 0; m_world.Step(timeStep, TestSettings.velocityIterations, TestSettings.positionIterations); //m_world.DrawDebugData(); if (timeStep > 0.0f) { ++m_stepCount; } // Make a small box. _selectedFixture = null; { AABB aabb = new AABB(); Vec2 d = new Vec2(0.001f, 0.001f); var p2 = Main.CursorPos; var p = Program.MainForm.ConvertScreenToWorld((int)p2.X, (int)p2.Y); aabb.LowerBound = p - d; aabb.UpperBound = p + d; m_world.QueryAABB( delegate(Fixture fixture) { Body body = fixture.Body; if (body.BodyType == BodyType.Dynamic) { bool inside = fixture.TestPoint(p); if (inside) { _selectedFixture = fixture; // We are done, terminate the query. return false; } } // Continue the query. return true; }, aabb); } }
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; } }
void PhysExplosion(Vec2 pos, float Radius, float Force) { AABB Sector = new AABB(); Sector.LowerBound = new Vec2(pos.X-Radius, pos.Y-Radius); Sector.UpperBound = new Vec2(pos.X+Radius, pos.Y+Radius); PhysExplosionCallback cb = new PhysExplosionCallback(); cb.Radius = Radius; cb.Force = Force; cb.pos = pos; m_world.QueryAABB(cb, Sector); }
public static extern void b2world_queryaabb(IntPtr world, IntPtr callback, AABB aabb);
public void QueryAABB(QueryCallbackDelegate callback, AABB aabb) { using (QueryCallbackDelegateWrapper wrapper = new QueryCallbackDelegateWrapper(callback)) QueryAABB(wrapper, aabb); }
public void QueryAABB(QueryCallback callback, AABB aabb) { NativeMethods.b2world_queryaabb(_worldPtr, callback.Listener, aabb); }