【问题标题】:Value returning 1.#INF000返回值 1.#INF000
【发布时间】:2011-12-13 11:58:39
【问题描述】:

相交算法不起作用;其中一个值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
}

【问题讨论】:

    标签: c++


    【解决方案1】:

    1.#INF000 很可能是正无穷大。如果您收到此信息,则表示您的代码存在以下情况之一:

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

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

    【讨论】:

    • 啊,是的,光线方向在z轴上为0,所以dirfrac的z分量变得无限。
    猜你喜欢
    • 1970-01-01
    • 2018-08-28
    • 2016-02-12
    • 2018-01-17
    • 1970-01-01
    • 1970-01-01
    • 2013-01-17
    • 2011-12-27
    • 2017-08-10
    相关资源
    最近更新 更多