Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1.     bool ray_intersect(pixel point, pixel direction, float& dist) {
  2.         pixel vpc = sub(center, point);
  3.         float thc;
  4.         float tca;
  5.         float d;
  6.         tca = cdot(vpc, direction);
  7.         d = cdot(vpc, vpc) - tca * tca;
  8.         thc = sqrtf(radius * radius - d);
  9.         float nvpc = norm(vpc);
  10.         if (tca < 0) {
  11.             if (nvpc > radius) {
  12.                 return false;
  13.             }
  14.             else if (nvpc == radius) {
  15.                 dist = 0;
  16.                 return true;
  17.             }
  18.             else {
  19.                 dist = thc - tca;
  20.                 return true;
  21.             }
  22.         }
  23.         else {
  24.             if (d > radius * radius) {
  25.                 return false;
  26.             }
  27.             else {
  28.                 if (nvpc > radius) {
  29.                     dist = tca - thc;
  30.                     return true;
  31.                 }
  32.                 else {
  33.                     dist = tca + thc;
  34.                     return true;
  35.                 }
  36.             }
  37.         }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement