View Full Version : Object space to Monitor space.
So I can get the 2D coordinates of an object in the viewport, but I would like to get it on the monitor instead. So that I can draw in monitor space where and object is.
Any one know how to go about that?
10-22-2009, 10:26 PM
There might be a "cleaner" way, but how about using mouse.pos (mouse position relative to viewport) and mouse.screenpos (mouse position relative to screen) to find the difference between the two coordinate systems?
10-22-2009, 10:27 PM
I am not 100% sure i got what you are looking for. Monitor vs. Viewport space as in monitor space beeing the whole screen res and viewport beeing bound to the viewport position and size ?
I can't use the mouse. And yes I want to convert the position of an object in a viewport to where it is relative to the over all monitor, Not a viewport. I can get the viewport space without a problem but I want to know where on the monitor is has been drawn.
I was wondering if I could go down this sort of road, this doesn't work though.
for i = 1 to maxHwnds.count do
hWnd=dnControl.FromChildHandle (dotNetObject "System.IntPtr" maxHwnds[i])
if hWnd!=undefined do print hWnd
10-23-2009, 02:13 AM
I can't use the mouse.
Why not? All you need to do is subtract mouse.pos from mouse.position and then add the result you get to the viewport coordinates to "translate" them to monitor space. Of course math has never been my strong point so I might be overlooking something.
10-23-2009, 03:10 AM
Paul, Marco has the correct solution. This has been talked about before, see this thread:
you even posted to it! :)
10-23-2009, 03:21 AM
Great minds think alike :D
Ah ya, I see how it works. Sorry but when I read mouse I'm thinking, I don't care where the mouse is as I might not even be over that viewport at the time. But of course it doesn't matter.
Well done. Thanks for the link to the thread, my searches turned up nothing at all and I don't think that I ever followed that thread to the end when it was originally posted.
10-23-2009, 03:28 PM
I'm just testing out the method outlined in the other thread mentioned above. It is working for me, but not consistently. More often than not I am getting the rollout I am creating to be displayed at the bottom centre of my monitor, right on line with the task bar. [527,975] to be exact. The correct results should return [665,668], which does happen from time to time. I formatted out a breakdown of values and discovered that the inconsistency is coming from the gw.transpoint call and the mouse position values are fine. Does anybody know why this is happening?
EDIT: This is happening in Max 2010. Just jumped to test in 2008 and so far have not had the issue. Will keep testing.
EDIT2: Just ran into it in 2008.
10-23-2009, 03:59 PM
maybe you're not setting the gw transform to the identity matrix before calling gw.transpoint by using:gw.setTransform (matrix3 1)also i seem to remember that gw.wTranspoint worked better that gw.transpoint, dont remember why.
10-23-2009, 04:32 PM
Cool, seems like that was it. Working now. Thanks!
10-23-2009, 05:13 PM
on a side note I noticed a thing with viewport.getviewportDIB the other day - on 32bit max 2010 this worked fine, yet on 64bit yielded a blank bitmap. Using gw.getViewportDib() worked on both platforms. meh.
I'm seen the same thing Pete, 2009 and 2010 were not working in one of my old tools. Noticed that I was using viewport and not gw.
10-23-2009, 06:15 PM
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.
vBulletin v3.0.5, Copyright ©2000-2014, Jelsoft Enterprises Ltd.