From: Reino Ruusu Date: Thu, 20 Feb 2020 14:30:43 +0000 (+0200) Subject: Perform view direction switching via vtkCameraAndSelectorAction X-Git-Tag: v1.43.0~69 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F92%2F3892%2F1;p=simantics%2F3d.git Perform view direction switching via vtkCameraAndSelectorAction gitlab #85 Change-Id: Ie15464b9eaed7060ac6bacca534b4ff2c39da896 --- diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/handlers/CameraPositionHandler.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/handlers/CameraPositionHandler.java index 1f88e118..e3697be2 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/handlers/CameraPositionHandler.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/handlers/CameraPositionHandler.java @@ -21,7 +21,9 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.g3d.vtk.action.vtkAction; import org.simantics.g3d.vtk.common.VtkView; +import org.simantics.g3d.vtk.swt.vtkCameraAndSelectorAction; import org.simantics.utils.threads.ThreadUtils; public class CameraPositionHandler extends AbstractHandler { @@ -55,14 +57,21 @@ public class CameraPositionHandler extends AbstractHandler { dir.set(direction); dir.scale(distance); dir.add(focal); + panel.getRenderer().GetActiveCamera().SetPosition(dir.x, dir.y, dir.z); - if (Math.abs(direction.dot(new Vector3d(0,1,0))) < 0.95) - panel.getRenderer().GetActiveCamera().SetViewUp(0, 1, 0); - else - panel.getRenderer().GetActiveCamera().SetViewUp(1, 0, 0); - - panel.getRenderer().ResetCameraClippingRange(); - + + vtkAction action = panel.getDefaultAction(); + if (action instanceof vtkCameraAndSelectorAction) + ((vtkCameraAndSelectorAction)action).focus(focal.x, focal.y, focal.z); + else { + if (Math.abs(direction.dot(new Vector3d(0,1,0))) < 0.95) + panel.getRenderer().GetActiveCamera().SetViewUp(0, 1, 0); + else + panel.getRenderer().GetActiveCamera().SetViewUp(1, 0, 0); + + panel.getRenderer().ResetCameraClippingRange(); + } + //panel.UpdateLight(); panel.refresh(); }