From: Tuukka Lehtonen Date: Wed, 8 Apr 2020 20:28:11 +0000 (+0300) Subject: Added vtkCameraAndSelectorAction.setViewDir(Vector3d) X-Git-Tag: v1.43.0~22 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F19%2F4119%2F1;p=simantics%2F3d.git Added vtkCameraAndSelectorAction.setViewDir(Vector3d) Allows setting the camera view direction without changing the focal point. gitlab #118 Change-Id: I33421fb46e05c62892a396203681838131b0b382 (cherry picked from commit 6325452591b2a854f82ac913fe4f61e3df2f922d) --- 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 a5ea6149..e177834e 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 @@ -477,4 +477,17 @@ public class vtkCameraAndSelectorAction extends vtkSwtAction implements ISelecti return Math.abs(dx * dir.x) + Math.abs(dy * dir.y) + Math.abs(dz * dir.z); } + public void setViewDir(Vector3d direction) { + Vector3d focal = new Vector3d(cam.GetFocalPoint()); + Vector3d pos = new Vector3d(cam.GetPosition()); + Vector3d dir = new Vector3d(pos); + dir.sub(focal); + double distance = dir.length(); + dir.scaleAdd(distance, direction, focal); + cam.SetPosition(dir.x, dir.y, dir.z); + focus(focal.x, focal.y, focal.z); + //panel.UpdateLight(); + panel.refresh(); + } + }