[Closed] Get Viewport 2d Pan/Zoom level?
Has anyone found a hack to get the 2d pan zoom level in maxscript?? It seems we can only get/set the 2d pan zoom mode not the actual level.
In orthographic views you can get the FOV and set the Zoom, and you can get the Pan from the viewport matrix and set it with the Pan property, so I am unsure what do you really mean when you say we can’t set the pan/zoom level.
In order to wrap up some code I made a few assumptions, which might be wrong.
- Zoom 1X level should be the default FOV (180/pi)
- You want the viewport pan to be the same in pixels for different zoom levels
- You want to zoom in/out keeping the pan (in pixels)
Note that the zoom level is “reversed” compared with how usually zoom works in most software, so a zoom of 0.5 is actually a 2X zoom.
If the assumptions are correct, the following code may be useful.
(
fn GetViewZoom =
(
return (viewport.getfov()) / (180.0 / pi)
)
fn SetViewZoom factor =
(
viewport.zoom (factor / GetViewZoom())
completeredraw()
)
fn GetViewPan =
(
tm = viewport.gettm()
pan = tm.row4 / GetViewZoom()
return pan
)
fn SetViewPan pos =
(
camWidth = 400.0
width = camWidth / (getviewsize()).x
tm = viewport.gettm()
pan = (tm.row4 / width) / GetViewZoom()
pos /= width
offsetx = pos.x - pan.x
offsety = pan.y - pos.y
viewport.pan offsetx offsety
completeredraw()
)
-- SetViewPan [5,10]
-- GetViewPan()
-- SetViewZoom 0.5
-- GetViewZoom()
)
Jorge, 2d pan zoom mode is for zooming in on a perspective/camera viewport.
https://youtu.be/9Kpj_v8OR50?t=46s
Using the viewport.pan() will move the camera left and right…