View Full Version : How to get the coordinates of the window frame ?

 hunter52803 March 2009, 09:10 AMHow to get the coordinates of the current window frame ? And the creating of "Rectangle" on the coordinates. Requests master help to answer, thanks ~ http://img9.imageshack.us/img9/5359/q001j.jpg
decon
04 April 2009, 12:47 PM
-- creates a rectangle around current orthographic viewport
(
TM =viewport.getTM()
p = mapScreenToView [0,0] 0.0
rWidth = abs(2 * p[1])
rLength = abs(2 * p[2])
r = rectangle pos:[0,0,0] width:rWidth length:rLength corner_radius:(rWidth/10.0)
r.transform = inverse TM
)

cheers :cool:

hunter528
04 April 2009, 04:00 AM
Thank you ~ Decon
How to get the coordinates of the currew frame of "camera" and "Perspective" ?
Requests master help to answer, thanks ~

decon
04 April 2009, 07:48 AM
where do you want it in space (or how big) ?

-- creates a rectangle around current viewport
(
TM = getViewTM()
viewPt = TM.row4
p = mapScreenToView [0,0] viewPt.z
rWidth = abs(2 * p[1])
rLength = abs(2 * p[2])
r = rectangle pos:[0,0,0] width:rWidth length:rLength corner_radius:(rWidth/10.0)
r.transform = inverse TM
r.pos = [0,0,viewPt.z] * r.transform
)

one solution, dont ask more .. :D

hunter528
04 April 2009, 12:51 PM
Thank you ~ Decon ~

I know how to creates the rectangle.
Records the coordinate,
And uses "viewport.setTM <matrix3>" restore viewport coordinates,
But why "Top" , "Front" and so on,
the 2D viewport can not restore it?

Requests master help to answer, thanks ~

TM = getViewTM()
viewport.setTM TM

decon
04 April 2009, 09:05 AM
well, at View menu, there is Save Active View option. Maybe you could use that . With script it might start up something like this:

-- First get current viewport values
--Returns the active view size as point2 in pixels
vSize = getViewSize()

-- gives construction plane world coords at viewport corners
p1 = mapScreenToCP [0,0]
p2 = mapScreenToCP vSize

-- scale factor
ssf = getScreenScaleFactor [0,0,0]

vWidth = abs((p2-p1).x)
vHeight = abs((p2-p1).y)
--------------------------------------------------
-- move and/or zoom the viewport ....
--------------------------------------------------
-- after that, restore earlier values

-- first the zoom:
ssf_new = getScreenScaleFactor [0,0,0]
zoomFactor = ssf / ssf_new
viewport.zoom zoomFactor

-- then other transforms:
p1_new = mapScreenToCP [0,0]
xVal = (p1_new - p1).x
yVal = (p1_new - p1).y

xVal = xVal / vWidth * vSize.x
yVal = -yVal / vHeight * vSize.y

viewport.pan xVal yVal
completeRedraw()

hope that gives some ideas :)

hunter528
04 April 2009, 06:45 AM