summaryrefslogtreecommitdiff
path: root/src/simulation/elements/LIGH.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-07-25 17:25:37 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-07-25 17:25:37 (GMT)
commit41cbd69ac807b79919649865293de2af8c50cbf7 (patch)
tree66d13f43cfec7d8abdca032c420072a6600605f0 /src/simulation/elements/LIGH.cpp
parentde4fe1a38ec1114c384ddbb5ab68c7aa22541eed (diff)
downloadpowder-41cbd69ac807b79919649865293de2af8c50cbf7.zip
powder-41cbd69ac807b79919649865293de2af8c50cbf7.tar.gz
TPT: Use atan2 for LIGH angle calculations 966f1dcc23
Diffstat (limited to 'src/simulation/elements/LIGH.cpp')
-rw-r--r--src/simulation/elements/LIGH.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/simulation/elements/LIGH.cpp b/src/simulation/elements/LIGH.cpp
index 0000f64..d413d29 100644
--- a/src/simulation/elements/LIGH.cpp
+++ b/src/simulation/elements/LIGH.cpp
@@ -155,15 +155,19 @@ int Element_LIGH::update(UPDATE_FUNC_ARGS)
{
int t=parts[pNear].type;
float n_angle; // angle to nearest part
+ float angle_diff;
rx=parts[pNear].x-x;
ry=parts[pNear].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(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, parts[i].tmp-90, 0);