Public Group

# how to scale proportionately

This topic is 4948 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 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 on other sites
Quote:
 Original post by ZahlmanGiven 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 on other sites
The existing x and y dimensions (i.e. width and height) of the thing you're scaling, of course. :)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 13
• 9
• 9
• 15
• 14
• ### Forum Statistics

• Total Topics
634070
• Total Posts
3015335
×