1
$\begingroup$

I need to rotate a 3D object with the mouse, get the new ViewPoint, and scale that by dist to get a new ViewPoint and use that in ViewVector. And do this while preserving the orientation. (In the code, I also get the orientation jumping with the size slider. I don’t want this either.)

This is extending Matt's solution in this question Changing the Actions in EventHandler.

Manipulate[
 vp = ViewPoint /. Options[Graphics3D, ViewPoint];
 uvp = Normalize[vp];
 vp = dist*uvp;

 Show[
  {
     Graphics3D[{Red, Opacity[0.5],
        Cylinder[size {{0, 0, -1}, {0, 0, 1}}]}],
     Graphics3D[{Black, Opacity[0.5], Sphere[]}],
     Graphics3D[{Black, Sphere[{0, 0, 0}, .2]}]
   },

  PlotRange -> 10 {{-1, +1}, {-1, +1}, {-1, +1}},

  ViewAngle -> Dynamic[vAngle \[Degree]],
  ViewVector -> {Dynamic[vp], Dynamic[Flatten@{center, 0}]}
  ],

 {{vAngle, 30, "Zoom"}, 90, 10, 1},
 {{center, {0, 0}, "Pan"}, 2 {-1, -1}, 2 {1, 1}},
 {{size, 1, "size"}, 0, 5, .1},
 {{dist, 10, "dist"}, 0, 20, .1},

 TrackedSymbols :> {vAngle, center, size, dist},
 ControlPlacement -> Left
 ]
$\endgroup$
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.