本文整理汇总了C++中AlignedBox::bound方法的典型用法代码示例。如果您正苦于以下问题:C++ AlignedBox::bound方法的具体用法?C++ AlignedBox::bound怎么用?C++ AlignedBox::bound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AlignedBox
的用法示例。
在下文中一共展示了AlignedBox::bound方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: framePoints
void Camera::framePoints( const vector< Point3 >& l, bool frameExactly ) {
if ( l.empty() )
return;
Vector3 direction = (_target - _position).normalized();
Vector3 right = direction ^ _up;
// Transform each of the points to camera space,
// and find the minimal bounding box containing them
// that is aligned with camera space.
// FIXME the projection we do here is orthogonal;
// it ignores the perspective projection of the camera
// that will make distant points appear closer to the line of sight.
// Thus, the camera will not frame points as tightly as it could.
AlignedBox box;
vector< Point3 >::const_iterator it = l.begin();
for ( ; it != l.end(); ++it ) {
Vector3 v = (*it) - _position;
box.bound( Point3( v * right, v * _up, v * direction ) );
}
// Translate the camera such
// that the line of sight passes through the centre of the bounding box,
// and the target point is at the centre of the bounding box.
Point3 boxCentre = box.getCentre();
Point3 newTarget = _position
+ right * boxCentre.x() + _up * boxCentre.y() + direction * boxCentre.z();
Vector3 translation = newTarget - _target;
_position += translation;
_target = newTarget;
// Next, dolly the camera forward (or backward)
// such that all points are visible.
// For each given point,
// we compute the amount by which to dolly forward for that point,
// and find the minimum of all such amounts
// to use for the actual dolly.
/*
In the below diagram,
"1" is the current position of the camera, which is pointing down
"a" is the distance to the near plane
"b" is half the width/height of the viewport
"3" is a point we want to frame by dollying the camera forward
"2" is the new location to place the camera to just frame "3"
"?" is the distance to dolly forward, which we want to compute
|-b-|
1 - - -
/| | | |
/ | a | |
/ | | | |
/---| - ? |
/ | | |
/ | | |
/ | | c
/ 2 - |
/ /| | |
/ / | | |
/ / | e |
/ / | | |
/ / | | |
.-------3-----. - -
|--f--|
|------d------|
The two hypotenuses are parallel because we don't want to change
the camera's field of view.
We have
a/b = c/d = e/f (where a,b,c,f are known)
and
? = c - e
= c - f*a/b
*/
float minDollyDelta = 0;
bool minDollyDeltaInitialized = false;
float min_c = 0;
for ( it = l.begin(); it != l.end(); ++it ) {
Vector3 v = (*it) - _position;
float c = v * direction;
if ( it == l.begin() ) min_c = c;
else if ( c < min_c ) min_c = c;
float f, dollyDelta;
if ( _viewport_width > 0 ) {
f = fabs( v * right );
dollyDelta = c - f * _near_plane * 2 / _viewport_width;
if ( minDollyDeltaInitialized ) {
if ( dollyDelta < minDollyDelta )
minDollyDelta = dollyDelta;
}
else {
minDollyDelta = dollyDelta;
minDollyDeltaInitialized = true;
}
}
if ( _viewport_height > 0 ) {
//.........这里部分代码省略.........