Good thing that's the default for Lua.tio wrote:And opening brackets at the same line as function definition
Debug draw for box2d physics World
Re: Debug draw for box2d physics World
Re: Debug draw for box2d physics World
Updated, now draws only on screen bodies and can draw from coordinates in world.
Re: Debug draw for box2d physics World
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.
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.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Debug draw for box2d physics World
Use love.math's RandomGenerator objects?
Re: Debug draw for box2d physics World
Updated to fix a few issues.
Re: Debug draw for box2d physics World
Thanks for the update, random generation works properly now.
Re: Debug draw for box2d physics World
Thank you so much for this script. For the latest version I changed to and all was well.
Code: Select all
love.graphics.point
Code: Select all
love.graphics.points
Re: Debug draw for box2d physics World
Very handy! Thanks
Re: Debug draw for box2d physics World
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
gtx 950, latest lua 11.1
ok, nevermind. found this snippet here:
https://love2d.org/wiki/Tutorial:PhysicsDrawing
at the very bottom. works great!
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'
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
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().
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 206 times
Who is online
Users browsing this forum: Amazon [Bot] and 4 guests