Sign in to follow this  
Wizumwalt_

how to scale proportionately

Recommended Posts

How is a model scaled proportionaltely if the width of the window is wider than the height. In other words, if the model is 200 wide by 100 high and my window is say 600 x 400, and I decrement by 1 as I scale down the model, the model's x and y will soon be 100 wide and 0 high as I scale down making it terribly out of proportion. When I use keys to zoom in or out (scale), I increment or decrement to the x and y vars, but my model is just not staying in proportion as it changes size (note: the window is not chaning size, just the model). glScalef(x, y, 0.0f); Any help much appreciated.

Share this post


Link to post
Share on other sites
When you scale a model, that happens multiplicatively, not additively. Thus, a 200x100 model that is scaled to 100 pixels wide would become 100x50, not 100x0.

If the x, y, and z parameters to glScale are equal, proportions will be maintained.

Share this post


Link to post
Share on other sites
Ok, I see that now. I have X and Y equal and it scales proportionately, but I have left Z as zero so that my model does not get clipped on the near and far planes if it were to scale in and out.

What I'm now trying to figure out is how to adjust the initial model size to fit the window once it's loaded.

I have the window height and width from my reshape() method and in my display method I have the min and max width and height of the model, so now I'm just trying to figure out what the algorithm would be to set x and y in my glScale(x, y, 0.0) method when the model is initially loaded so that it fits the window.

Do I take the width of the model and multiply it by some fraction of the window width? (I tried but then my proportions got all out of whack).

Share this post


Link to post
Share on other sites
Given the current x and y, and the window x and y:

First, divide window x by current x to get an x scaling factor. Likewise with y.

Then scale by the smaller of these two values.

You will need to be sure to use floating point arithmetic, and possibly handle special cases too (current x and/or y == 0). You might also want to scale by a slightly smaller number, to leave some border at the screen edges.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Given the current x and y, and the window x and y:


What do you mean by 'current x and y'? Certainly not the current mouse coords, right? Window x and y are gl canvas width and height?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this