2011-12-13 170 views
3

的交叉算法不工作;其中一个值,tmin,计算结果为1.#INF000 - 这是什么?它为什么发生这意味着什么? tmax似乎是罚款。值返回1.#INF000

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 
} 

回答

7

1.#INF000最有可能是正无穷。如果您遇到这种情况,意味着在你的代码的情况下,执行下列操作之一:

  • t1t2均为无限
  • t3t4都无限
  • t5t6都无限

我的猜测是,你可能被零除地方,最有可能当你计算dirfrac值。

+0

啊是,光线方向在z轴0所以dirfrac的z分量变得无限大。 – SirYakalot