本文整理汇总了C++中BVHNode::GetRightChild方法的典型用法代码示例。如果您正苦于以下问题:C++ BVHNode::GetRightChild方法的具体用法?C++ BVHNode::GetRightChild怎么用?C++ BVHNode::GetRightChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BVHNode
的用法示例。
在下文中一共展示了BVHNode::GetRightChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ItrIntersect
/**
* Iteratively intersect rays with the given nodes and returns the distance to
* the closest intersection and stores the id of the intersected sphere in
* sphereId.
*/
inline float ItrIntersect(const Ray charles, const vector<BVHNode>& nodes,
const vector<Sphere> spheres, unsigned int &sphereId) {
// cout << "=== ItrIntersect:" << charles.ToString() << " ===" << endl;
sphereId = -1;
float t = 1e30f;
vector<std::pair<int, float> > stack(60);
int i = 0;
stack[i] = std::pair<int, float>(0, 0.0f);
do {
// cout << "\n----" << endl;
// for (int j = i; j >= 0; --j)
// cout << "| " << j << ": " << stack[j].second << " - " << nodes[stack[j].first].ToString() << endl;
// cout << "----" << endl;
std::pair<int, float> next = stack[i]; --i;
if (t < next.second) {
// cout << i << "discard: " << nodes[next.first].ToString() << endl;
continue;
}
BVHNode currentNode = nodes[next.first];
if (currentNode.GetType() == BVHNode::LEAF) // Intersect leaf
t = Exhaustive(charles, t, currentNode, spheres, sphereId);
else {
rayAABBCheck += 2;
const BVHNode& left = nodes[currentNode.GetLeftChild()];
float tLeft;
if (!left.aabb.ClosestIntersection(charles, tLeft)) tLeft = 1e32f;
const BVHNode& right = nodes[currentNode.GetRightChild()];
float tRight;
if (!right.aabb.ClosestIntersection(charles, tRight)) tRight = 1e32f;
if (tLeft < tRight) { // Intersect left first
if (tRight < t) stack[++i] = std::pair<int, float>(currentNode.GetRightChild(), tRight);
if (tLeft < t) stack[++i] = std::pair<int, float>(currentNode.GetLeftChild(), tLeft);
} else { // Intersect right first
if (tLeft < t) stack[++i] = std::pair<int, float>(currentNode.GetLeftChild(), tLeft);
if (tRight < t) stack[++i] = std::pair<int, float>(currentNode.GetRightChild(), tRight);
}
}
} while (i >= 0);
return t;
}
示例2: Intersect
/**
* Recursively intersects Ray Charles with his node and returns the distance to
* the closest intersection and a stores the id of the sphere in sphereId.
*/
inline float Intersect(const Ray charles, float t,
const BVHNode& node, const vector<BVHNode>& nodes,
const vector<Sphere> spheres, unsigned int &sphereId) {
if (node.GetType() == BVHNode::LEAF) {
// Intersect leaf
return Exhaustive(charles, t, node, spheres, sphereId);
} else {
// Traverse further
const BVHNode left = nodes[node.GetLeftChild()];
float tLeft;
if (!left.aabb.ClosestIntersection(charles, tLeft)) tLeft = 1e32f;
const BVHNode right = nodes[node.GetRightChild()];
float tRight;
if (!right.aabb.ClosestIntersection(charles, tRight)) tRight = 1e32f;
if (tLeft < tRight) { // Intersect left first
if (tLeft < t) t = Intersect(charles, t, left, nodes, spheres, sphereId);
if (tRight < t) t = Intersect(charles, t, right, nodes, spheres, sphereId);
} else { // Intersect right first
if (tRight < t) t = Intersect(charles, t, right, nodes, spheres, sphereId);
if (tLeft < t) t = Intersect(charles, t, left, nodes, spheres, sphereId);
}
return t;
}
}