PyQt: viewport vs window - how do you translate co-ordinates?

Veek M vek.m1234 at gmail.com
Sun Sep 24 06:08:18 EDT 2017


On Saturday, September 23, 2017 at 8:44:25 PM UTC+5:30, Michael Torrie wrote:
> On 09/23/2017 05:38 AM, Veek M wrote:
> > I didn't understand any of that - could someone expand on that para?
> > Is there a reading resource that explains the Viewport and translations? I am not a CS student so I did not study computer graphics.
> 
> I'm sure there are lots of things that might help. This is primarily
> about OpenGL but the principles may apply:
> https://www.cs.mtsu.edu/~jhankins/files/4250/notes/WinToView/WinToViewMap.html
> 
> Alternatively, you can think it through.  Imagine you're laying out a
> fence around your house. You could use global coordinates for
> everything, or you could just call the exact center of your yard 0,0 and
> measure everything from there, in whatever units you wish. That's the
> idea here. Rather than referring to pixels by their screen coordinates
> (which can change if it moves around the screen), you refer to them by
> an arbitrary coordinate system with it's own scaling relative to the
> screen region.  You could have a screen region that is 100 px by 100 px,
> and the you designate that the upper left corner of that region is
> -500,500 and the lower right corner is 500,-500. Or it could be
> something like -500,200 to 500,-200, which would make things stretched
> out in the x axis compared to the y axis.
> 
> > (sorry for using google groups but my knode is broken and pan is horrible on olvwm - my plan is to write myself a News client in PyQt :))
> 
> I don't think you need to know that much about graphics coordinate
> systems to get started with Qt. Most GUI layout stuff does not depend on
> pixels or coordinates.

I took a look at the: OpenGL SuperBible - 7e - it's heavy on doing, and not much theory; they have a section on Views. Also, read that link. The link has some mistakes I suspect..

Let's say we have a teacup-photograph and a table in a 3d-room. The photo has a local space - called Model Space or Object Space. The edges of the photo will form a coordinate system and using that i could make the teacup handle red.

If i take that photo and place it on top of that table - i get a World Space that contains both objects and the walls of the room form a coordinate system. (this is where that link is wrong)

Now let's say I want to display the room on a computer screen.

The entire computer screen forms a Screen coordinate system and will include the Dolphin file browser, maybe firefox, the kde toolbar)

However, I can't directly take a 3d room and stick it in my 2d screen so, I have to capture part of the room from a PERSPECTIVE - this is 2d because the camera film is 2d - so, this is a View Space/Clipping Window (link/url).

Now the View Space data that I captured has to be placed on the screen BUT not everywhere - this is the Interface Window (link/url).

However I may want to caption the room-image-displayed-on-screen so the Interface Window is further shrunk into a Viewport which represents pixels/points on the device/paper.

Transformation is a matrix associated with a space that will give you the desired pixels in the Viewport.

View Space is how this World Space looks when viewed
-----------------------------------------------

So how does the above fit into PyQt/book-description.

We have a Widget that is drawn in pixels/picas/whatever that has a physical-coordinate system associated with it (800x600 and will prolly fill the entire computer-screen). 

We have a window which is at (-60, -60) + 120 length&breadth - so you have a small rectangle in which to draw - equivalent to the ViewSpace however since this is 2d, it can also be equivalent to the Model/Object Space - with some random center (0,0) could be the teacup-handle.

The aspect ratio for widget is 1.3333
aspect ratio for window is 1

If the aspect ratios were the same there would be no problem - however since the aspect ratios are different, x-axis scaling is 120:800 and y-axis is 120:600. We need to bear this in mind when we draw in our little window because what looks proportional/linear will be deformed when placed on screen/viewport.

So if we badly want a square window, we can create a square Screen/Viewport and loose some drawing area as a result of the viewport being squared from a rectangle.
--------------------------

Phew! anyway this is just my longwinded way but I think I got it. Thanks :)








More information about the Python-list mailing list