]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Perform view direction switching via vtkCameraAndSelectorAction 92/3892/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Thu, 20 Feb 2020 14:30:43 +0000 (16:30 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Thu, 20 Feb 2020 14:31:06 +0000 (16:31 +0200)
gitlab #85

Change-Id: Ie15464b9eaed7060ac6bacca534b4ff2c39da896

org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/handlers/CameraPositionHandler.java

index 1f88e11845a7e13bdd08deeb4a28d8094c11f06e..e3697be2a8295992bb63adb23e05f3bd764a6ad1 100644 (file)
@@ -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();
                        }