tanema / light_world.lua

A lighting model made for love 2d
https://love2d.org/forums/viewtopic.php?f=5&t=78998
MIT License
223 stars 18 forks source link

lightworld rotation scaling issues (lights will not rotate) #33

Open RichardEllicott opened 7 years ago

RichardEllicott commented 7 years ago

okay, i have confirmed lightworld rotates (sort of), if i put in the love.graphics.rotate into the actual lightworld function bit, in my code, in ee_engine.lua:


lightWorld:draw(function() --this is the lightworld pass

            love.graphics.rotate(camera.rotation)

            for _,entity in pairs(self.entities) do
                entity:lightdraw()
            end
        end)

i found if i omit, the scaling and translation, it is the closest to working correctly.

i found also, the sequence is important, so lightworld has received the scaling and translation, it is important other draws follow the same sequence (rotation MUST be last)

this investigation suggests the code on the main page might be wrong?? you are not supposed to scale and translate in love.draw()

Please, have a look at my code, at least try using the controls to see. It has WSAD directions, QE scale, and RF rotate.

You can switch on (in ee_engine.lua) a non-lightpass, with Engine.draw_non_lightpass = true

I have managed to get both passes to exactly match each other.

Sorry i am so long winded, the fundamental issue is, the lights do not rotate with the scene, if you rotate my (attempted) camera, you will find the lights do not rotate (so lightworld sprites rotate fine, it's lights do not).

EntityEngine.zip

This little framework, i was hoping to integrate all this stuff, light, physics, camera, and eventually UDP, into one thing bases on the usual sort of Unity style component model. The best bit so far is the physics are optional :)

Summary of code: main.lua ee_engine.lua --the singleton ee_entity.lua --the in game objects

RichardEllicott commented 7 years ago

i still kinda like this product and think i might just decide not to use rotation, but it would be nice to solve this, and i may have highlighted someting strange about setting translations to the lightworld:

lightWorld:update(dt)
  lightWorld:setTranslation(x, y, scale)

when you're also then doing it again in:

love.graphics.translate(x, y)
    love.graphics.scale(scale)

in my attached example, i do not make them two second ones (except for non-lightworld pass).... i have managed to make it all line up!

RichardEllicott commented 7 years ago

also my code is free as in free, if any code i made was useful to people i'd be honoured to have helped (but it may not be to people's tastes here as they tend to make these bits themselves)

RichardEllicott commented 7 years ago

in love 2d, the official way to make the sequence is:

translate rotate scale

to line things up correct, translate needs to occur first i believe (rotate and scale could be interchanged in sequence)... this is handy, as lightdraw will only rotate it appears if you chuck the rotate inside it?

something is not right with this, perhaps it's a shame that lightworld could not be a fundamental part of love 2d itself, i feel this would be the best thing, we're trying to line up a now very complicated sequence of translations