Debug draw for box2d physics World

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Debug draw for box2d physics World

Post by Azhukar » Fri Mar 07, 2014 7:56 pm

tio wrote:And opening brackets at the same line as function definition :awesome:
Good thing that's the default for Lua.

User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Debug draw for box2d physics World

Post by Azhukar » Thu Nov 27, 2014 4:12 pm

Updated, now draws only on screen bodies and can draw from coordinates in world.

User avatar
nfey
Citizen
Posts: 63
Joined: Tue Feb 18, 2014 9:50 am
Location: Romania

Re: Debug draw for box2d physics World

Post by nfey » Wed Dec 03, 2014 9:12 pm

This is really helpful for debugging physics issues, I was thinking about writing something similar for my own use but found this first :) Thanks a lot.

I do have one observation to make: your math.randomseed(1) call will forever break random number generation in the project that is being debugged. Resetting the seed at the end of the function doesn't help either, because you'd need the system time in milliseconds, due to the frequent love.draw() calls (and os.time() apparently gives a value in seconds). On the other hand, I understand why you hardcoded the seed (in order to get the same "random" colors for the same fixtures for each screen redraw) and I couldn't think of a way to achieve the same effect and still obtain different colours for a larger number of fixtures.

User avatar
bartbes
Sex machine
Posts: 4942
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Debug draw for box2d physics World

Post by bartbes » Wed Dec 03, 2014 10:49 pm

Use love.math's RandomGenerator objects?

User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Debug draw for box2d physics World

Post by Azhukar » Wed Dec 03, 2014 11:36 pm

Updated to fix a few issues.

User avatar
nfey
Citizen
Posts: 63
Joined: Tue Feb 18, 2014 9:50 am
Location: Romania

Re: Debug draw for box2d physics World

Post by nfey » Sat Dec 06, 2014 2:36 pm

Thanks for the update, random generation works properly now.

edbucks
Prole
Posts: 1
Joined: Fri Jun 17, 2016 2:54 pm

Re: Debug draw for box2d physics World

Post by edbucks » Fri Jun 17, 2016 2:57 pm

Thank you so much for this script. For the latest version I changed

Code: Select all

love.graphics.point
to

Code: Select all

love.graphics.points
and all was well.

The_JinJ
Prole
Posts: 8
Joined: Fri Jul 22, 2016 12:43 am

Re: Debug draw for box2d physics World

Post by The_JinJ » Thu Jul 28, 2016 9:51 pm

Very handy! Thanks :)

girng
Prole
Posts: 39
Joined: Fri Sep 07, 2018 5:42 am

Re: Debug draw for box2d physics World

Post by girng » Thu Sep 13, 2018 4:05 am

not sure what to do with the "(world,x,y,width,height)" part.

where are u getting x, y, width and height from?

i'm looking for a tool just to draw the shapes on all my bodies in my tilemap. hmm

ok i just put 0,0,0,0

screen turns red

after i create some shapes, i eventually get

Code: Select all

Error

addons/debugWorldDraw.lua:93: attempt to call field 'point' (a nil value)


Traceback

addons/debugWorldDraw.lua:93: in function 'debugWorldDraw'
main.lua:253: in function 'draw'
[C]: in function 'xpcall'
gtx 950, latest lua 11.1

ok, nevermind. found this snippet here:
https://love2d.org/wiki/Tutorial:PhysicsDrawing

at the very bottom. works great!

User avatar
pgimeno
Party member
Posts: 1232
Joined: Sun Oct 18, 2015 2:58 pm

Re: Debug draw for box2d physics World

Post by pgimeno » Thu Sep 13, 2018 9:27 am

I use this library fairly often. I've updated it to work with versions up to 11.1. Since the author doesn't seem to frequent these forums any longer, I'll post my updated version, but all credit goes to Azhukar.

Changes are:

- All setColor calls have been made cross-version compatible.
- point() has been replaced with rectangle(). The rectangles are 3x3 pixels. setPointSize calls have been removed
- The calls deprecated in 11.1 are not called if the new calls are found.
- The "eye" of the circles has been commented out.
- The library no longer alters the global state (colour, line width, point size).

As for girng's question: you pass it the top left corner's position x and y, and the width and height, of the area to draw, in physics units. The idea is to not even consider any object that is outside that area, as they don't need to be painted. If your units match pixels, and you're using the entire screen, you just use 0, 0, love.graphics.getWidth(), love.graphics.getHeight().
Attachments
debugWorldDraw_11.lua
(2.82 KiB) Downloaded 2 times
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories
The Microsoft Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests