diff options
| author | jacksonmj <mj-pt@jacksonmj.co.uk> | 2012-06-28 23:04:46 (GMT) |
|---|---|---|
| committer | jacksonmj <mj-pt@jacksonmj.co.uk> | 2012-06-28 23:04:46 (GMT) |
| commit | 966f1dcc235d65943d14e2a99058de709a15659a (patch) | |
| tree | 443e006634ed5f5065661b9257ecdc9ad0d8e6ef /src/elements/ligh.c | |
| parent | 167740e83926c233b108ada9ca770f6adaf312dd (diff) | |
| download | powder-966f1dcc235d65943d14e2a99058de709a15659a.zip powder-966f1dcc235d65943d14e2a99058de709a15659a.tar.gz | |
Use atan2 for LIGH angle calculations
atan2 gives the actual angle (in the range -pi to pi). acos and asin just
give the principal value (in the range 0 to pi, or -pi/2 to pi/2)
Diffstat (limited to 'src/elements/ligh.c')
| -rw-r--r-- | src/elements/ligh.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/elements/ligh.c b/src/elements/ligh.c index a17954f..31f53b3 100644 --- a/src/elements/ligh.c +++ b/src/elements/ligh.c @@ -217,15 +217,19 @@ int update_LIGH(UPDATE_FUNC_ARGS) { int t=parts[near].type; float n_angle; // angle to nearest part + float angle_diff; rx=parts[near].x-x; ry=parts[near].y-y; - if (rx*rx+ry*ry!=0) - n_angle = asin(-ry/sqrt(rx*rx+ry*ry)); + if (rx!=0 || ry!=0) + n_angle = atan2f(-ry, rx); else n_angle = 0; if (n_angle<0) 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(x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, parts[i].tmp-90, 0); |
