mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
changed the class handling
This commit is contained in:
parent
d56b4ca660
commit
fd58dd6a86
@ -22,13 +22,14 @@ function love.load()
|
||||
-- create shadow bodys
|
||||
circleTest = lightWorld:newCircle(256, 256, 16)
|
||||
rectangleTest = lightWorld:newRectangle(512, 512, 64, 64)
|
||||
|
||||
imageTest = lightWorld:newImage(image, 64, 64, 24, 6)
|
||||
imageTest:setNormalMap(image_normal)
|
||||
imageTest:setGlowMap(glow)
|
||||
imageTest:setOffset(12, -10)
|
||||
|
||||
-- create body object
|
||||
objectTest = lightWorld:newBody("refraction", normal, 64, 64, 128, 128)
|
||||
objectTest = lightWorld:newRefraction(normal, 64, 64, 128, 128)
|
||||
--objectTest:setShine(false)
|
||||
--objectTest:setShadowType("rectangle")
|
||||
--objectTest:setShadowDimension(64, 64)
|
||||
|
291
lib/body.lua
291
lib/body.lua
@ -1,170 +1,172 @@
|
||||
local _PACKAGE = (...):match("^(.+)[%./][^%./]+") or ""
|
||||
local class = require(_PACKAGE.."/class")
|
||||
|
||||
local body = class(function(o, world, id, type, ...)
|
||||
local body = class()
|
||||
|
||||
function body:init(world, id, type, ...)
|
||||
local args = {...}
|
||||
o.id = id
|
||||
o.type = type
|
||||
o.normal = nil
|
||||
o.material = nil
|
||||
o.glow = nil
|
||||
o.world = world
|
||||
if o.type == "circle" then
|
||||
o.x = args[1] or 0
|
||||
o.y = args[2] or 0
|
||||
o.radius = args[3] or 16
|
||||
o.ox = args[4] or 0
|
||||
o.oy = args[5] or 0
|
||||
o.shadowType = "circle"
|
||||
o.reflection = false
|
||||
o.reflective = false
|
||||
o.refraction = false
|
||||
o.refractive = false
|
||||
self.id = id
|
||||
self.type = type
|
||||
self.normal = nil
|
||||
self.material = nil
|
||||
self.glow = nil
|
||||
self.world = world
|
||||
if self.type == "circle" then
|
||||
self.x = args[1] or 0
|
||||
self.y = args[2] or 0
|
||||
self.radius = args[3] or 16
|
||||
self.ox = args[4] or 0
|
||||
self.oy = args[5] or 0
|
||||
self.shadowType = "circle"
|
||||
self.reflection = false
|
||||
self.reflective = false
|
||||
self.refraction = false
|
||||
self.refractive = false
|
||||
world.isShadows = true
|
||||
elseif o.type == "rectangle" then
|
||||
o.x = args[1] or 0
|
||||
o.y = args[2] or 0
|
||||
o.width = args[3] or 64
|
||||
o.height = args[4] or 64
|
||||
o.ox = o.width * 0.5
|
||||
o.oy = o.height * 0.5
|
||||
o.shadowType = "rectangle"
|
||||
o.data = {
|
||||
o.x - o.ox,
|
||||
o.y - o.oy,
|
||||
o.x - o.ox + o.width,
|
||||
o.y - o.oy,
|
||||
o.x - o.ox + o.width,
|
||||
o.y - o.oy + o.height,
|
||||
o.x - o.ox,
|
||||
o.y - o.oy + o.height
|
||||
elseif self.type == "rectangle" then
|
||||
self.x = args[1] or 0
|
||||
self.y = args[2] or 0
|
||||
self.width = args[3] or 64
|
||||
self.height = args[4] or 64
|
||||
self.ox = self.width * 0.5
|
||||
self.oy = self.height * 0.5
|
||||
self.shadowType = "rectangle"
|
||||
self.data = {
|
||||
self.x - self.ox,
|
||||
self.y - self.oy,
|
||||
self.x - self.ox + self.width,
|
||||
self.y - self.oy,
|
||||
self.x - self.ox + self.width,
|
||||
self.y - self.oy + self.height,
|
||||
self.x - self.ox,
|
||||
self.y - self.oy + self.height
|
||||
}
|
||||
o.reflection = false
|
||||
o.reflective = false
|
||||
o.refraction = false
|
||||
o.refractive = false
|
||||
self.reflection = false
|
||||
self.reflective = false
|
||||
self.refraction = false
|
||||
self.refractive = false
|
||||
world.isShadows = true
|
||||
elseif o.type == "polygon" then
|
||||
o.shadowType = "polygon"
|
||||
o.data = args or {0, 0, 0, 0, 0, 0}
|
||||
o.reflection = false
|
||||
o.reflective = false
|
||||
o.refraction = false
|
||||
o.refractive = false
|
||||
elseif self.type == "polygon" then
|
||||
self.shadowType = "polygon"
|
||||
self.data = args or {0, 0, 0, 0, 0, 0}
|
||||
self.reflection = false
|
||||
self.reflective = false
|
||||
self.refraction = false
|
||||
self.refractive = false
|
||||
world.isShadows = true
|
||||
elseif o.type == "image" then
|
||||
o.img = args[1]
|
||||
o.x = args[2] or 0
|
||||
o.y = args[3] or 0
|
||||
if o.img then
|
||||
o.imgWidth = o.img:getWidth()
|
||||
o.imgHeight = o.img:getHeight()
|
||||
o.width = args[4] or o.imgWidth
|
||||
o.height = args[5] or o.imgHeight
|
||||
o.ix = o.imgWidth * 0.5
|
||||
o.iy = o.imgHeight * 0.5
|
||||
o.vert = {
|
||||
elseif self.type == "image" then
|
||||
self.img = args[1]
|
||||
self.x = args[2] or 0
|
||||
self.y = args[3] or 0
|
||||
if self.img then
|
||||
self.imgWidth = self.img:getWidth()
|
||||
self.imgHeight = self.img:getHeight()
|
||||
self.width = args[4] or self.imgWidth
|
||||
self.height = args[5] or self.imgHeight
|
||||
self.ix = self.imgWidth * 0.5
|
||||
self.iy = self.imgHeight * 0.5
|
||||
self.vert = {
|
||||
{ 0.0, 0.0, 0.0, 0.0 },
|
||||
{ o.width, 0.0, 1.0, 0.0 },
|
||||
{ o.width, o.height, 1.0, 1.0 },
|
||||
{ 0.0, o.height, 0.0, 1.0 },
|
||||
{ self.width, 0.0, 1.0, 0.0 },
|
||||
{ self.width, self.height, 1.0, 1.0 },
|
||||
{ 0.0, self.height, 0.0, 1.0 },
|
||||
}
|
||||
o.msh = love.graphics.newMesh(o.vert, o.img, "fan")
|
||||
self.msh = love.graphics.newMesh(self.vert, self.img, "fan")
|
||||
else
|
||||
o.width = args[4] or 64
|
||||
o.height = args[5] or 64
|
||||
self.width = args[4] or 64
|
||||
self.height = args[5] or 64
|
||||
end
|
||||
o.ox = args[6] or o.width * 0.5
|
||||
o.oy = args[7] or o.height * 0.5
|
||||
o.shadowType = "rectangle"
|
||||
o.data = {
|
||||
o.x - o.ox,
|
||||
o.y - o.oy,
|
||||
o.x - o.ox + o.width,
|
||||
o.y - o.oy,
|
||||
o.x - o.ox + o.width,
|
||||
o.y - o.oy + o.height,
|
||||
o.x - o.ox,
|
||||
o.y - o.oy + o.height
|
||||
self.ox = args[6] or self.width * 0.5
|
||||
self.oy = args[7] or self.height * 0.5
|
||||
self.shadowType = "rectangle"
|
||||
self.data = {
|
||||
self.x - self.ox,
|
||||
self.y - self.oy,
|
||||
self.x - self.ox + self.width,
|
||||
self.y - self.oy,
|
||||
self.x - self.ox + self.width,
|
||||
self.y - self.oy + self.height,
|
||||
self.x - self.ox,
|
||||
self.y - self.oy + self.height
|
||||
}
|
||||
o.reflection = false
|
||||
o.reflective = true
|
||||
o.refraction = false
|
||||
o.refractive = false
|
||||
self.reflection = false
|
||||
self.reflective = true
|
||||
self.refraction = false
|
||||
self.refractive = false
|
||||
world.isShadows = true
|
||||
elseif o.type == "refraction" then
|
||||
o.normal = args[1]
|
||||
o.x = args[2] or 0
|
||||
o.y = args[3] or 0
|
||||
if o.normal then
|
||||
o.normalWidth = o.normal:getWidth()
|
||||
o.normalHeight = o.normal:getHeight()
|
||||
o.width = args[4] or o.normalWidth
|
||||
o.height = args[5] or o.normalHeight
|
||||
o.nx = o.normalWidth * 0.5
|
||||
o.ny = o.normalHeight * 0.5
|
||||
o.normal:setWrap("repeat", "repeat")
|
||||
o.normalVert = {
|
||||
elseif self.type == "refraction" then
|
||||
self.normal = args[1]
|
||||
self.x = args[2] or 0
|
||||
self.y = args[3] or 0
|
||||
if self.normal then
|
||||
self.normalWidth = self.normal:getWidth()
|
||||
self.normalHeight = self.normal:getHeight()
|
||||
self.width = args[4] or self.normalWidth
|
||||
self.height = args[5] or self.normalHeight
|
||||
self.nx = self.normalWidth * 0.5
|
||||
self.ny = self.normalHeight * 0.5
|
||||
self.normal:setWrap("repeat", "repeat")
|
||||
self.normalVert = {
|
||||
{0.0, 0.0, 0.0, 0.0},
|
||||
{o.width, 0.0, 1.0, 0.0},
|
||||
{o.width, o.height, 1.0, 1.0},
|
||||
{0.0, o.height, 0.0, 1.0}
|
||||
{self.width, 0.0, 1.0, 0.0},
|
||||
{self.width, self.height, 1.0, 1.0},
|
||||
{0.0, self.height, 0.0, 1.0}
|
||||
}
|
||||
o.normalMesh = love.graphics.newMesh(o.normalVert, o.normal, "fan")
|
||||
self.normalMesh = love.graphics.newMesh(self.normalVert, self.normal, "fan")
|
||||
else
|
||||
o.width = args[4] or 64
|
||||
o.height = args[5] or 64
|
||||
self.width = args[4] or 64
|
||||
self.height = args[5] or 64
|
||||
end
|
||||
o.ox = o.width * 0.5
|
||||
o.oy = o.height * 0.5
|
||||
o.reflection = false
|
||||
o.reflective = false
|
||||
o.refraction = true
|
||||
o.refractive = false
|
||||
self.ox = self.width * 0.5
|
||||
self.oy = self.height * 0.5
|
||||
self.reflection = false
|
||||
self.reflective = false
|
||||
self.refraction = true
|
||||
self.refractive = false
|
||||
world.isRefraction = true
|
||||
elseif o.type == "reflection" then
|
||||
o.normal = args[1]
|
||||
o.x = args[2] or 0
|
||||
o.y = args[3] or 0
|
||||
if o.normal then
|
||||
o.normalWidth = o.normal:getWidth()
|
||||
o.normalHeight = o.normal:getHeight()
|
||||
o.width = args[4] or o.normalWidth
|
||||
o.height = args[5] or o.normalHeight
|
||||
o.nx = o.normalWidth * 0.5
|
||||
o.ny = o.normalHeight * 0.5
|
||||
o.normal:setWrap("repeat", "repeat")
|
||||
o.normalVert = {
|
||||
elseif self.type == "reflection" then
|
||||
self.normal = args[1]
|
||||
self.x = args[2] or 0
|
||||
self.y = args[3] or 0
|
||||
if self.normal then
|
||||
self.normalWidth = self.normal:getWidth()
|
||||
self.normalHeight = self.normal:getHeight()
|
||||
self.width = args[4] or self.normalWidth
|
||||
self.height = args[5] or self.normalHeight
|
||||
self.nx = self.normalWidth * 0.5
|
||||
self.ny = self.normalHeight * 0.5
|
||||
self.normal:setWrap("repeat", "repeat")
|
||||
self.normalVert = {
|
||||
{0.0, 0.0, 0.0, 0.0},
|
||||
{o.width, 0.0, 1.0, 0.0},
|
||||
{o.width, o.height, 1.0, 1.0},
|
||||
{0.0, o.height, 0.0, 1.0}
|
||||
{self.width, 0.0, 1.0, 0.0},
|
||||
{self.width, self.height, 1.0, 1.0},
|
||||
{0.0, self.height, 0.0, 1.0}
|
||||
}
|
||||
o.normalMesh = love.graphics.newMesh(o.normalVert, o.normal, "fan")
|
||||
self.normalMesh = love.graphics.newMesh(self.normalVert, self.normal, "fan")
|
||||
else
|
||||
o.width = args[4] or 64
|
||||
o.height = args[5] or 64
|
||||
self.width = args[4] or 64
|
||||
self.height = args[5] or 64
|
||||
end
|
||||
o.ox = o.width * 0.5
|
||||
o.oy = o.height * 0.5
|
||||
o.reflection = true
|
||||
o.reflective = false
|
||||
o.refraction = false
|
||||
o.refractive = false
|
||||
self.ox = self.width * 0.5
|
||||
self.oy = self.height * 0.5
|
||||
self.reflection = true
|
||||
self.reflective = false
|
||||
self.refraction = false
|
||||
self.refractive = false
|
||||
world.isReflection = true
|
||||
end
|
||||
o.shine = true
|
||||
o.red = 0
|
||||
o.green = 0
|
||||
o.blue = 0
|
||||
o.alpha = 1.0
|
||||
o.glowRed = 255
|
||||
o.glowGreen = 255
|
||||
o.glowBlue = 255
|
||||
o.glowStrength = 0.0
|
||||
o.tileX = 0
|
||||
o.tileY = 0
|
||||
end)
|
||||
self.shine = true
|
||||
self.red = 0
|
||||
self.green = 0
|
||||
self.blue = 0
|
||||
self.alpha = 1.0
|
||||
self.glowRed = 255
|
||||
self.glowGreen = 255
|
||||
self.glowBlue = 255
|
||||
self.glowStrength = 0.0
|
||||
self.tileX = 0
|
||||
self.tileY = 0
|
||||
end
|
||||
|
||||
-- refresh
|
||||
function body:refresh()
|
||||
@ -297,11 +299,6 @@ function body:getPoints()
|
||||
return unpack(self.data)
|
||||
end
|
||||
-- set shadow on/off
|
||||
function body:setShadowType(type)
|
||||
self.shadowType = type
|
||||
self.world.changed = true
|
||||
end
|
||||
-- set shadow on/off
|
||||
function body:setShadow(b)
|
||||
self.castsNoShadow = not b
|
||||
self.world.changed = true
|
||||
|
@ -21,8 +21,8 @@ local class = function(base, init)
|
||||
mt.__call = function(class_tbl, ...)
|
||||
local obj = {}
|
||||
setmetatable(obj,c)
|
||||
if init then
|
||||
init(obj,...)
|
||||
if class_tbl.init then
|
||||
class_tbl.init(obj,...)
|
||||
else
|
||||
-- make sure that any stuff from the base class is initialized!
|
||||
if base and base.init then
|
||||
|
@ -1,26 +1,28 @@
|
||||
local _PACKAGE = (...):match("^(.+)[%./][^%./]+") or ""
|
||||
local class = require(_PACKAGE.."/class")
|
||||
|
||||
local light = class(function(l, world, x, y, r, g, b, range)
|
||||
l.world = world
|
||||
l.direction = 0
|
||||
l.angle = math.pi * 2.0
|
||||
l.range = 0
|
||||
l.shadow = love.graphics.newCanvas()
|
||||
l.shine = love.graphics.newCanvas()
|
||||
l.x = x or 0
|
||||
l.y = y or 0
|
||||
l.z = 15
|
||||
l.red = r or 255
|
||||
l.green = g or 255
|
||||
l.blue = b or 255
|
||||
l.range = range or 300
|
||||
l.smooth = 1.0
|
||||
l.glowSize = 0.1
|
||||
l.glowStrength = 0.0
|
||||
l.changed = true
|
||||
l.visible = true
|
||||
end)
|
||||
local light = class()
|
||||
|
||||
function light:init(world, x, y, r, g, b, range)
|
||||
self.world = world
|
||||
self.direction = 0
|
||||
self.angle = math.pi * 2.0
|
||||
self.range = 0
|
||||
self.shadow = love.graphics.newCanvas()
|
||||
self.shine = love.graphics.newCanvas()
|
||||
self.x = x or 0
|
||||
self.y = y or 0
|
||||
self.z = 15
|
||||
self.red = r or 255
|
||||
self.green = g or 255
|
||||
self.blue = b or 255
|
||||
self.range = range or 300
|
||||
self.smooth = 1.0
|
||||
self.glowSize = 0.1
|
||||
self.glowStrength = 0.0
|
||||
self.changed = true
|
||||
self.visible = true
|
||||
end
|
||||
|
||||
-- set position
|
||||
function light:setPosition(x, y, z)
|
||||
|
@ -28,70 +28,72 @@ local vector = require(_PACKAGE..'/vector')
|
||||
local Light = require(_PACKAGE..'/light')
|
||||
local Body = require(_PACKAGE..'/body')
|
||||
|
||||
local light_world = class(function(o)
|
||||
o.translate_x = 0
|
||||
o.translate_y = 0
|
||||
o.translate_x_old = 0
|
||||
o.translate_y_old = 0
|
||||
o.direction = 0
|
||||
local light_world = class()
|
||||
|
||||
o.last_buffer = nil
|
||||
function light_world:init()
|
||||
self.translate_x = 0
|
||||
self.translate_y = 0
|
||||
self.translate_x_old = 0
|
||||
self.translate_y_old = 0
|
||||
self.direction = 0
|
||||
|
||||
o.lights = {}
|
||||
o.ambient = {0, 0, 0}
|
||||
o.body = {}
|
||||
o.refraction = {}
|
||||
o.shadow = love.graphics.newCanvas()
|
||||
o.shadow2 = love.graphics.newCanvas()
|
||||
o.shine = love.graphics.newCanvas()
|
||||
o.shine2 = love.graphics.newCanvas()
|
||||
o.normalMap = love.graphics.newCanvas()
|
||||
o.glowMap = love.graphics.newCanvas()
|
||||
o.glowMap2 = love.graphics.newCanvas()
|
||||
o.refractionMap = love.graphics.newCanvas()
|
||||
o.refractionMap2 = love.graphics.newCanvas()
|
||||
o.reflectionMap = love.graphics.newCanvas()
|
||||
o.reflectionMap2 = love.graphics.newCanvas()
|
||||
o.normalInvert = false
|
||||
o.glowBlur = 1.0
|
||||
o.glowTimer = 0.0
|
||||
o.glowDown = false
|
||||
o.refractionStrength = 8.0
|
||||
self.last_buffer = nil
|
||||
|
||||
o.pixelShadow = love.graphics.newCanvas()
|
||||
o.pixelShadow2 = love.graphics.newCanvas()
|
||||
self.lights = {}
|
||||
self.ambient = {0, 0, 0}
|
||||
self.body = {}
|
||||
self.refraction = {}
|
||||
self.shadow = love.graphics.newCanvas()
|
||||
self.shadow2 = love.graphics.newCanvas()
|
||||
self.shine = love.graphics.newCanvas()
|
||||
self.shine2 = love.graphics.newCanvas()
|
||||
self.normalMap = love.graphics.newCanvas()
|
||||
self.glowMap = love.graphics.newCanvas()
|
||||
self.glowMap2 = love.graphics.newCanvas()
|
||||
self.refractionMap = love.graphics.newCanvas()
|
||||
self.refractionMap2 = love.graphics.newCanvas()
|
||||
self.reflectionMap = love.graphics.newCanvas()
|
||||
self.reflectionMap2 = love.graphics.newCanvas()
|
||||
self.normalInvert = false
|
||||
self.glowBlur = 1.0
|
||||
self.glowTimer = 0.0
|
||||
self.glowDown = false
|
||||
self.refractionStrength = 8.0
|
||||
|
||||
o.blurv = love.graphics.newShader("shader/blurv.glsl")
|
||||
o.blurh = love.graphics.newShader("shader/blurh.glsl")
|
||||
o.blurv:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
o.blurh:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
self.pixelShadow = love.graphics.newCanvas()
|
||||
self.pixelShadow2 = love.graphics.newCanvas()
|
||||
|
||||
o.shader = love.graphics.newShader("shader/poly_shadow.glsl")
|
||||
o.glowShader = love.graphics.newShader("shader/glow.glsl")
|
||||
o.normalShader = love.graphics.newShader("shader/normal.glsl")
|
||||
o.normalInvertShader = love.graphics.newShader("shader/normal_invert.glsl")
|
||||
o.materialShader = love.graphics.newShader("shader/material.glsl")
|
||||
o.refractionShader = love.graphics.newShader("shader/refraction.glsl")
|
||||
o.refractionShader:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
o.reflectionShader = love.graphics.newShader("shader/reflection.glsl")
|
||||
o.reflectionShader:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
self.blurv = love.graphics.newShader("shader/blurv.glsl")
|
||||
self.blurh = love.graphics.newShader("shader/blurh.glsl")
|
||||
self.blurv:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
self.blurh:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
|
||||
o.reflectionStrength = 16.0
|
||||
o.reflectionVisibility = 1.0
|
||||
o.changed = true
|
||||
o.blur = 2.0
|
||||
o.optionShadows = true
|
||||
o.optionPixelShadows = true
|
||||
o.optionGlow = true
|
||||
o.optionRefraction = true
|
||||
o.optionReflection = true
|
||||
o.isShadows = false
|
||||
o.isLight = false
|
||||
o.isPixelShadows = false
|
||||
o.isGlow = false
|
||||
o.isRefraction = false
|
||||
o.isReflection = false
|
||||
end)
|
||||
self.shader = love.graphics.newShader("shader/poly_shadow.glsl")
|
||||
self.glowShader = love.graphics.newShader("shader/glow.glsl")
|
||||
self.normalShader = love.graphics.newShader("shader/normal.glsl")
|
||||
self.normalInvertShader = love.graphics.newShader("shader/normal_invert.glsl")
|
||||
self.materialShader = love.graphics.newShader("shader/material.glsl")
|
||||
self.refractionShader = love.graphics.newShader("shader/refraction.glsl")
|
||||
self.refractionShader:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
self.reflectionShader = love.graphics.newShader("shader/reflection.glsl")
|
||||
self.reflectionShader:send("screen", {love.window.getWidth(), love.window.getHeight()})
|
||||
|
||||
self.reflectionStrength = 16.0
|
||||
self.reflectionVisibility = 1.0
|
||||
self.changed = true
|
||||
self.blur = 2.0
|
||||
self.optionShadows = true
|
||||
self.optionPixelShadows = true
|
||||
self.optionGlow = true
|
||||
self.optionRefraction = true
|
||||
self.optionReflection = true
|
||||
self.isShadows = false
|
||||
self.isLight = false
|
||||
self.isPixelShadows = false
|
||||
self.isGlow = false
|
||||
self.isRefraction = false
|
||||
self.isReflection = false
|
||||
end
|
||||
|
||||
-- update
|
||||
function light_world:update()
|
||||
|
Loading…
Reference in New Issue
Block a user