Skip to content

Commit

Permalink
Gui: Use panning plane when hit point not found in lookAtPoint
Browse files Browse the repository at this point in the history
Also enables navigation animations when pressing MMB while the mouse is not over an object
  • Loading branch information
Rexbas committed Apr 20, 2024
1 parent 620a5c6 commit 19f16d0
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 50 deletions.
5 changes: 1 addition & 4 deletions src/Gui/BlenderNavigationStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev)
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// is it just a middle click?
if (tmp.getValue() < dci && !this->lockrecenter) {
if (!this->lookAtPoint(pos)) {
panToCenter(panningplane, posn);
this->interactiveCountDec();
}
lookAtPoint(pos);
processed = true;
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/Gui/CADNavigationStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,7 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev)
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// is it just a middle click?
if (tmp.getValue() < dci && !this->lockrecenter) {
if (!this->lookAtPoint(pos)) {
panToCenter(panningplane, posn);
this->interactiveCountDec();
}
lookAtPoint(pos);
processed = true;
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/Gui/GestureNavigationStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ class NS::IdleState : public sc::state<NS::IdleState, NS::NaviMachine>
//MMB click
if(ev.isPress(3) && ev.mbstate() == 0x010){
ev.flags->processed = true;
ns.onSetRotationCenter(ev.inventor_event->getPosition());
ns.setupPanningPlane(ns.viewer->getCamera());
ns.lookAtPoint(ev.inventor_event->getPosition());
return transit<NS::AwaitingReleaseState>();
}

Expand All @@ -314,8 +315,10 @@ class NS::IdleState : public sc::state<NS::IdleState, NS::NaviMachine>
bool press = (kbev->getState() == SoKeyboardEvent::DOWN);
switch (kbev->getKey()) {
case SoKeyboardEvent::H:
if (!press)
ns.onSetRotationCenter(kbev->getPosition());
if (!press) {
ns.setupPanningPlane(ns.viewer->getCamera());
ns.lookAtPoint(kbev->getPosition());
}
break;
case SoKeyboardEvent::PAGE_UP:
if(!press){
Expand Down
10 changes: 2 additions & 8 deletions src/Gui/InventorNavigationStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev)
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// is it just a left click?
if (tmp.getValue() < dci && !this->lockrecenter) {
if (!this->lookAtPoint(pos)) {
panToCenter(panningplane, posn);
this->interactiveCountDec();
}
lookAtPoint(pos);
processed = true;
}
}
Expand Down Expand Up @@ -197,10 +194,7 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev)
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// is it just a middle click?
if (tmp.getValue() < dci && !this->lockrecenter) {
if (!this->lookAtPoint(pos)) {
panToCenter(panningplane, posn);
this->interactiveCountDec();
}
lookAtPoint(pos);
processed = true;
}
}
Expand Down
18 changes: 5 additions & 13 deletions src/Gui/MayaGestureNavigationStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,9 @@ SbBool MayaGestureNavigationStyle::processSoEvent(const SoEvent * const ev)
switch (event->getKey()) {
case SoKeyboardEvent::H:
processed = true;
if(!press){
SbBool ret = NavigationStyle::lookAtPoint(event->getPosition());
if(!ret){
this->interactiveCountDec();
Base::Console().Log(
"No object under cursor! Can't set new center of rotation.\n");
}
if (!press) {
setupPanningPlane(viewer->getCamera());
lookAtPoint(event->getPosition());
}
break;
default:
Expand Down Expand Up @@ -431,12 +427,8 @@ SbBool MayaGestureNavigationStyle::processSoEvent(const SoEvent * const ev)
setViewingMode(NavigationStyle::PANNING);
} else if(press){
// if not PANNING then look at point
SbBool ret = NavigationStyle::lookAtPoint(event->getPosition());
if(!ret){
this->interactiveCountDec();
Base::Console().Log(
"No object under cursor! Can't set new center of rotation.\n");
}
setupPanningPlane(viewer->getCamera());
lookAtPoint(event->getPosition());
}
processed = true;
break;
Expand Down
40 changes: 27 additions & 13 deletions src/Gui/NavigationStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,27 +327,41 @@ void NavigationStyle::seekToPoint(const SbVec3f& scenepos)
viewer->seekToPoint(scenepos);
}

SbBool NavigationStyle::lookAtPoint(const SbVec2s screenpos)
void NavigationStyle::lookAtPoint(const SbVec2s screenpos)
{
SoCamera* cam = viewer->getSoRenderManager()->getCamera();
if (!cam)
return false;
const SoCamera* camera = viewer->getCamera();
if (!camera) {
return;
}

SoRayPickAction rpaction(viewer->getSoRenderManager()->getViewportRegion());
SoRayPickAction rpaction(viewer->getViewportRegion());
rpaction.setPoint(screenpos);
rpaction.setRadius(viewer->getPickRadius());
rpaction.apply(viewer->getSoRenderManager()->getSceneGraph());

SoPickedPoint * picked = rpaction.getPickedPoint();
if (!picked) {
this->interactiveCountInc();
return false;
const SoPickedPoint* picked = rpaction.getPickedPoint();

// Point is either the hitpoint or the projected point on the panning plane
SbVec3f point;
if (picked) {
point = picked->getPoint();
}
else {
const SbViewportRegion& vp = viewer->getViewportRegion();
const float aspectratio = vp.getViewportAspectRatio();
SbViewVolume vv = camera->getViewVolume(aspectratio);

// See note in Coin docs for SoCamera::getViewVolume re:viewport mapping
if (aspectratio < 1.0) {
vv.scale(1.0 / aspectratio);
}

SbLine line;
vv.projectPointToLine(normalizePixelPos(screenpos), line);
panningplane.intersect(line, point);
}

SbVec3f hitpoint;
hitpoint = picked->getPoint();
lookAtPoint(hitpoint);
return true;
lookAtPoint(point);
}

void NavigationStyle::lookAtPoint(const SbVec3f& position)
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/NavigationStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class GuiExport NavigationStyle : public Base::BaseClass
void setSeekMode(SbBool enable);
SbBool seekToPoint(const SbVec2s screenpos);
void seekToPoint(const SbVec3f& scenepos);
SbBool lookAtPoint(const SbVec2s screenpos);
void lookAtPoint(const SbVec2s screenpos);
void lookAtPoint(const SbVec3f& position);

void panCamera(SoCamera * camera,
Expand Down
5 changes: 1 addition & 4 deletions src/Gui/RevitNavigationStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ SbBool RevitNavigationStyle::processSoEvent(const SoEvent * const ev)
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// is it just a middle click?
if (tmp.getValue() < dci && !this->lockrecenter) {
if (!this->lookAtPoint(pos)) {
panToCenter(panningplane, posn);
this->interactiveCountDec();
}
lookAtPoint(pos);
processed = true;
}
}
Expand Down

0 comments on commit 19f16d0

Please sign in to comment.