PDA

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


hunter528
03-31-2009, 10:10 AM
How 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-01-2009, 01: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-02-2009, 05: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-02-2009, 08: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-03-2009, 01:51 PM
Thank you ~ Decon ~

I know how to creates the rectangle.
I have made a exercises.
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-07-2009, 10: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-08-2009, 07:45 AM
Thanks for your answers, it's good for me.

CGTalk Moderation
04-08-2009, 07:45 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.