Computer Graphics

Moderators: Sephiroth
Number of threads: 1241
Number of posts: 2641

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
viewport to window mapping Posted by black_star on 13 May 2009 at 8:40 PM
Hi ...
I need to draw a map .I have the latitude longitude values of it .I was able to map these to screen coordinates and then draw the map.Once the map is drawn,as the mouse moves over the map i need to show the latitude and longitude values. This is where i am struck .For the initial case its simple,just rearrangement of window to view port mapping formula .i.e.,
u = (x-xmin)* sx+ umin
v = (y-ymin)* sy + vmin
But once the zoom and pan operations are applied on the map, I dont know how to get the latitude longitude values for each screen coordinate .
If some one knows how to solve this ,Please help me

Thanks in advance
Report
Re: viewport to window mapping Posted by dario_ramos on 6 Jan 2010 at 11:27 AM
This is how I do it. Going from window to viewport coordinates is a linear transform of this kind (dunno if I can post LaTeX code here, it would look way better):

| Xs | = |eM11 0 | |X| + |eDx|
| Ys | |0 eM22| |Y| |eDy|

(Xs,Ys) are screen coordinates, (X,Y) are window/world coordinates.
This transform represents scaling in x (given by eM11), scaling in y (given by eM22) and translation (given by eDx and eDy). Scaling = zoom (eM11 and eM22 will always have the same value), translation = pan.

So, when you zoom, if the structure which represents the transform is called m_TWorld2Screen, you have to update eM11 and eM22, but also eDx and eDy, since the translation is affected by zoom (it's not the same distance):

m_TWorld2Screen.eM11 = newVal;
m_TWorld2Screen.eM22 = newVal;
m_TWorld2Screen.eDx = (m_TWorld2Screen - m_iWidth/2.0f) * newVal / oldZoomFactor + m_iWidth/2.0f;
m_TWorld2Screen.eDy = (m_TWorld2Screen.eDy- m_iHeight/2.0f) * newVal / oldZoomFactor + m_iHeight/2.0f;


-newVal is the new zoom factor (between 0 and 1)
-m_iWidth and m_iHeight are the viewport's dimensions
-oldZoomFactor is the previous zoom factor

And when you pan, you only need to update eDx and eDy:

m_TWorld2Screen.eDx = - m_TWorld2Screen.eDx / m_TWorld2Screen.eM11;
m_TWorld2Screen.eDy = - m_TWorld2Screen.eDy / m_TWorld2Screen.eM22;


The proof of these formulas is quite tedious to write without LaTeX, but this works for me.
You might need to define m_TScreen2World to do the inverse transform. If you understood my concept, ask away



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.