本文整理汇总了C++中Viewport::cameraPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Viewport::cameraPosition方法的具体用法?C++ Viewport::cameraPosition怎么用?C++ Viewport::cameraPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Viewport
的用法示例。
在下文中一共展示了Viewport::cameraPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onAlignViewToPlane
/******************************************************************************
* Aligns the current viewing direction to the slicing plane.
******************************************************************************/
void SliceModifierEditor::onAlignViewToPlane()
{
TimeInterval interval;
Viewport* vp = dataset()->viewportConfig()->activeViewport();
if(!vp) return;
// Get the object to world transformation for the currently selected object.
ObjectNode* node = dynamic_object_cast<ObjectNode>(dataset()->selection()->front());
if(!node) return;
const AffineTransformation& nodeTM = node->getWorldTransform(dataset()->animationSettings()->time(), interval);
// Transform the current slicing plane to the world coordinate system.
SliceModifier* mod = static_object_cast<SliceModifier>(editObject());
if(!mod) return;
Plane3 planeLocal = mod->slicingPlane(dataset()->animationSettings()->time(), interval);
Plane3 planeWorld = nodeTM * planeLocal;
// Calculate the intersection point of the current viewing direction with the current slicing plane.
Ray3 viewportRay(vp->cameraPosition(), vp->cameraDirection());
FloatType t = planeWorld.intersectionT(viewportRay);
Point3 intersectionPoint;
if(t != FLOATTYPE_MAX)
intersectionPoint = viewportRay.point(t);
else
intersectionPoint = Point3::Origin() + nodeTM.translation();
if(vp->isPerspectiveProjection()) {
FloatType distance = (vp->cameraPosition() - intersectionPoint).length();
vp->setViewType(Viewport::VIEW_PERSPECTIVE);
vp->setCameraDirection(-planeWorld.normal);
vp->setCameraPosition(intersectionPoint + planeWorld.normal * distance);
}
else {
vp->setViewType(Viewport::VIEW_ORTHO);
vp->setCameraDirection(-planeWorld.normal);
}
vp->zoomToSelectionExtents();
}