Solved

Incorporating window aspect ratio into drawing window

Posted on 2012-04-10
3
524 Views
Last Modified: 2012-04-17
I have a window in my C++ app that I use to draw something.  I'll call this "something" a "model".  My window is NOT a perfect square.  It is wider than it is taller.  It's about 4 times wider than it is tall.  I am having trouble wrapping my brain around how to set the window dimensions, such that the model I draw within the window will be scaled correctly.  

If the model I want to draw is taller than it is wide, this is easy to draw.  I just make the window dimensions in the vertical direction equal to the model's height.  Then, I make the window's horizontal dimensions be equal to the model's height times 4 (because the window's aspect ratio is 4). This works fine.

But, if the model I want to draw is wider than it is taller, I am having difficulty.  I could just make the window's vertical dimension be equal to the model's horizontal dimension, and make the window's horizontal dimension be equal to the model's horizontal dimension times 4.  This scales my model wit proper proportion.  However, it makes my model draw too small, because the window's dimensions are much bigger than they need to be.

Any help would be greatly appreciated.
0
Comment
Question by:cjm20
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Accepted Solution

by:
satsumo earned 500 total points
ID: 37830492
In any given size of model or window there are two possiblities, the model fits the window either vertically or horizontally.  To do the fitting I assume you use some kind of zoom factor at the moment?  Compare the zoom for model width into window width and model height into window height and choose the one which is best.  That would typically be the smaller of the two.

For example lets say the window is 100 pixels wide by 30 pixels high, the model is 50 (somethings) wide by 20 tall.

Horizontal = 100 / 50 = 2
Vertical = 30 / 20 = 1.5

Vertical is less than horizontal so this model fits the window vertically at a zoom of 1.5

Window is 100 X 30 again, this time model is 80 x 15

Horizontal = 100 / 80 = 1.25
Vertical = 30 / 15 = 2

This time horizontal is less than vertical, so the model fits horizontally, at zoom 1.25.

I can explain more details of how to apply this if needs be, it depends on what graphics system you are using.
0
 
LVL 16

Expert Comment

by:imladris
ID: 37833272
Or perhaps you need to be able to scroll.....
0
 

Author Closing Comment

by:cjm20
ID: 37858070
Excellent.  Thanks very much.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Generate Unique ID in VB.NET 21 134
programming a polycom voip phone 3 84
C qsort compare function issue 6 70
CSV file copy field 1 to field 2 2 62
A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question