本文整理汇总了C++中Intersection::nullPrimitive方法的典型用法代码示例。如果您正苦于以下问题:C++ Intersection::nullPrimitive方法的具体用法?C++ Intersection::nullPrimitive怎么用?C++ Intersection::nullPrimitive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intersection
的用法示例。
在下文中一共展示了Intersection::nullPrimitive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: intersectWithPrims
/**
* Implementation of TA^B_{rec}
* Algorithm is described in http://www.cgg.cvut.cz/~havran/phdthesis.html
*/
Intersection KdTreePrimitiveManager::intersectWithPrims(const Ray& ray) const {
StackElem stack[64];
Node* far;
Node* cur = m_root;
floating a, b, t;
int en = 0, ex = 1, tmp;
if (!intersectAabb(m_bbox, ray, a, b)) {
return {};
}
stack[en].t = a;
stack[en].pb = ray.origin();
if (a >= 0.0) {
stack[en].pb += ray.dir() * a;
}
stack[ex].t = b;
stack[ex].pb = ray.origin() + ray.dir() * b;
stack[ex].node = nullptr;
while (cur != nullptr) {
while (cur->m_axis < 3) {
const float split = cur->m_split;
uint8_t axis = cur->m_axis;
if (stack[en].pb[axis] < split) {
if (stack[ex].pb[axis] < split) {
cur = cur->m_left;
continue;
}
far = cur->m_right;
cur = cur->m_left;
} else {
if (stack[ex].pb[axis] > split) {
cur = cur->m_right;
continue;
}
far = cur->m_left;
cur = cur->m_right;
}
t = (split - ray.origin(axis)) / ray.dir(axis);
tmp = ex;
++ex;
if (ex == en)
++ex;
stack[ex].prev = tmp;
stack[ex].t = t;
stack[ex].node = far;
stack[ex].pb[axis] = split;
axis = (axis + 1) % 3;
stack[ex].pb[axis] = ray.origin(axis) + t * ray.dir(axis);
axis = (axis + 1) % 3;
stack[ex].pb[axis] = ray.origin(axis) + t * ray.dir(axis);
}
{
Intersection intr;
for (PrimPtr *ptr = cur->prims(); *ptr; ++ptr) {
auto prim = *ptr;
prim->intersect(ray, intr);
if (intr.hasIntersections()) {
if (intr.dist() < stack[en].t - epsilon ||
intr.dist() > stack[ex].t + epsilon) {
intr.nullPrimitive();
}
}
}
if (intr.hasIntersections()) {
return intr;
}
}
en = ex;
cur = stack[ex].node;
ex = stack[en].prev;
}
return {};
}