Skip to content

Commit

Permalink
[10190] Fix another numerical corner case...
Browse files Browse the repository at this point in the history
...hopefully the last one.
Slightly different approach to tree bound intersection.
  • Loading branch information
Lynx3d committed Jul 14, 2010
1 parent 999b5b9 commit 16e576a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10189"
#define REVISION_NR "10190"
#endif // __REVISION_NR_H__
34 changes: 19 additions & 15 deletions src/shared/vmap/BIH.h
Expand Up @@ -118,32 +118,36 @@ class BIH
template<typename RayCallback>
void intersectRay(const Ray &r, RayCallback& intersectCallback, float &maxDist, bool stopAtFirst=false) const
{
float intervalMin = 0.f;
float intervalMax = maxDist;
float intervalMin = -1.f;
float intervalMax = -1.f;
Vector3 org = r.origin();
Vector3 dir = r.direction();
Vector3 invDir;
float t1, t2;
for(int i=0; i<3; ++i)
for (int i=0; i<3; ++i)
{
invDir[i] = 1.f / dir[i];
t1 = (bounds.low()[i] - org[i]) * invDir[i];
t2 = (bounds.high()[i] - org[i]) * invDir[i];
if (invDir[i] > 0) {
if (dir[i] != 0.f)
{
float t1 = (bounds.low()[i] - org[i]) * invDir[i];
float t2 = (bounds.high()[i] - org[i]) * invDir[i];
if (t1 > t2)
std::swap(t1, t2);
if (t1 > intervalMin)
intervalMin = t1;
if (t2 < intervalMax)
if (t2 < intervalMax || intervalMax < 0.f)
intervalMax = t2;
} else {
if (t2 > intervalMin)
intervalMin = t2;
if (t1 < intervalMax)
intervalMax = t1;
// intervalMax can only become smaller for other axis,
// and intervalMin only larger respectively, so stop early
if (intervalMax <= 0 || intervalMin >= maxDist)
return;
}
if (intervalMin > intervalMax)
return;
}

if (intervalMin > intervalMax)
return;
intervalMin = std::max(intervalMin, 0.f);
intervalMax = std::min(intervalMax, maxDist);

uint32 offsetFront[3];
uint32 offsetBack[3];
uint32 offsetFront3[3];
Expand Down

0 comments on commit 16e576a

Please sign in to comment.