Author Topic: How to improve math skills?  (Read 21616 times)

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: How to improve math skills?
« Reply #45 on: May 10, 2015, 08:42:32 AM »
http://koti.mbnet.fi/paulkp/temp/falloffs.png

Let's look at this properly with an illustrative image (link above).
Inverse square (=realistic light falloff) (roughly pictured at left) falloff makes the first tile bright, then following tiles are really dark. Linear falloff is easy and it can be used in the interpolation easily by calculating the dimming value for the length of the line (I'm using line drawing in light routine to shoot rays of light).
(Note: when using only an equation with line's loop value the result is a rectangular light area!)
The right side falloff is what I want. First tiles are bright, then drops quite fast to darkness, giving somewhat smooth edges from light to dark.
But I don't know how to calculate that kind of falloff curve inside the line drawing with "loop" value as the distance. (Note: the distance in circular form is different than the raw loop value. Hence when using simple equation the result is a rectangle.)

reaver

  • Rogueliker
  • ***
  • Posts: 207
  • Karma: +0/-0
    • View Profile
Re: How to improve math skills?
« Reply #46 on: May 10, 2015, 11:29:50 AM »
Use this then

https://www.desmos.com/calculator/29oyym8myd

The shape that you see is for 1-x^4, you can play around with the "b" parameter to get the shape that you want
You can multiply the function by the maximum distance, as in the graph that I gave you always goes to zero at x=1.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: How to improve math skills?
« Reply #47 on: June 17, 2015, 01:47:39 PM »
Well, finally I was able to do something about this. I was using a fractional value to increase X to get smoother (non-square) falloff for the area, but it's still kind of square-ish (ix and add_x variables). Also, I noticed that using 4.0 for power was way too much (I ended up using 1.2), because there just aren't enough tiles to show the falloff! Instead I was using a condition to start increase X after one run of loop to get the block around the player in full light. But I guess it's the reason the light is more rectangle shaped that I hoped.

Code: [Select]
double ix=0.0;
const double add_x=(float)1.0f/(loop-1);

for (int t=0; t<loop; t++)
{
r.x=Function::round(x);
r.y=Function::round(y);

int i=Get_Index(r);
if (i==-1) break;

double tx=pow(ix, 1.2);
int iv=(int)(light_value*(1.0-(tx*tx)));

tilemap[i].Set_Light_Value(iv);
if (t>0 && tilemap[i].Determine_Los_Value()!=fovVisible) break;

x+=x_inc;
y+=y_inc;

if (t>0) ix+=add_x;
}

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: How to improve math skills?
« Reply #48 on: June 18, 2015, 07:34:29 AM »
I think this could also be done entirely without math by creating precalculated paths for the lighting routine and also the data for intensity of light, because lights spots in this game are small and there is a maximum size for light spots.