Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. float rayAtDistanceFromOrigin(const Ray& r, float radius)
  2. {
  3. const float* d = r.getDirection();
  4. if (d[0] == 0.0 && d[1] == 0.0 && d[2] == 0.0) return 0.0f;
  5.  
  6. const float* p = r.getOrigin();
  7. const float a = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
  8. const float b = -(p[0] * d[0] + p[1] * d[1] + p[2] * d[2]);
  9. const float c = p[0] * p[0] + p[1] * p[1] + p[2] * p[2] - radius * radius;
  10. const float disc = b * b - a * c;
  11. if (disc < 0.0f) return -1.0f;
  12. const float d1_2 = sqrtf(disc);
  13. const float t0 = b + d1_2;
  14. const float t1 = b - d1_2;
  15. if (t0 < t1)
  16. if (t0 < 0.0f) return t1 / a;
  17. else return t0 / a;
  18. else
  19. if (t1 < 0.0) return t0 / a;
  20. else return t1 / a;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement