-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugWorldDraw.lua
92 lines (83 loc) · 2.98 KB
/
debugWorldDraw.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--[[
-- Copyright (C) Azhukar 2014
-- By Azhukar
-- Taken from https://love2d.org/forums/viewtopic.php?f=5&t=77596
--]]
local function debugWorldDraw(world)
local bodies = world:getBodyList()
for b=#bodies,1,-1 do
local body = bodies[b]
local bx,by = body:getPosition()
local bodyAngle = body:getAngle()
love.graphics.push()
love.graphics.translate(bx,by)
love.graphics.rotate(bodyAngle)
math.randomseed(1) --for color generation
local fixtures = body:getFixtureList()
for i=1,#fixtures do
local fixture = fixtures[i]
local shape = fixture:getShape()
local shapeType = shape:getType()
local isSensor = fixture:isSensor()
if (isSensor) then
love.graphics.setColor(0,0,255,96)
else
love.graphics.setColor(math.random(32,200),math.random(32,200),math.random(32,200),96)
end
love.graphics.setLineWidth(1)
if (shapeType == "circle") then
local x,y = fixture:getMassData() --0.9.0 missing circleshape:getPoint()
--local x,y = shape:getPoint() --0.9.1
local radius = shape:getRadius()
love.graphics.circle("fill",x,y,radius,15)
love.graphics.setColor(0,0,0,255)
love.graphics.circle("line",x,y,radius,15)
local eyeRadius = radius/4
love.graphics.setColor(0,0,0,255)
love.graphics.circle("fill",x+radius-eyeRadius,y,eyeRadius,10)
elseif (shapeType == "polygon") then
local points = {shape:getPoints()}
love.graphics.polygon("fill",points)
love.graphics.setColor(0,0,0,255)
love.graphics.polygon("line",points)
elseif (shapeType == "edge") then
love.graphics.setColor(0,0,0,255)
love.graphics.line(shape:getPoints())
elseif (shapeType == "chain") then
love.graphics.setColor(0,0,0,255)
love.graphics.line(shape:getPoints())
end
end
love.graphics.pop()
end
local joints = world:getJointList()
for index,joint in pairs(joints) do
love.graphics.setColor(0,255,0,255)
local x1,y1,x2,y2 = joint:getAnchors()
if (x1 and x2) then
love.graphics.setLineWidth(3)
love.graphics.line(x1,y1,x2,y2)
else
love.graphics.setPointSize(3)
if (x1) then
love.graphics.point(x1,y1)
end
if (x2) then
love.graphics.point(x2,y2)
end
end
end
local contacts = world:getContactList()
for i=1,#contacts do
love.graphics.setColor(255,0,0,255)
love.graphics.setPointSize(3)
local x1,y1,x2,y2 = contacts[i]:getPositions()
if (x1) then
love.graphics.point(x1,y1)
end
if (x2) then
love.graphics.point(x2,y2)
end
end
end
return debugWorldDraw