ByteArena / box2d

Box2D.go - Go port of Box2D - a 2D Physics Engine for Games.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Debug draw?

ntop001 opened this issue · comments

I see some code about debug draw, but they are commented out. Is there any preferred way to draw debug shapes?

For any one who has the same questions. I wrote some code to draw debug shape/joint/boundingbox:

// debug draw
func (b2 *B2System) DebugDraw() {
	w := b2.world
	if b2.debug.shape { // shape
		for b := w.GetBodyList(); b != nil; b = b.GetNext() {
			xf := b.GetTransform()
			for f := b.GetFixtureList(); f != nil; f = f.GetNext() {
				drawShape(f, xf)
			}
		}
	}

	if b2.debug.joint { // joint
		for j := w.GetJointList(); j != nil; j = j.GetNext() {
			drawJoint(j)
		}
	}

	if b2.debug.bounding { // bounding-box
		bp := &w.M_contactManager.M_broadPhase
		for b := w.GetBodyList(); b != nil; b = b.GetNext() {
			if !b.IsActive() {
				continue
			}
			for f := b.GetFixtureList(); f != nil; f = f.GetNext() {
				for i := 0; i < f.M_proxyCount; i++ {
					proxy := f.M_proxies[i]
					aabb := bp.GetFatAABB(proxy.ProxyId)
					vs := [4]box2d.B2Vec2{}
					vs[0] = box2d.B2Vec2{aabb.LowerBound.X, aabb.LowerBound.Y}
					vs[1] = box2d.B2Vec2{aabb.UpperBound.X, aabb.LowerBound.Y}
					vs[2] = box2d.B2Vec2{aabb.UpperBound.X, aabb.UpperBound.Y}
					vs[3] = box2d.B2Vec2{aabb.LowerBound.X, aabb.UpperBound.Y}
					drawPolygon(vs[:])
				}
			}
		}
	}
}

Here, you have to implement drawShapedrawJoint and drawPolygon method. In my engine , it's easy to use dbg system to implement these method.