From: Reino Ruusu Date: Thu, 5 Mar 2020 10:49:50 +0000 (+0200) Subject: Fix camera focus method to handle special case of vertical direction. X-Git-Tag: v1.43.0~49 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F67%2F3967%2F1;p=simantics%2F3d.git Fix camera focus method to handle special case of vertical direction. gitlab #99 Change-Id: I61deefb45e8e4be993a6e4699042a550dda89707 --- diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/vtkCameraAndSelectorAction.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/vtkCameraAndSelectorAction.java index 7a0cc031..7a6f0d89 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/vtkCameraAndSelectorAction.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/vtkCameraAndSelectorAction.java @@ -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();