Object space to Monitor space.

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 10 October 2009   #1
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?
Paul Neale
Old 10 October 2009   #2
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?
MatManager - take control of your materials
Teacup - online material sharing inside 3D Studio
Old 10 October 2009   #3
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 ?
Old 10 October 2009   #4
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.
Paul Neale
Old 10 October 2009   #5
I was wondering if I could go down this sort of road, this doesn't work though.

dnControl=dotNetClass "system.windows.forms.control"
maxHwnds=(windows.getChildrenHWND #max)
for i = 1 to maxHwnds.count do
	hWnd=dnControl.FromChildHandle (dotNetObject "System.IntPtr" maxHwnds[i][1])
	if hWnd!=undefined do print hWnd
Paul Neale
Old 10 October 2009   #6
Originally Posted by PEN: 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.
MatManager - take control of your materials
Teacup - online material sharing inside 3D Studio
Old 10 October 2009   #7
Paul, Marco has the correct solution. This has been talked about before, see this thread:
you even posted to it!
Old 10 October 2009   #8
Great minds think alike
MatManager - take control of your materials
Teacup - online material sharing inside 3D Studio

Last edited by MarcoBrunetta : 10 October 2009 at 02:24 AM.
Old 10 October 2009   #9
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.
Paul Neale
Old 10 October 2009   #10
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.

Last edited by Mathieson : 10 October 2009 at 02:44 PM.
Old 10 October 2009   #11
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.
Old 10 October 2009   #12
Cool, seems like that was it. Working now. Thanks!
Old 10 October 2009   #13
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.

Read my technical blog - lonerobot.net
Old 10 October 2009   #14
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.
Paul Neale
Old 10 October 2009   #15
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 02:25 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.