c++ - 返回值 1.#INF000

标签 c++

交集算法不起作用;其中一个值 tmin 的计算结果为 1.#INF000 - 这是什么意思,为什么会这样? tmax 似乎没问题。

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
}

最佳答案

1.#INF000 很可能是正无穷大。如果你得到这个,这意味着你的代码出现以下情况之一:

  • t1t2 都是无限的
  • t3t4 都是无限的
  • t5t6 都是无限的

我的猜测是您可能在某处除以零,最有可能是在计算 dirfrac 的值时。

关于c++ - 返回值 1.#INF000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8488841/

相关文章:

c++ - C++中string和char[]类型的区别

c++ - 如何用非类函数指针调用类成员函数?

c++ - 模拟模板的 C 错误

c++ - 在 C++ 中,不允许将对象直接传递给函数吗?

c++ - 使用迭代器的递归调用崩溃

c++ - mpg123 链接错误 "_read"和 "_lseek"

c++ - Mac OS X 上的 iconv 库 : strange behavior

c++ - "Link executables with xxx.lib"是什么意思

c++ - 在 MFC 中访问多个编辑框

c# - 如何从 C++/C# 与 silverlight 网站交互