I have a idea on how one can implement lighting of sorts :

First we need to have a emitter of light and give it some important values :

Code: Select all

```
love.load()
MyEmitter = {}
MyEmitter.xPos = 2
MyEmitter.yPos = 2
MyEmitter.angle = 45 --This is important as it sets the direction the light is emitted
MyEmitter.max_angle = 15 -- This is the maximum angle the light will be emitted at, the true maximum is MyEmitter.angle+MyEmitter.max_angle
MyEmitter.min_angle = -15 -- This is the same as above but is the minimum, thus : MyEmitter.angle+MyEmitter.min_angle
MyEmitter.intensity = 50 -- this is the maximum range that the light will be traveling
end
```

Code: Select all

```
function EmitLight(emitter)
emitter.min_angle = math.rad(emitter.min_angle)
emitter.max_angle = math.rad(emitter.max_angle)
emitter.angle = math.rad(emitter.angle)
tbl = {}
points = {}
increment = emitter.angle+emitter.min_angle
break_Loop_angles = false
while(increment < emitter.angle+emitter.max_angle) and not break_Loop_angles do -- here we loop until all angles between the max and min are used.
for dx = 0,emitter.intensity do -- loop until intensity maxed out
local x_check = (dx*math.cos(increment))+emitter.xPos -- this gets the xPoint of the current angle at the current distance(dx)
local y_check = (dx*math.sin(increment))+emitter.yPos -- this gets the yPoint of the current angle at the current distance(dx)
table.insert(points,x_check)
table.insert(points,y_check)
end
increment = increment+math.rad(1) --- TAKE NOT OF THIS LINE FOR BELOW
end
return points
end
```

This line i found to be important as the LOWER the number we increment by the more filled and accurate our cone of light is.

I found that 0.1 is abit better, 0.01 is incredibly good but extremely slow and 0.001 is absolutely filled cone but can just about crash the program!

Ok so we want to render our cone :

Code: Select all

```
love.update(dt)
if love.keyboard.isDown("f") then
myCone = EmitLight(MyEmitter)
end
end
love.draw()
if myCone then
love.graphics.polygon("fill",myCone)
end
end
```

Firstly if we pass a table of objects to check against we can make some light get obstructed. During the intensity(dx) loop we loop through all objects and compare the x/y_check with that objects x,y. Should they match then the point isnt added to points and we move onto the next angle since no more "light" will be beyond that point.

Next is focus on the increment. Setting it lower makes the cone more filled, yet anywhere below 1 (and even 1) just lags out alot.

I have absolutely no idea how to combat this.

Lastly there is the drawing of the cone, when using lower increments like 0.1 etc the drawing of the points is insane.

To combat this i think taking all the points and then converting them into a more clean poly gon that fills in just as muh would be a good way to optimize this. It may even help with needing lower increments for more filled cones.

So far im unsure on whether this is a good wayto look at for lighting idea, but its one i think is pretty different from what i know. Also i think what i do in EmitLight is similar to rayCasting but im unsure...

Anyways, please feel free to discuss this and provide feedback, BUT remember : my goal above was to work on a way to make light in games and this is also a practice session involving love.physics and angles.

IF any explanation is required for anything regarding my idea is needed ill gladly provide.

-end-