TPT: Use atan2 for LIGH angle calculations 966f1dcc23

This commit is contained in:
Simon Robertshaw 2012-07-25 18:25:37 +01:00
parent de4fe1a38e
commit 41cbd69ac8
2 changed files with 9 additions and 7 deletions

View File

@ -155,15 +155,19 @@ int Element_LIGH::update(UPDATE_FUNC_ARGS)
{ {
int t=parts[pNear].type; int t=parts[pNear].type;
float n_angle; // angle to nearest part float n_angle; // angle to nearest part
float angle_diff;
rx=parts[pNear].x-x; rx=parts[pNear].x-x;
ry=parts[pNear].y-y; ry=parts[pNear].y-y;
if (rx*rx+ry*ry!=0) if (rx!=0 || ry!=0)
n_angle = asin(-ry/sqrt(rx*rx+ry*ry)); n_angle = atan2f(-ry, rx);
else else
n_angle = 0; n_angle = 0;
if (n_angle<0) if (n_angle<0)
n_angle+=M_PI*2; n_angle+=M_PI*2;
if (parts[i].life<5 || fabs(n_angle-parts[i].tmp*M_PI/180)<M_PI*0.8) // lightning strike angle_diff = fabsf(n_angle-parts[i].tmp*M_PI/180);
if (angle_diff>M_PI)
angle_diff = M_PI*2 - angle_diff;
if (parts[i].life<5 || angle_diff<M_PI*0.8) // lightning strike
{ {
create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, parts[i].tmp-90, 0); create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, parts[i].tmp-90, 0);

View File

@ -111,19 +111,17 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (r) if (r)
continue; continue;
if (rand()%(parts[i].tmp*parts[i].tmp/20+6)==0) if (parts[i].tmp>4 && rand()%(parts[i].tmp*parts[i].tmp/20+6)==0)
{ {
int p = sim->create_part(-1, x+rx*2, y+ry*2, PT_LIGH); int p = sim->create_part(-1, x+rx*2, y+ry*2, PT_LIGH);
if (p!=-1) if (p!=-1)
{ {
if(parts[i].tmp<=4) //Prevent Arithmetic errors with zero values
continue;
parts[p].life=rand()%(2+parts[i].tmp/15)+parts[i].tmp/7; parts[p].life=rand()%(2+parts[i].tmp/15)+parts[i].tmp/7;
if (parts[i].life>60) if (parts[i].life>60)
parts[i].life=60; parts[i].life=60;
parts[p].temp=parts[p].life*parts[i].tmp/2.5; parts[p].temp=parts[p].life*parts[i].tmp/2.5;
parts[p].tmp2=1; parts[p].tmp2=1;
parts[p].tmp=acos(1.0*rx/sqrt(rx*rx+ry*ry))/M_PI*360; parts[p].tmp=atan2(-ry, rx)/M_PI*360;
parts[i].temp-=parts[i].tmp*2+parts[i].temp/5; // slight self-cooling parts[i].temp-=parts[i].tmp*2+parts[i].temp/5; // slight self-cooling
if (fabs(sim->pv[y/CELL][x/CELL])!=0.0f) if (fabs(sim->pv[y/CELL][x/CELL])!=0.0f)
{ {