/// <summary> /// Called to setup the arena boundaries and bind to all of the physics stuff. /// </summary> public virtual void Bind() { float width = dimensions.X, height = dimensions.Y; worldAABB = new AABB(); worldAABB.LowerBound.Set(-width / 2 - edgeTolerance, -edgeTolerance); worldAABB.UpperBound.Set(width / 2 + edgeTolerance, height + edgeTolerance); Vec2 gravity = new Vec2(this.gravity.X, this.gravity.Y); bool doSleep = true; world = new World(worldAABB, gravity, doSleep); world.SetContactFilter(new ContactFilter()); BodyDef groundBodyDef = new BodyDef(); groundBodyDef.Position.Set(0.0f, 0.0f); Body groundBody = world.CreateBody(groundBodyDef); // Bottom AddBoundaryBlock(groundBody, 0, -(boundaryThickness / 2), width + boundaryThickness * 2, boundaryThickness); // Top AddBoundaryBlock(groundBody, 0, height + boundaryThickness / 2, width + boundaryThickness * 2, boundaryThickness); // Left AddBoundaryBlock(groundBody, -(width / 2) - boundaryThickness / 2, height / 2, boundaryThickness, height + boundaryThickness * 2); // Right AddBoundaryBlock(groundBody, +(width / 2) + boundaryThickness / 2, height / 2, boundaryThickness, height + boundaryThickness * 2); DebugDraw draw = new OpenTKDebugDraw(); draw.Flags = DebugDraw.DrawFlags.Shape; if (Program.DebugDraw) { world.SetDebugDraw(draw); } world.SetContactListener(this); // Old code for reference /* * * _worldAABB = new AABB(); _worldAABB.LowerBound.Set(-30.0f, -20.0f); _worldAABB.UpperBound.Set(30.0f, 40.0f); Vec2 gravity = new Vec2(); gravity.Set(0.0f, -10.0f); bool doSleep = true; _world = new World(_worldAABB, gravity, doSleep); _world.SetContactFilter(new ContactFilter()); BodyDef groundBodyDef = new BodyDef(); groundBodyDef.Position.Set(0.0f, 0.0f); Body groundBody = _world.CreateBody(groundBodyDef); AddBlock(groundBody, 0, -5, 40, 10); AddBlock(groundBody, -20, 20, 1, 40); AddBlock(groundBody, 20, 20, 1, 40); AddBlock(groundBody, 0, 30, 40, 10); DebugDraw draw = new OpenTKDebugDraw(); draw.Flags = DebugDraw.DrawFlags.Shape; if (Program.DebugDraw) { _world.SetDebugDraw(draw); } _world.SetContactListener(this); */ }
/// <summary> /// Called to setup the arena boundaries and bind to all of the physics stuff. /// </summary> public virtual void Bind() { float width = dimensions.X, height = dimensions.Y; worldAABB = new AABB(); worldAABB.LowerBound.Set(-width / 2 - edgeTolerance, -edgeTolerance); worldAABB.UpperBound.Set(width / 2 + edgeTolerance, height + edgeTolerance); Vec2 gravity = new Vec2(this.gravity.X, this.gravity.Y); bool doSleep = true; world = new World(worldAABB, gravity, doSleep); world.SetContactFilter(new ContactFilter()); BodyDef groundBodyDef = new BodyDef(); groundBodyDef.Position.Set(0.0f, 0.0f); Body groundBody = world.CreateBody(groundBodyDef); // Bottom AddBoundaryBlock(groundBody, 0, -(boundaryThickness / 2), width + boundaryThickness * 2, boundaryThickness); // Top AddBoundaryBlock(groundBody, 0, height + boundaryThickness / 2, width + boundaryThickness * 2, boundaryThickness); // Left AddBoundaryBlock(groundBody, -(width / 2) - boundaryThickness / 2, height / 2, boundaryThickness, height + boundaryThickness * 2); // Right AddBoundaryBlock(groundBody, +(width / 2) + boundaryThickness / 2, height / 2, boundaryThickness, height + boundaryThickness * 2); DebugDraw draw = new OpenTKDebugDraw(); draw.Flags = DebugDraw.DrawFlags.Shape; if (Program.DebugDraw) { world.SetDebugDraw(draw); } world.SetContactListener(this); // Old code for reference /* * * * _worldAABB = new AABB(); * _worldAABB.LowerBound.Set(-30.0f, -20.0f); * _worldAABB.UpperBound.Set(30.0f, 40.0f); * Vec2 gravity = new Vec2(); * gravity.Set(0.0f, -10.0f); * bool doSleep = true; * _world = new World(_worldAABB, gravity, doSleep); * _world.SetContactFilter(new ContactFilter()); * * BodyDef groundBodyDef = new BodyDef(); * groundBodyDef.Position.Set(0.0f, 0.0f); * * Body groundBody = _world.CreateBody(groundBodyDef); * * AddBlock(groundBody, 0, -5, 40, 10); * AddBlock(groundBody, -20, 20, 1, 40); * AddBlock(groundBody, 20, 20, 1, 40); * AddBlock(groundBody, 0, 30, 40, 10); * * DebugDraw draw = new OpenTKDebugDraw(); * draw.Flags = DebugDraw.DrawFlags.Shape; * if (Program.DebugDraw) { * _world.SetDebugDraw(draw); * } * * _world.SetContactListener(this); */ }