2014-10-18 14:51:23 +00:00
|
|
|
class = require 'hump.class'
|
2014-10-18 19:23:04 +00:00
|
|
|
VectorLight = require 'hump/vector-light'
|
|
|
|
|
2014-10-23 06:42:38 +00:00
|
|
|
local scale = 0.001
|
2014-10-18 19:23:04 +00:00
|
|
|
|
|
|
|
local font = love.graphics.newFont(10)
|
2014-10-18 14:51:23 +00:00
|
|
|
|
|
|
|
DebugVector = Class {
|
2014-10-18 19:23:04 +00:00
|
|
|
init = function(self, label, x0 , y0, dx, dy)
|
2014-10-18 14:51:23 +00:00
|
|
|
self.x0 = x0;
|
|
|
|
self.y0 = y0;
|
|
|
|
self.dx = dx;
|
|
|
|
self.dy = dy;
|
2014-10-18 19:23:04 +00:00
|
|
|
self.label = label;
|
2014-10-18 14:51:23 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-10-19 10:10:34 +00:00
|
|
|
draw = function(self, labelDistance)
|
2014-10-18 14:51:23 +00:00
|
|
|
love.graphics.setColor(255, 0, 0)
|
2014-10-18 19:23:04 +00:00
|
|
|
love.graphics.line(self.x0, self.y0, self.x0 + self.dx * scale, self.y0 + self.dy * scale);
|
|
|
|
if self.label then
|
|
|
|
love.graphics.setColor(0,0,0)
|
|
|
|
love.graphics.setFont(font)
|
|
|
|
local unit_x, unit_y = VectorLight.div(VectorLight.len(self.dx, self.dy), self.dx, self.dy)
|
|
|
|
local dist_x, dist_y = self.dx * scale, self.dy * scale
|
2014-10-19 10:10:34 +00:00
|
|
|
local distance = math.min(labelDistance, VectorLight.len(dist_x, dist_y))
|
2014-10-18 19:23:04 +00:00
|
|
|
dist_x, dist_y = VectorLight.mul(distance, unit_x, unit_y)
|
2014-10-19 04:11:15 +00:00
|
|
|
love.graphics.printf(string.format("%s %f", self.label, VectorLight.len(self.dx, self.dy)), self.x0 + dist_x, self.y0 + dist_y, 100, "left")
|
2014-10-18 19:23:04 +00:00
|
|
|
end
|
2014-10-18 14:51:23 +00:00
|
|
|
end;
|
|
|
|
}
|
|
|
|
|
2014-10-19 04:11:15 +00:00
|
|
|
DebugCircle = Class {
|
|
|
|
init = function(self, label, x0 , y0)
|
|
|
|
self.x0 = x0;
|
|
|
|
self.y0 = y0;
|
|
|
|
self.label = label;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-10-19 10:10:34 +00:00
|
|
|
draw = function(self, distance)
|
2014-10-19 04:11:15 +00:00
|
|
|
love.graphics.setColor(255, 0, 0)
|
|
|
|
love.graphics.circle("fill", self.x0, self.y0, 5, 20);
|
|
|
|
-- if self.label then
|
|
|
|
-- love.graphics.setColor(0,0,0)
|
|
|
|
-- love.graphics.setFont(font)
|
|
|
|
-- local unit_x, unit_y = VectorLight.div(VectorLight.len(self.dx, self.dy), self.dx, self.dy)
|
|
|
|
-- local dist_x, dist_y = self.dx * scale, self.dy * scale
|
|
|
|
-- local distance = math.min(100, VectorLight.len(dist_x, dist_y))
|
|
|
|
-- dist_x, dist_y = VectorLight.mul(distance, unit_x, unit_y)
|
|
|
|
-- love.graphics.printf(string.format("%s %f", self.label, VectorLight.len(self.dx, self.dy)), self.x0 + dist_x, self.y0 + dist_y, 100, "left")
|
|
|
|
-- end
|
|
|
|
end;
|
|
|
|
}
|
|
|
|
|
2014-10-19 01:59:12 +00:00
|
|
|
debugEnabled = false
|
|
|
|
|
2014-10-18 20:16:11 +00:00
|
|
|
drawDebug = function(debugVectors)
|
2014-10-19 04:11:15 +00:00
|
|
|
if debugEnabled and debugVectors then
|
2014-10-19 10:10:34 +00:00
|
|
|
local labelDistance = 100
|
2014-10-19 01:59:12 +00:00
|
|
|
for key, debugVector in pairs(debugVectors) do
|
2014-10-19 10:10:34 +00:00
|
|
|
debugVector:draw(labelDistance);
|
|
|
|
labelDistance = labelDistance + 50
|
2014-10-19 01:59:12 +00:00
|
|
|
end
|
2014-10-18 14:51:23 +00:00
|
|
|
end
|
|
|
|
end;
|