Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value returning 1.#INF000

Tags:

c++

An intersection algorithm isn't working; one of the values, tmin, evaluates to 1.#INF000 - what does this mean and why is it occurring? tmax seems to be fine.

float Ray::Intersects(BoundingBox boundingBox)
{
// direction is unit direction vector of the ray
D3DXVECTOR3 dirfrac(
    1.0f / direction.x,
    1.0f / direction.y,
    1.0f / direction.z);

D3DXVECTOR3 min = boundingBox.Min();
D3DXVECTOR3 max = boundingBox.Max();

//min and max are the negative and positive corners of the bounding box
float t1 = (min.x - origin.x) * dirfrac.x;
float t2 = (max.x - origin.x) * dirfrac.x;
float t3 = (min.y - origin.y) * dirfrac.y;
float t4 = (max.y - origin.y) * dirfrac.y;
float t5 = (min.z - origin.z) * dirfrac.z;
float t6 = (max.z - origin.z) * dirfrac.z;

float tmin = max(max(min(t1, t2), min(t3, t4)), min(t5, t6));
float tmax = min(min(max(t1, t2), max(t3, t4)), max(t5, t6));

// if tmax < 0, ray (line) is intersecting AABB, but whole AABB is behind us
if (tmax < 0) { return -1; }

// if tmin > tmax, ray doesn't intersect AABB
if (tmin > tmax) { return -1; } //HERE TMIN IS 1.#INFOOO

return tmin; //THIS IS NEVER REACHED
}
like image 363
Dollarslice Avatar asked Mar 07 '26 23:03

Dollarslice


1 Answers

1.#INF000 is most likely the positive infinity. If you are getting this, it means one of the following in case of your code:

  • t1 and t2 are both infinite
  • t3 and t4 are both infinite
  • t5 and t6 are both infinite

My guess is that you are probably dividing by zero somewhere, most likely when you calculate the value of dirfrac.

like image 139
Tamás Avatar answered Mar 10 '26 12:03

Tamás