equal
deleted
inserted
replaced
75 /* http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter3.htm */ |
75 /* http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter3.htm */ |
76 bool BBox::intersect(const Ray &ray, Float &a, Float &b) const |
76 bool BBox::intersect(const Ray &ray, Float &a, Float &b) const |
77 { |
77 { |
78 register Float tnear = -Inf; |
78 register Float tnear = -Inf; |
79 register Float tfar = Inf; |
79 register Float tfar = Inf; |
80 register Float t1, t2; |
80 register Float t1, t2, t; |
81 |
81 |
82 for (int i = 0; i < 3; i++) |
82 for (int i = 0; i < 3; i++) |
83 { |
83 { |
84 if (ray.dir[i] == 0) { |
84 if (ray.dir[i] == 0) { |
85 /* ray is parallel to these planes */ |
85 /* ray is parallel to these planes */ |
90 /* compute the intersection distance of the planes */ |
90 /* compute the intersection distance of the planes */ |
91 t1 = (L[i] - ray.o[i]) / ray.dir[i]; |
91 t1 = (L[i] - ray.o[i]) / ray.dir[i]; |
92 t2 = (H[i] - ray.o[i]) / ray.dir[i]; |
92 t2 = (H[i] - ray.o[i]) / ray.dir[i]; |
93 |
93 |
94 if (t1 > t2) |
94 if (t1 > t2) |
95 swap(t1, t2); |
95 { |
|
96 t = t1; |
|
97 t1 = t2; |
|
98 t2 = t; |
|
99 } |
96 |
100 |
97 if (t1 > tnear) |
101 if (t1 > tnear) |
98 tnear = t1; /* want largest Tnear */ |
102 tnear = t1; /* want largest Tnear */ |
99 if (t2 < tfar) |
103 if (t2 < tfar) |
100 tfar = t2; /* want smallest Tfar */ |
104 tfar = t2; /* want smallest Tfar */ |