From efb52587babd1b858c8e77fedc44a5b4ef0c1088 Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Thu, 20 Feb 2020 16:30:43 +0200 Subject: [PATCH] Perform view direction switching via vtkCameraAndSelectorAction gitlab #85 Change-Id: Ie15464b9eaed7060ac6bacca534b4ff2c39da896 --- .../vtk/handlers/CameraPositionHandler.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) 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(); } -- 2.47.1