Page 11 of 15

Re: Löve "Light vs. Shadow" Engine v2

Posted: Fri Jan 30, 2015 12:31 am
by Relazy
drunken_thor wrote:Just an update, I pretty much implemented scaling and rotating of light bodies, there is just some inaccuracy in them so the object get slightly smaller if you rotate them and scaling does not match up with how love.graphics.draw scales so it will be a different size depending on the scale.
Did you commit on github? I don't see any new updates :? . Thanks for keeping the plugin alive! Another suggestion would be to implement z-map, although from my perspective that looks to be difficult to implement based on the current structure of the plugin(Unless I am too dumb to see that it's already implemented).

Re: Löve "Light vs. Shadow" Engine v2

Posted: Fri Jan 30, 2015 7:38 pm
by drunken_thor
I just pushed a rotation_and_scaling branch on github, you can check it out there. I ended making rectangles into polygons to eliminate some extra code and I think I am going to have to approach rotating and scaling from a different way because to address the inaccuracy issues/

Re: Löve "Light vs. Shadow" Engine v2

Posted: Wed Feb 18, 2015 3:29 pm
by drunken_thor
Okay I have finally finished scaling and rotating most things I am not sure I did scaling circles now that I think about it.....

Anyways it is all merged into master now so try it out and let me know what it means. If you have problems it is all tagged you can use the 2.0 tag.

Re: Löve "Light vs. Shadow" Engine v2

Posted: Wed Feb 18, 2015 9:24 pm
by drunken_thor
okay finished circles now as well!

Re: Löve "Light vs. Shadow" Engine v2

