Gui: Combine getFocalPoint() and getCenterPointOnFocalPlane()
This commit is contained in:
committed by
Max Wilfinger
parent
013a1d5f3a
commit
d443d5b065
@@ -194,14 +194,13 @@ void DemoMode::onAngleSliderValueChanged(int v)
|
||||
void DemoMode::reorientCamera(SoCamera* cam, const SbRotation& rot)
|
||||
{
|
||||
// Find global coordinates of focal point.
|
||||
SbVec3f direction;
|
||||
cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
|
||||
SbVec3f focalpoint = cam->position.getValue() + cam->focalDistance.getValue() * direction;
|
||||
SbVec3f focalpoint = activeView()->getViewer()->getFocalPoint();
|
||||
|
||||
// Set new orientation value by accumulating the new rotation.
|
||||
cam->orientation = rot * cam->orientation.getValue();
|
||||
|
||||
// Reposition camera so we are still pointing at the same old focal point.
|
||||
SbVec3f direction;
|
||||
cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
|
||||
cam->position = focalpoint - cam->focalDistance.getValue() * direction;
|
||||
}
|
||||
|
||||
@@ -710,7 +710,7 @@ public:
|
||||
: my_base(ctx)
|
||||
{
|
||||
auto& ns = this->outermost_context().ns;
|
||||
ns.setRotationCenter(ns.getFocalPoint());
|
||||
ns.setRotationCenter(ns.viewer->getFocalPoint());
|
||||
ns.setViewingMode(NavigationStyle::DRAGGING);
|
||||
this->base_pos
|
||||
= static_cast<const NS::Event*>(this->triggering_event())->inventor_event->getPosition();
|
||||
|
||||
@@ -589,7 +589,7 @@ SbBool MayaGestureNavigationStyle::processSoEvent(const SoEvent* const ev)
|
||||
if (comboAfter & BUTTON1DOWN || comboAfter & BUTTON2DOWN) {
|
||||
// don't leave navigation till all buttons have been released
|
||||
if (comboAfter & BUTTON1DOWN && comboAfter & BUTTON2DOWN) {
|
||||
setRotationCenter(getFocalPoint());
|
||||
setRotationCenter(viewer->getFocalPoint());
|
||||
}
|
||||
else {
|
||||
saveCursorPosition(ev);
|
||||
|
||||
@@ -504,7 +504,7 @@ void NavigationStyle::lookAtPoint(const SbVec2s screenpos)
|
||||
void NavigationStyle::lookAtPoint(const SbVec3f& position)
|
||||
{
|
||||
this->rotationCenterFound = false;
|
||||
translateCamera(position - getFocalPoint());
|
||||
translateCamera(position - viewer->getFocalPoint());
|
||||
}
|
||||
|
||||
SoCamera* NavigationStyle::getCamera() const
|
||||
@@ -524,7 +524,7 @@ std::shared_ptr<NavigationAnimation> NavigationStyle::setCameraOrientation(
|
||||
|
||||
animator->stop();
|
||||
|
||||
const SbVec3f focalPoint = getFocalPoint();
|
||||
const SbVec3f focalPoint = viewer->getFocalPoint();
|
||||
SbVec3f translation(0, 0, 0);
|
||||
|
||||
if (moveToCenter) {
|
||||
@@ -618,6 +618,7 @@ void NavigationStyle::boxZoom(const SbBox2s& box)
|
||||
|
||||
doScale(cam, scaleFactor);
|
||||
}
|
||||
|
||||
void NavigationStyle::scale(float factor)
|
||||
{
|
||||
SoCamera* cam = viewer->getSoRenderManager()->getCamera();
|
||||
@@ -626,9 +627,7 @@ void NavigationStyle::scale(float factor)
|
||||
}
|
||||
|
||||
// Find the current center of the screen
|
||||
SbVec3f direction;
|
||||
cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
|
||||
SbVec3f initCenter = cam->position.getValue() + cam->focalDistance.getValue() * direction;
|
||||
SbVec3f initCenter = viewer->getFocalPoint();
|
||||
|
||||
// Move the camera to the origin for scaling
|
||||
cam->position = cam->position.getValue() - initCenter;
|
||||
@@ -702,7 +701,7 @@ void NavigationStyle::findBoundingSphere()
|
||||
*/
|
||||
void NavigationStyle::reorientCamera(SoCamera* camera, const SbRotation& rotation)
|
||||
{
|
||||
reorientCamera(camera, rotation, getFocalPoint());
|
||||
reorientCamera(camera, rotation, viewer->getFocalPoint());
|
||||
}
|
||||
|
||||
/** Rotate the camera by the given amount, then reposition it so the rotation center stays in the
|
||||
@@ -751,7 +750,7 @@ void NavigationStyle::reorientCamera(
|
||||
#else
|
||||
constexpr float orthographicFocalDistance = 1;
|
||||
#endif
|
||||
camera->position = getFocalPoint() - orthographicFocalDistance * direction;
|
||||
camera->position = viewer->getFocalPoint() - orthographicFocalDistance * direction;
|
||||
camera->focalDistance = orthographicFocalDistance;
|
||||
}
|
||||
|
||||
@@ -1004,7 +1003,7 @@ void NavigationStyle::doZoom(SoCamera* camera, float logfactor, const SbVec2f& p
|
||||
// Change the position of the rotation center indicator after zooming at cursor
|
||||
// Rotation mode is WindowCenter
|
||||
if (!rotationCenterMode) {
|
||||
viewer->changeRotationCenterPosition(getFocalPoint());
|
||||
viewer->changeRotationCenterPosition(viewer->getFocalPoint());
|
||||
|
||||
#if (COIN_MAJOR_VERSION * 100 + COIN_MINOR_VERSION * 10 + COIN_MICRO_VERSION < 403)
|
||||
findBoundingSphere();
|
||||
@@ -1083,20 +1082,6 @@ void NavigationStyle::setRotationCenter(const SbVec3f& cnt)
|
||||
}
|
||||
}
|
||||
|
||||
SbVec3f NavigationStyle::getFocalPoint() const
|
||||
{
|
||||
SoCamera* cam = viewer->getSoRenderManager()->getCamera();
|
||||
if (!cam) {
|
||||
return {0, 0, 0};
|
||||
}
|
||||
|
||||
// Find global coordinates of focal point.
|
||||
SbVec3f direction;
|
||||
cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
|
||||
SbVec3f focal = cam->position.getValue() + cam->focalDistance.getValue() * direction;
|
||||
return focal;
|
||||
}
|
||||
|
||||
/** Uses the sphere sheet projector to map the mouse position onto
|
||||
* a 3D point and find a rotation from this and the last calculated point.
|
||||
*/
|
||||
@@ -1296,7 +1281,7 @@ void NavigationStyle::saveCursorPosition(const SoEvent* const ev)
|
||||
|
||||
// mode is WindowCenter
|
||||
if (!this->rotationCenterMode) {
|
||||
setRotationCenter(getFocalPoint());
|
||||
setRotationCenter(viewer->getFocalPoint());
|
||||
}
|
||||
|
||||
// Option to get point on model (slow) or always on focal plane (fast)
|
||||
|
||||
@@ -166,7 +166,6 @@ public:
|
||||
void setRotationCenterMode(RotationCenterModes);
|
||||
RotationCenterModes getRotationCenterMode() const;
|
||||
void setRotationCenter(const SbVec3f& cnt);
|
||||
SbVec3f getFocalPoint() const;
|
||||
|
||||
SoCamera* getCamera() const;
|
||||
std::shared_ptr<NavigationAnimation> setCameraOrientation(
|
||||
|
||||
@@ -2678,16 +2678,16 @@ void View3DInventorViewer::setSeekMode(bool on)
|
||||
);
|
||||
}
|
||||
|
||||
SbVec3f View3DInventorViewer::getCenterPointOnFocalPlane() const
|
||||
SbVec3f View3DInventorViewer::getFocalPoint() const
|
||||
{
|
||||
SoCamera* cam = getSoRenderManager()->getCamera();
|
||||
if (!cam) {
|
||||
const SoCamera* camera = getCamera();
|
||||
if (!camera) {
|
||||
return {0., 0., 0.};
|
||||
}
|
||||
|
||||
SbVec3f direction;
|
||||
cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
|
||||
return cam->position.getValue() + cam->focalDistance.getValue() * direction;
|
||||
camera->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
|
||||
return camera->position.getValue() + camera->focalDistance.getValue() * direction;
|
||||
}
|
||||
|
||||
float View3DInventorViewer::getMaxDimension() const
|
||||
|
||||
@@ -506,7 +506,7 @@ public:
|
||||
|
||||
void getDimensions(float& fHeight, float& fWidth) const;
|
||||
float getMaxDimension() const;
|
||||
SbVec3f getCenterPointOnFocalPlane() const;
|
||||
SbVec3f getFocalPoint() const;
|
||||
|
||||
NavigationStyle* navigationStyle() const;
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ bool GridExtensionP::checkCameraTranslationChange(const Gui::View3DInventorViewe
|
||||
{
|
||||
// Then we check if user moved by more than 10% of camera dimension (must be after updating
|
||||
// camera dimension).
|
||||
SbVec3f newCamCenterPointOnFocalPlane = viewer->getCenterPointOnFocalPlane();
|
||||
SbVec3f newCamCenterPointOnFocalPlane = viewer->getFocalPoint();
|
||||
|
||||
if ((camCenterPointOnFocalPlane - newCamCenterPointOnFocalPlane).length()
|
||||
> 0.1 * camMaxDimension) {
|
||||
|
||||
Reference in New Issue
Block a user