mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
colored shadows almost functional again
This commit is contained in:
parent
012a5481e9
commit
bbcd20a27e
@ -619,7 +619,7 @@ function love.keypressed(k, u)
|
|||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld:newImage(blopp, mx, my, 42, 16, 21, 0)
|
phyLight[phyCnt] = lightWorld:newImage(blopp, mx, my, 42, 16, 21, 0)
|
||||||
phyLight[phyCnt]:generateNormalMapGradient("gradient", "gradient")
|
phyLight[phyCnt]:generateNormalMapGradient("gradient", "gradient")
|
||||||
phyLight[phyCnt]:setAlpha(0.5)
|
phyLight[phyCnt]:setAlpha(255 * 0.5)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 42, 29)
|
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 42, 29)
|
||||||
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
||||||
@ -640,7 +640,7 @@ function love.keypressed(k, u)
|
|||||||
-- add rectangle
|
-- add rectangle
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld:newPolygon()
|
phyLight[phyCnt] = lightWorld:newPolygon()
|
||||||
phyLight[phyCnt]:setAlpha(0.5)
|
phyLight[phyCnt]:setAlpha(255 * 0.5)
|
||||||
phyLight[phyCnt]:setGlowStrength(1.0)
|
phyLight[phyCnt]:setGlowStrength(1.0)
|
||||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||||
math.randomseed(love.timer.getTime())
|
math.randomseed(love.timer.getTime())
|
||||||
@ -657,7 +657,7 @@ function love.keypressed(k, u)
|
|||||||
cRadius = math.random(8, 32)
|
cRadius = math.random(8, 32)
|
||||||
phyCnt = phyCnt + 1
|
phyCnt = phyCnt + 1
|
||||||
phyLight[phyCnt] = lightWorld:newCircle(mx, my, cRadius)
|
phyLight[phyCnt] = lightWorld:newCircle(mx, my, cRadius)
|
||||||
phyLight[phyCnt]:setAlpha(0.5)
|
phyLight[phyCnt]:setAlpha(255 * 0.5)
|
||||||
phyLight[phyCnt]:setGlowStrength(1.0)
|
phyLight[phyCnt]:setGlowStrength(1.0)
|
||||||
math.randomseed(phyCnt)
|
math.randomseed(phyCnt)
|
||||||
phyLight[phyCnt]:setGlowColor(math.random(0, 255), math.random(0, 255), math.random(0, 255))
|
phyLight[phyCnt]:setGlowColor(math.random(0, 255), math.random(0, 255), math.random(0, 255))
|
||||||
|
13
lib/body.lua
13
lib/body.lua
@ -461,6 +461,10 @@ function body:drawMaterial()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function body:drawShadow(light)
|
function body:drawShadow(light)
|
||||||
|
if self.castsNoShadow or (self.zheight - light.z) > 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
love.graphics.setColor(self.red, self.green, self.blue, self.alpha)
|
love.graphics.setColor(self.red, self.green, self.blue, self.alpha)
|
||||||
if self.shadowType == "rectangle" or self.shadowType == "polygon" then
|
if self.shadowType == "rectangle" or self.shadowType == "polygon" then
|
||||||
self:drawPolyShadow(light)
|
self:drawPolyShadow(light)
|
||||||
@ -474,10 +478,6 @@ end
|
|||||||
--using shadow point calculations from this article
|
--using shadow point calculations from this article
|
||||||
--http://web.cs.wpi.edu/~matt/courses/cs563/talks/shadow/shadow.html
|
--http://web.cs.wpi.edu/~matt/courses/cs563/talks/shadow/shadow.html
|
||||||
function body:drawPolyShadow(light)
|
function body:drawPolyShadow(light)
|
||||||
if self.castsNoShadow or (self.zheight - light.z) > 0 then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local edgeFacingTo = {}
|
local edgeFacingTo = {}
|
||||||
for k = 1, #self.data, 2 do
|
for k = 1, #self.data, 2 do
|
||||||
local indexOfNextVertex = (k + 2) % #self.data
|
local indexOfNextVertex = (k + 2) % #self.data
|
||||||
@ -529,10 +529,6 @@ end
|
|||||||
--using shadow point calculations from this article
|
--using shadow point calculations from this article
|
||||||
--http://web.cs.wpi.edu/~matt/courses/cs563/talks/shadow/shadow.html
|
--http://web.cs.wpi.edu/~matt/courses/cs563/talks/shadow/shadow.html
|
||||||
function body:drawCircleShadow(light)
|
function body:drawCircleShadow(light)
|
||||||
if self.castsNoShadow or (self.zheight - light.z) > 0 then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local curShadowGeometry = {}
|
local curShadowGeometry = {}
|
||||||
local angle = math.atan2(light.x - (self.x - self.ox), (self.y - self.oy) - light.y) + math.pi / 2
|
local angle = math.atan2(light.x - (self.x - self.ox), (self.y - self.oy) - light.y) + math.pi / 2
|
||||||
local x2 = ((self.x - self.ox) + math.sin(angle) * self.radius)
|
local x2 = ((self.x - self.ox) + math.sin(angle) * self.radius)
|
||||||
@ -566,6 +562,7 @@ function body:drawCircleShadow(light)
|
|||||||
|
|
||||||
love.graphics.polygon("fill", curShadowGeometry)
|
love.graphics.polygon("fill", curShadowGeometry)
|
||||||
|
|
||||||
|
print(self.red, self.green, self.blue, self.alpha)
|
||||||
if distance1 <= self.radius then
|
if distance1 <= self.radius then
|
||||||
love.graphics.arc("fill", cx, cy, radius, 0, (math.pi * 2))
|
love.graphics.arc("fill", cx, cy, radius, 0, (math.pi * 2))
|
||||||
elseif distance2 < light.range then -- dont draw circle if way off screen
|
elseif distance2 < light.range then -- dont draw circle if way off screen
|
||||||
|
Loading…
Reference in New Issue
Block a user