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


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

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


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


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