mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
made circle shadow bodies use arc instead of circle, also optimized so they were not drawn if not neccessary
This commit is contained in:
parent
ac5b9afa16
commit
993e029a2f
15
lib/body.lua
15
lib/body.lua
@ -636,7 +636,20 @@ function body:calculateCircleShadow(light)
|
||||
|
||||
local radius = math.sqrt(math.pow(curShadowGeometry[7] - curShadowGeometry[5], 2) + math.pow(curShadowGeometry[8]-curShadowGeometry[6], 2)) / 2
|
||||
local cx, cy = (curShadowGeometry[5] + curShadowGeometry[7])/2, (curShadowGeometry[6] + curShadowGeometry[8])/2
|
||||
curShadowGeometry.circle = {cx, cy, radius}
|
||||
local angle1 = math.atan2(curShadowGeometry[6] - cy, curShadowGeometry[5] - cx)
|
||||
local angle2 = math.atan2(curShadowGeometry[8] - cy, curShadowGeometry[7] - cx)
|
||||
local distance1 = math.sqrt(math.pow(light.x - self.x, 2) + math.pow(light.y - self.y, 2)) / 2
|
||||
local distance2 = math.sqrt(math.pow(light.x - cx, 2) + math.pow(light.y - cy, 2)) / 2
|
||||
|
||||
if distance1 <= self.radius then
|
||||
curShadowGeometry.circle = {cx, cy, radius, 0, (math.pi * 2)}
|
||||
elseif distance2 < light.range then -- dont draw circle if way off screen
|
||||
if angle1 > angle2 then
|
||||
curShadowGeometry.circle = {cx, cy, radius, angle1, angle2}
|
||||
else
|
||||
curShadowGeometry.circle = {cx, cy, radius, angle1 - math.pi, angle2 - math.pi}
|
||||
end
|
||||
end
|
||||
|
||||
curShadowGeometry.red = self.red
|
||||
curShadowGeometry.green = self.green
|
||||
|
@ -1,7 +1,7 @@
|
||||
--[[
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Marcus Ihde
|
||||
Copyright (c) 2014 Marcus Ihde, Tim Anema
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -165,6 +165,9 @@ function light:drawShadow(l,t,w,h,s,bodies, canvas)
|
||||
shadow_geometry[k].blue * (1.0 - shadow_geometry[k].alpha)
|
||||
)
|
||||
love.graphics.polygon("fill", unpack(shadow_geometry[k]))
|
||||
if shadow_geometry[k].circle then
|
||||
love.graphics.arc("fill", unpack(shadow_geometry[k].circle))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -7,7 +7,7 @@ function stencils.shadow(geometry, bodies)
|
||||
if geometry[i].alpha == 1.0 then
|
||||
love.graphics.polygon("fill", unpack(geometry[i]))
|
||||
if geometry[i].circle then
|
||||
love.graphics.circle("fill", unpack(geometry[i].circle))
|
||||
love.graphics.arc("fill", unpack(geometry[i].circle))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user