加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 返回值1.#INF000

发布时间:2020-12-16 09:39:08 所属栏目:百科 来源:网络整理
导读:交集算法不起作用;其中一个值tmin,评估为1.#INF000 – 这意味着什么,为什么会发生? tmax似乎很好. float Ray::Intersects(BoundingBox boundingBox){// direction is unit direction vector of the rayD3DXVECTOR3 dirfrac( 1.0f / direction.x,1.0f / dire
交集算法不起作用;其中一个值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,max(t3,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很可能是正无穷大.如果你得到这个,那么就你的代码而言,这意味着下列之一:

> t1和t2都是无限的
> t3和t4都是无限的
> t5和t6都是无限的

我的猜测是你可能在某个地方除以零,最有可能的是你计算dirfrac的值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读