Posted: Thu Feb 19, 2015 10:03 pm
by Relazy
I am having trouble with rotation.. First of all if I have a "rectangle" type shadow, I get an error as "self.unit_data" is nil in body.lua 126. However when I swap the type to Image, the issue I described before shows up again. Heres a screen shot(Note: it's rotated by 180 degrees):

Re: Löve "Light vs. Shadow" Engine v2

Posted: Fri Feb 20, 2015 10:35 am
by 8bitDaemon
I'm having some issues with implementing the engine with my camera. Basically my camera and the light engine don't line up, or the light engine will cancel out the cameras zoom and stuff like that. I'm not using HUMP but a different one that includes parallax and camera boundaries. The damn camera works wonderfully until I try to put the lights through it. Heres the code for the camera:

Code: Select all

camera = {}
camera._x = 0
camera._y = 0
camera.scaleX = 1
camera.scaleY = 1
camera.rotation = 0
camera.layers = {}


--creates layers for parralax
function camera:newLayer(scale, func)
  table.insert(self.layers, {draw = func, scale = scale}) 
  table.sort(self.layers, function(a,b) return a.scale < b.scale end)
end

--draws the parralax layers
function camera:draw()
  local bx, by = self._x, self._y
  
  for _, v in ipairs(self.layers) do
    self._x = bx *v.scale
    self._y = by *v.scale
    camera:set()
    v.draw()
    camera:unset()
    
    end
  
 end

--attaches the camear
function camera:set()
  love.graphics.push()
  love.graphics.rotate(-self.rotation)
  love.graphics.scale(self.scaleX, self.scaleY)
  love.graphics.translate(-self._x, -self._y)
 
end
 
 --detaches the camera
function camera:unset()
  love.graphics.pop()
end
 
 --moves the camera
function camera:move(dx, dy)
  self._x = self._x + (dx or 0)
  self._y = self._y + (dy or 0)
end
 
function camera:rotate(dr)
  self.rotation = self.rotation + dr
end
 
function camera:scale(sx, sy)
  sx = sx or 1
  self.scaleX = self.scaleX * sx
  self.scaleY = self.scaleY * (sy or sx)
end
 
function camera:setX(value)
  if self._bounds then
    self._x = math.clamp(value, self._bounds.x1, self._bounds.x2)
  else
    self._x = value
  end
end
 
function camera:setY(value)
  if self._bounds then
    self._y = math.clamp(value, self._bounds.y1, self._bounds.y2)
  else
    self._y = value
  end
end
 
function camera:setPosition(x, y)
  if x then self:setX(x) end
  if y then self:setY(y) end
end
 
function camera:setScale(sx, sy)
  self.scaleX = sx or self.scaleX
  self.scaleY = sy or self.scaleY
end
 
function camera:getBounds()
  return unpack(self._bounds)
end

 function camera:getPos()
   return self._x, self._y
 end
--sets the bounding box for the camera 
function camera:setBounds(x1, y1, x2, y2)
  self._bounds = { x1 = x1, y1 = y1, x2 = x2, y2 = y2 }
end
Heres the snippet where my draw is

Code: Select all

function love.draw()
 lightWorld:draw(function()
    camera:draw() 
camera:set()
 
 --normal drawing stuff here--
end)
  camera:unset()
   end
Yeah, I know I"m calling the lightWorld:draw before the camera:set while having the function end before the camera is unset, but It's the only way I can get it to work at all.

any help would be appreciated> :cry:

Re: Löve "Light vs. Shadow" Engine v2

Posted: Tue Feb 24, 2015 5:55 pm
by drunken_thor
8bitDaemon wrote: Heres the snippet where my draw is

Code: Select all

function love.draw()
 lightWorld:draw(function()
    camera:draw() 
camera:set()
 
 --normal drawing stuff here--
end)
  camera:unset()
   end
any help would be appreciated> :cry:
You need to change your camera because normal usage of this would be something like this

Code: Select all

function love.draw()
   lightWorld:setTranslation(camera._x, camera.y, camera.scaleX, camera.scale)
    camera:set()
    lightWorld:draw(function()
        for _, v in ipairs(camera.layers) do
           v.draw()
        end
    end)
    camera:unset()  
end
Please see the camera examples and the normal usage examples to show you how light_world expects translation and scaling.

Re: Löve "Light vs. Shadow" Engine v2

Posted: Tue Feb 24, 2015 5:56 pm
by drunken_thor
Relazy wrote:I am having trouble with rotation.. First of all if I have a "rectangle" type shadow, I get an error as "self.unit_data" is nil in body.lua 126. However when I swap the type to Image, the issue I described before shows up again. Heres a screen shot(Note: it's rotated by 180 degrees):
Do you have any code I can see? unit_data is set when you create a rectangle and should never change after that so if it is nil you might be doing something I did not predict.

Re: Löve "Light vs. Shadow" Engine v2

Posted: Wed Feb 25, 2015 4:47 pm
by Magicked
This is a very noob question, but I'm trying to get a quick test to work and I am failing miserably. I'm sure I am missing something obvious. I just want to draw a tiny space ship and a light.

Code: Select all

local LightWorld = require "lib/lightworld"

function love.load(arg)
	camera = { x = 0, y = 0, scale = 1 }
	x = 300
	y = 400
	z = 1
	img = love.graphics.newImage("res/tinyship.png")
	img_normal = love.graphics.newImage("res/tinyship_normal.png")
	img_glow = love.graphics.newImage("res/tinyship_glow.png")
	lightWorld = LightWorld({
		ambient = {55,55,55},
		refractionStrength = 32.0,
		refractionVisibility = 0.75,
		shadowBlur = 0.0
	})
	sunLight = lightWorld:newLight(0,0,255,127,63,500)
	sunLight:setPosition(300,350,1)
	sunLight:setGlowStrength(0.3)
	sunLight:setVisible(true)
	sunLight:setRange(300)
	playerImageTest = lightWorld:newImage(img, x, y)
	playerImageTest:setNormalMap(img_normal)
	playerImageTest:setGlowMap(img_glow)
end

function love.update(dt)
	lightWorld:update(dt)
	sunLight:setPosition(200/camera.scale, 200/camera.scale, z)
end

function love.draw()
	love.graphics.setBackgroundColor(40,40,40)
	lightWorld:setTranslation(camera.x, camera.y, camera.scale)
	love.graphics.push()
    	love.graphics.translate(camera.x, camera.y)
    	love.graphics.scale(camera.scale)
    	lightWorld:draw(function()
    		love.graphics.setColor(255, 255, 255)
      		love.graphics.draw(img, x - img:getWidth() * 0.5, y - img:getHeight() * 0.5)
    	end)
  	love.graphics.pop()
  	love.graphics.setBlendMode("alpha")
end
This results in the following, even though I *think* the light should be right next to the ship.

Image

Like I say, I am probably missing something obvious. What am I doing wrong? Thanks!

Re: Löve "Light vs. Shadow" Engine v2

Posted: Sat Feb 28, 2015 2:41 am
by drunken_thor
Magicked wrote:This is a very noob question, but I'm trying to get a quick test to work and I am failing miserably. I'm sure I am missing something obvious. I just want to draw a tiny space ship and a light.

Code: Select all

local LightWorld = require "lib/lightworld"

function love.load(arg)
	camera = { x = 0, y = 0, scale = 1 }
	x = 300
	y = 400
	z = 1
	img = love.graphics.newImage("res/tinyship.png")
	img_normal = love.graphics.newImage("res/tinyship_normal.png")
	img_glow = love.graphics.newImage("res/tinyship_glow.png")
	lightWorld = LightWorld({
		ambient = {55,55,55},
		refractionStrength = 32.0,
		refractionVisibility = 0.75,
		shadowBlur = 0.0
	})
	sunLight = lightWorld:newLight(0,0,255,127,63,500)
	sunLight:setPosition(300,350,1)
	sunLight:setGlowStrength(0.3)
	sunLight:setVisible(true)
	sunLight:setRange(300)
	playerImageTest = lightWorld:newImage(img, x, y)
	playerImageTest:setNormalMap(img_normal)
	playerImageTest:setGlowMap(img_glow)
end

function love.update(dt)
	lightWorld:update(dt)
	sunLight:setPosition(200/camera.scale, 200/camera.scale, z)
end

function love.draw()
	love.graphics.setBackgroundColor(40,40,40)
	lightWorld:setTranslation(camera.x, camera.y, camera.scale)
	love.graphics.push()
    	love.graphics.translate(camera.x, camera.y)
    	love.graphics.scale(camera.scale)
    	lightWorld:draw(function()
    		love.graphics.setColor(255, 255, 255)
      		love.graphics.draw(img, x - img:getWidth() * 0.5, y - img:getHeight() * 0.5)
    	end)
  	love.graphics.pop()
  	love.graphics.setBlendMode("alpha")
end
This results in the following, even though I *think* the light should be right next to the ship.

Image

Like I say, I am probably missing something obvious. What am I doing wrong? Thanks!
This library works by blending the background with the lighting you need to draw a background of some sort (not just set the background color)