本文整理汇总了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;
}