Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool ray_intersect(pixel point, pixel direction, float& dist) {
- pixel vpc = sub(center, point);
- float thc;
- float tca;
- float d;
- tca = cdot(vpc, direction);
- d = cdot(vpc, vpc) - tca * tca;
- thc = sqrtf(radius * radius - d);
- float nvpc = norm(vpc);
- if (tca < 0) {
- if (nvpc > radius) {
- return false;
- }
- else if (nvpc == radius) {
- dist = 0;
- return true;
- }
- else {
- dist = thc - tca;
- return true;
- }
- }
- else {
- if (d > radius * radius) {
- return false;
- }
- else {
- if (nvpc > radius) {
- dist = tca - thc;
- return true;
- }
- else {
- dist = tca + thc;
- return true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement