]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Fix camera focus method to handle special case of vertical direction. 67/3967/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Thu, 5 Mar 2020 10:49:50 +0000 (12:49 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Thu, 5 Mar 2020 10:49:50 +0000 (12:49 +0200)
gitlab #99

Change-Id: I61deefb45e8e4be993a6e4699042a550dda89707

org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/vtkCameraAndSelectorAction.java

index 7a0cc0314d228a793e73ce3b2c49fe6c70e425da..7a6f0d894173ad29e8eebb48be2c18da39ad20e6 100644 (file)
@@ -401,8 +401,15 @@ public class vtkCameraAndSelectorAction extends vtkSwtAction implements ISelecti
        public void focus(double x, double y, double z) {
                Lock();
                cam.SetFocalPoint(x, y, z);
-               if (doNotRotate)
-                       cam.SetViewUp(upDirection);
+               if (doNotRotate) {
+                       double[] proj = cam.GetDirectionOfProjection();
+                       if (Math.abs(proj[1] * upDirection[2] - proj[2] * upDirection[1]) < 1e-6 &&
+                               Math.abs(proj[2] * upDirection[0] - proj[0] * upDirection[2]) < 1e-6 &&
+                               Math.abs(proj[0] * upDirection[1] - proj[1] * upDirection[0]) < 1e-6)
+                               cam.SetViewUp(upDirection[1], upDirection[2], upDirection[0]);
+                       else
+                               cam.SetViewUp(upDirection);
+               }
                cam.OrthogonalizeViewUp();
                resetCameraClippingRange();
                // panel.UpdateLight();