Page 3 of 4

Re: Debug draw for box2d physics World

Posted: Fri Mar 07, 2014 7:56 pm
by Azhukar
tio wrote:And opening brackets at the same line as function definition :awesome:
Good thing that's the default for Lua.

Re: Debug draw for box2d physics World

Posted: Thu Nov 27, 2014 4:12 pm
by Azhukar
Updated, now draws only on screen bodies and can draw from coordinates in world.

Re: Debug draw for box2d physics World

Posted: Wed Dec 03, 2014 9:12 pm
by nfey
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.

Re: Debug draw for box2d physics World

Posted: Wed Dec 03, 2014 10:49 pm
by bartbes
Use love.math's RandomGenerator objects?

Re: Debug draw for box2d physics World

Posted: Wed Dec 03, 2014 11:36 pm
by Azhukar
Updated to fix a few issues.

Re: Debug draw for box2d physics World

Posted: Sat Dec 06, 2014 2:36 pm
by nfey
Thanks for the update, random generation works properly now.

Re: Debug draw for box2d physics World

Posted: Fri Jun 17, 2016 2:57 pm
by edbucks
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.

Re: Debug draw for box2d physics World

Posted: Thu Jul 28, 2016 9:51 pm
by The_JinJ
Very handy! Thanks :)

Re: Debug draw for box2d physics World

Posted: Thu Sep 13, 2018 4:05 am
by girng
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!

Re: Debug draw for box2d physics World

Posted: Thu Sep 13, 2018 9:27 am
by pgimeno
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().