当前位置: 首页>>代码示例>>C++>>正文


C++ BBox::inside方法代码示例

本文整理汇总了C++中BBox::inside方法的典型用法代码示例。如果您正苦于以下问题:C++ BBox::inside方法的具体用法?C++ BBox::inside怎么用?C++ BBox::inside使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BBox的用法示例。


在下文中一共展示了BBox::inside方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: intersectKD

bool Mesh::intersectKD(KDTree& node, const BBox& box, const FastRay& ray, IntersectionInfo& info) const
{
	if (node.axis == AXIS_NONE) {
		vector<int>& trios = *node.data.triangles;
		double foundlambda2 = 0, foundlambda3 = 0, dist = INF;
		int foundIdx = -1;
		for (int i = 0; i < (int) trios.size(); i++) {
			const Triangle& t = triangles[trios[i]];
			double l2, l3;
			if (intersectTriangleFast(ray, vertices[t.v[0]], t, l2, l3, dist)) {
				foundIdx = trios[i];
				foundlambda2 = l2;
				foundlambda3 = l3;
			}
		}
		if (foundIdx != -1) {
			Vector ip = ray.start + ray.dir * dist;
			if (box.inside(ip)) {
				fillInfo(ray, info, foundIdx, foundlambda2, foundlambda3, dist);
				return true;
			}
		}
		return false;
	} else {
		BBox boxChild[2];
		box.split(node.axis, node.sp, boxChild[0], boxChild[1]);
		int order[2] = { 0, 1 };
		if (ray.start[node.axis] > node.sp) swap(order[0], order[1]);
		// if the ray intersects the common wall between the two sub-boxes, then it invariably
		// intersects both boxes (we can skip the testIntersect() checks):
		// (see http://raytracing-bg.net/?q=node/68 )
		if (box.intersectWall(node.axis, node.sp, ray)) {
			if (intersectKD(node.data.children[order[0]], boxChild[order[0]], ray, info)) return true;
			return intersectKD(node.data.children[order[1]], boxChild[order[1]], ray, info);
		} else {
			// if the wall isn't hit, then we intersect exclusively one of the sub-boxes;
			// test one, if the test fails, then it's in the other:
			if (boxChild[order[0]].testIntersect(ray))
				return intersectKD(node.data.children[order[0]], boxChild[order[0]], ray, info);
			else
				return intersectKD(node.data.children[order[1]], boxChild[order[1]], ray, info);
		}
	}
	return false;
}
开发者ID:zstoychev,项目名称:retrace-distributed,代码行数:45,代码来源:mesh.cpp

示例2: intersectKD

bool Mesh::intersectKD(KDTreeNode& node, const BBox& bbox, const Ray& ray, IntersectionData& data)
{
	if (node.axis == AXIS_NONE) {
		// leaf node; try intersecting with the triangle list:
		bool found = false;
		for (size_t i = 0; i < node.triangles->size(); i++) {
			int triIdx = (*node.triangles)[i];
			if (intersectTriangle(ray, data, triangles[triIdx])) {
				found = true;
			}
		}
		// the found intersection has to be inside "our" BBox, otherwise we can miss a triangle,
		// as explained in the presentations:
		if (found && bbox.inside(data.p)) return true;
		return false;
	} else {
		// a in-node; intersect with the two children, starting with the closer one first:
		int childOrder[2] = { 0, 1 };
		if (ray.start[node.axis] > node.splitPos)
			swap(childOrder[0], childOrder[1]);
		//
		BBox childBB[2];
		bbox.split(node.axis, node.splitPos, childBB[0], childBB[1]);
		// name the children bboxen:
		BBox& firstBB = childBB[childOrder[0]];
		BBox& secondBB = childBB[childOrder[1]];
		KDTreeNode& firstChild = node.children[childOrder[0]];
		KDTreeNode& secondChild = node.children[childOrder[1]];
		// if the ray intersects the common wall between the two sub-boxes, then it invariably
		// intersects both boxes (we can skip the testIntersect() checks):
		// (see http://raytracing-bg.net/?q=node/68 )
		if (bbox.intersectWall(node.axis, node.splitPos, ray)) {
			if (intersectKD(firstChild, firstBB, ray, data)) return true;
			return intersectKD(secondChild, secondBB, ray, data);
		} else {
			// if the wall isn't hit, then we intersect exclusively one of the sub-boxes;
			// test one, if the test fails, then it's in the other:
			if (firstBB.testIntersect(ray))
				return intersectKD(firstChild, firstBB, ray, data);
			else
				return intersectKD(secondChild, secondBB, ray, data);
		}
	}
}
开发者ID:nikoladimitroff,项目名称:trinity,代码行数:44,代码来源:mesh.cpp


注:本文中的BBox::inside方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。