Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float rayAtDistanceFromOrigin(const Ray& r, float radius)
- {
- const float* d = r.getDirection();
- if (d[0] == 0.0 && d[1] == 0.0 && d[2] == 0.0) return 0.0f;
- const float* p = r.getOrigin();
- const float a = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
- const float b = -(p[0] * d[0] + p[1] * d[1] + p[2] * d[2]);
- const float c = p[0] * p[0] + p[1] * p[1] + p[2] * p[2] - radius * radius;
- const float disc = b * b - a * c;
- if (disc < 0.0f) return -1.0f;
- const float d1_2 = sqrtf(disc);
- const float t0 = b + d1_2;
- const float t1 = b - d1_2;
- if (t0 < t1)
- if (t0 < 0.0f) return t1 / a;
- else return t0 / a;
- else
- if (t1 < 0.0) return t0 / a;
- else return t1 / a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement