本文整理汇总了C++中Viewpoint::focus方法的典型用法代码示例。如果您正苦于以下问题:C++ Viewpoint::focus方法的具体用法?C++ Viewpoint::focus怎么用?C++ Viewpoint::focus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Viewpoint
的用法示例。
在下文中一共展示了Viewpoint::focus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsVisible
/*
* Returns true if the given point is visible from the given viewpoint.
*
* A point is visible if it will be on screen, and if it is not occluded by
* other objects.
*
* Input:
* point: The point whose visibility we want to check.
* viewpoint: The viewpoint to check from.
*
* Returns: True if the point is visible from the viewpoint.
*/
bool VisibilityChecker::IsVisible(const Ogre::Vector3& point,
const Viewpoint& viewpoint) {
float screen_x;
float screen_y;
auto old_position = camera_->getPosition();
auto old_direction = camera_->getDirection();
camera_->setPosition(viewpoint.position());
camera_->lookAt(viewpoint.focus());
GetScreenPosition(point, &screen_x, &screen_y);
bool result = false;
if (IsOnScreen(screen_x, screen_y)) {
Ogre::Ray ray;
camera_->getCameraToViewportRay(screen_x, screen_y, &ray);
Ogre::Vector3 hit;
if (RaycastAABB(ray, &hit)) {
auto dist = point.distance(hit);
if (dist < kOcclusionThreshold) {
result = true;
} else { // Hit something, but too far away from the target.
result = false;
}
} else {
// No hits. The ray should hit the target, but if it doesn't, that usually
// indicates visibility. This is because if the target is occluded, the
// ray is likely to have hit the occluding object.
result = true;
}
} else { // Not on screen
result= false;
}
camera_->setPosition(old_position);
camera_->setDirection(old_direction);
return result;
}