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


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

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


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

示例1: dir

// get/update camera from values in node
GvBool	GvViewpoint::getCamera(GCamera &camera, 
							   BBox &bbox,
							   float visibilityLimitNear,float visibilityLimit,
							   Matrix *cameraTransform)
{
	Matrix m;
    float viewAngle = 0.785398;
	float aspectRatio = 1.0f;
    orientation.get(m);
	camera.position=position;
    viewAngle = (float) fieldOfView;
	Point dir(0,0,-1.0);
	Point up(0,1.0,0);
			
    // apply orientation to standard dir and up vectors
    dir *= m;	
	up *= m;	up.Normalize();
			
    if (cameraTransform) {
        camera.position *= *cameraTransform;
        dir = RotateOnly(*cameraTransform,dir);
        up = RotateOnly(*cameraTransform,up);
        // near far focalDistance ??????????
    }
    dir.Normalize();
    up.Normalize();

	Point size = bbox.Size(); // computed bounding box
		    
	float field = max(max(fabs(size.x),fabs(size.y)),fabs(size.z));
			
	int positionInBox = bbox.Inside(camera.position);
  			
	if (bbox.IsEmpty() || (field<=1E-20f)) 
		field = 2.0f; // no bounding box yet, bad 
  			
            // compute distance to target point
  			//xx float targetDistance = field*2.0f;
  			float targetDistance = field*1.0f;
			
			// viewpoint inside scene 
			if (positionInBox) targetDistance = 0.2 * field; 

            camera.targetDistanceIsDefault=1;
            camera.zrangeIsDefault=1;

            // compute a reasonable z-range 

				if (visibilityLimit >0.0f) {
					camera.zfar = visibilityLimit;
					camera.zrangeIsDefault=0;
				}
				else {
					if (positionInBox) 
						camera.zfar = field*1.5;
					else camera.zfar = field*3.0f;
					
					Point center = bbox.Center();
					Point d = camera.position - center;
					float dist = d.Length();
					
					// make shure object is visible from viewpoint 
					if ((dist+field) > camera.zfar)
						camera.zfar = dist + field;

				}

				if (visibilityLimitNear > 0.0f)
				    camera.znear = visibilityLimitNear;
				else 
					 camera.znear = camera.zfar * camera.znearFactor;

            // compute target 
			camera.target = camera.position + targetDistance*dir;
			camera.up = up;

            // field of view 
			camera.height = 2.0 * tan(viewAngle * 0.5)*targetDistance;
			camera.width = camera.height *  aspectRatio;

			if (!bbox.IsEmpty())
				camera.SetWorldReference(bbox);

			camera.ComputeWorldUpFromUp(); 

            camera.OnChanged();

	return gtrue;

}
开发者ID:deepmatrix,项目名称:blaxxun-cc3d,代码行数:91,代码来源:gvperspectivecamera.cpp

示例2: FindSplit

void DBVH::FindSplit(int nNode, int first, int count, int sdepth) {
	BBox bbox = nodes[nNode].bbox;

	if(count <= 1) {
	LEAF_NODE:
		depth = Max(depth, sdepth);
		nodes[nNode].first = first | 0x80000000;
		nodes[nNode].count = count;
	}
	else {
		int minAxis = MaxAxis(bbox.Size());
		const float traverseCost = 0.0;
		const float intersectCost = 1.0;

		struct Bin {
			Bin() :count(0) {
				box.min = Vec3f(constant::inf, constant::inf, constant::inf);
				box.max = Vec3f(-constant::inf, -constant::inf, -constant::inf);
			}

			BBox box;
			int count;
		};

		int nBins = count < 8? 8 : 16;
		Bin bins[nBins];

		float mul = nBins * (1.0f - constant::epsilon) /
			((&bbox.max.x)[minAxis] - (&bbox.min.x)[minAxis]);
		float sub = (&bbox.min.x)[minAxis];

		for(int n = 0; n < count; n++) {
			const BBox &box = elements[first + n].GetBBox();
			float c = ((&box.max.x)[minAxis] + (&box.min.x)[minAxis]) * 0.5f;
			int nBin = int( (c - sub) * mul );
			bins[nBin].count++;
			bins[nBin].box += box;
		}

		BBox leftBoxes[nBins], rightBoxes[nBins];
		int leftCounts[nBins], rightCounts[nBins];

		rightBoxes[nBins - 1] = bins[nBins - 1].box;
		rightCounts[nBins - 1] = bins[nBins - 1].count;
		leftBoxes[0] = bins[0].box;
		leftCounts[0] = bins[0].count;

		for(size_t n = 1; n < nBins; n++) {
			leftBoxes[n] = leftBoxes[n - 1] + bins[n].box;
			leftCounts[n] = leftCounts[n - 1] + bins[n].count;
		}
		for(int n = nBins - 2; n >= 0; n--) {
			rightBoxes[n] = rightBoxes[n + 1] + bins[n].box;
			rightCounts[n] = rightCounts[n + 1] + bins[n].count;
		}
		
		float minCost = constant::inf;
		float noSplitCost = intersectCost * count * BoxSA(bbox);
		int minIdx = 1;

		for(size_t n = 1; n < nBins; n++) {
			float cost =
				(leftCounts[n - 1]?	BoxSA(leftBoxes[n - 1]) * leftCounts[n - 1] : 0) +
				(rightCounts[n]?	BoxSA(rightBoxes[n]) * rightCounts[n] : 0);

			if(cost < minCost) {
				minCost = cost;
				minIdx = n;
			}
		}

		minCost = traverseCost + intersectCost * minCost;
		if(noSplitCost < minCost)
			goto LEAF_NODE;
		
		ObjectInstance *it =
			std::partition(&elements[first], &elements[first + count], TestBoxes(minAxis, minIdx, sub, mul));

		BBox leftBox = leftBoxes[minIdx - 1];
		BBox rightBox = rightBoxes[minIdx];
		int leftCount = leftCounts[minIdx - 1];
		int rightCount = rightCounts[minIdx];

		if(leftCount == 0 || rightCount == 0) {
			minIdx = count / 2;
			leftBox = elements[first].GetBBox();
			rightBox = elements[first + count - 1].GetBBox();

			for(size_t n = 1; n < minIdx; n++)
				leftBox  += elements[first + n].GetBBox();
			for(size_t n = minIdx; n < count; n++)
				rightBox += elements[first + n].GetBBox();
			leftCount = minIdx;
			rightCount = count - leftCount;
		}
			
		int subNode = nodes.size();
		nodes[nNode].subNode = subNode;

		nodes[nNode].axis = minAxis;
//.........这里部分代码省略.........
开发者ID:nadult,项目名称:Snail,代码行数:101,代码来源:tree.cpp


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