Jump to content
  • Advertisement
Sign in to follow this  
Wizumwalt_

how to scale proportionately

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
The existing x and y dimensions (i.e. width and height) of the thing you're scaling, of course. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!