Solved : Rotating view around non-target point scripting

Hi All,

I am trying to replicate one feature of Rhino mouse navigation in a script and after trying hard for a while I hit the wall.
What I am after is rotating the camera view around a given point [P] that is NOT at target or in the view center - so the camera point rotates around the point yet the camera plane/target location are set in such way that the point [P] stays at the same spot in the viewport.

This is currently possible in Rhino by Ctrl+Shift+RMB-drag over an object in the scene - see the clip:

( @Pascal mentioned here: Tip : mouse view rotation that @Mikko may be behind this feature - hope for some hints! )

Clearly there is more to it than just rotating the camera and target around the point [P] - I came close with some solutions but nothing works precisely keeping the point in place in the viewport as in Rhino UI. I have a feeling that there should be simple and clean rule behind it but I ran out of ideas.

In the attached file, C1-T1 is the camera and P is the point I want to keep intact in the viewport while rotating camera around P. So when given any new camera point location - for example C2 (new camera location on the sphere around P) - how to find the correct camera plane/target location to make it work?
View_Orbit_Sample.3dm (335.5 KB)

I am using RhinoScript but any hint about logic of such rotation would be much appreciated.


Never mind. Figured that out finally!
( I break the compound rotation vector apart into horizontal rotation and vertical rotation separately - this way I can rotate the camera and target around P horizontally along World Z axis and then vertically along Camera Plane X axis and point P.
This way the frame stays up after both rotations and the point P stays at the exact same screen location.