Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug draw? #8

Open
ntop001 opened this issue Jun 27, 2018 · 1 comment
Open

Debug draw? #8

ntop001 opened this issue Jun 27, 2018 · 1 comment

Comments

@ntop001
Copy link

ntop001 commented Jun 27, 2018

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

@ntop001
Copy link
Author

ntop001 commented Jul 3, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant