Improved smoke trace

This commit is contained in:
INeedBots 2020-12-19 13:07:34 -06:00
parent 8ec8b4d9ca
commit 59ba4c1713

View File

@ -532,9 +532,19 @@ notifyAfterDelay(delay, not)
/* /*
Pezbot's line sphere intersection. Pezbot's line sphere intersection.
http://paulbourke.net/geometry/circlesphere/raysphere.c
*/ */
RaySphereIntersect(start, end, spherePos, radius) RaySphereIntersect(start, end, spherePos, radius)
{ {
// check if the start or end points are in the sphere
r2 = radius * radius;
if (DistanceSquared(start, spherePos) < r2)
return true;
if (DistanceSquared(end, spherePos) < r2)
return true;
// check if the line made by start and end intersect the sphere
dp = end - start; dp = end - start;
a = dp[0] * dp[0] + dp[1] * dp[1] + dp[2] * dp[2]; a = dp[0] * dp[0] + dp[1] * dp[1] + dp[2] * dp[2];
b = 2 * (dp[0] * (start[0] - spherePos[0]) + dp[1] * (start[1] - spherePos[1]) + dp[2] * (start[2] - spherePos[2])); b = 2 * (dp[0] * (start[0] - spherePos[0]) + dp[1] * (start[1] - spherePos[1]) + dp[2] * (start[2] - spherePos[2]));
@ -544,7 +554,29 @@ RaySphereIntersect(start, end, spherePos, radius)
c -= radius * radius; c -= radius * radius;
bb4ac = b * b - 4.0 * a * c; bb4ac = b * b - 4.0 * a * c;
return (bb4ac >= 0); if (abs(a) < 0.0001 || bb4ac < 0)
return false;
mu1 = (0-b + sqrt(bb4ac)) / (2 * a);
//mu2 = (0-b - sqrt(bb4ac)) / (2 * a);
// intersection points of the sphere
ip1 = start + mu1 * dp;
//ip2 = start + mu2 * dp;
myDist = DistanceSquared(start, end);
// check if both intersection points far
if (DistanceSquared(start, ip1) > myDist/* && DistanceSquared(start, ip2) > myDist*/)
return false;
dpAngles = VectorToAngles(dp);
// check if the point is behind us
if (getConeDot(ip1, start, dpAngles) < 0/* || getConeDot(ip2, start, dpAngles) < 0*/)
return false;
return true;
} }
/* /*