mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
fixed inaccuracy of the inRange method in Light. also added it to the draw methods in light so that they wont draw if not needed
This commit is contained in:
parent
3d4819cda4
commit
233d40ea39
@ -107,15 +107,17 @@ function light:setGlowStrength(strength)
|
|||||||
self.glowStrength = strength
|
self.glowStrength = strength
|
||||||
end
|
end
|
||||||
|
|
||||||
function light:inRange(l,t,w,h)
|
function light:inRange(l,t,w,h,s)
|
||||||
return self.x + self.range > l and
|
local lx, ly, rs = (self.x + l/s) * s, (self.y + t/s) * s, self.range * s
|
||||||
self.x - self.range < (l+w) and
|
|
||||||
self.y + self.range > t and
|
return (lx + rs) > 0 and
|
||||||
self.y - self.range < (t+h)
|
(lx - rs) < w/s and
|
||||||
|
(ly + rs) > 0 and
|
||||||
|
(ly - rs) < h/s
|
||||||
end
|
end
|
||||||
|
|
||||||
function light:drawShadow(l,t,w,h,s,bodies, canvas)
|
function light:drawShadow(l,t,w,h,s,bodies, canvas)
|
||||||
if self.visible and self:inRange(l,t,w,h) then
|
if self.visible and self:inRange(l,t,w,h,s) then
|
||||||
-- calculate shadows
|
-- calculate shadows
|
||||||
local shadow_geometry = {}
|
local shadow_geometry = {}
|
||||||
for i = 1, #bodies do
|
for i = 1, #bodies do
|
||||||
@ -167,7 +169,7 @@ function light:drawShadow(l,t,w,h,s,bodies, canvas)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function light:drawShine(l,t,w,h,s,bodies,canvas)
|
function light:drawShine(l,t,w,h,s,bodies,canvas)
|
||||||
if self.visible then
|
if self.visible and self:inRange(l,t,w,h,s) then
|
||||||
--update shine
|
--update shine
|
||||||
self.shine:clear(255, 255, 255)
|
self.shine:clear(255, 255, 255)
|
||||||
util.drawto(self.shine, l, t, s, function()
|
util.drawto(self.shine, l, t, s, function()
|
||||||
@ -183,7 +185,7 @@ function light:drawShine(l,t,w,h,s,bodies,canvas)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function light:drawPixelShadow(l,t,w,h,s, normalMap, canvas)
|
function light:drawPixelShadow(l,t,w,h,s, normalMap, canvas)
|
||||||
if self.visible then
|
if self.visible and self:inRange(l,t,w,h,s) then
|
||||||
if self.normalInvert then
|
if self.normalInvert then
|
||||||
self.normalInvertShader:send('lightColor', {self.red / 255.0, self.green / 255.0, self.blue / 255.0})
|
self.normalInvertShader:send('lightColor', {self.red / 255.0, self.green / 255.0, self.blue / 255.0})
|
||||||
self.normalInvertShader:send("lightPosition", {(self.x + l/s) * s, (h/s - (self.y + t/s)) * s, self.z / 255.0})
|
self.normalInvertShader:send("lightPosition", {(self.x + l/s) * s, (h/s - (self.y + t/s)) * s, self.z / 255.0})
|
||||||
|
Loading…
Reference in New Issue
Block a user