• Advertisement
Sign in to follow this  

fixed size in viewport, aspect ratio

This topic is 2722 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

hello, I have a problem, I try to maintain an object size in viewport no matter what is width and height its size must remain same, however in order to keep aspect ratio there is a calculation which scale x value of the object acording to aspect ratio (width/height) here is the formula


float yscale = (1/tan(fovy/2));
float xscale = yscale/aspect;

closeProjection[0][0] = xscale ;
closeProjection[1][1] = yscale;

but in order to protect aspect ratio, object it self scale down aswell when the aspect ratio is increasing. So I figure out that I need to scale object by a factor of inverse aspect ratio before projecting it

object.x *= 1/aspect;
object.y *= 1/aspect;
object.z *= 1/aspect;

I did this but there is something missing, it is not working as I expected. The working example of my stuation can be observed in max or maya, open one of them select rotate manipulator, and change size of the window, manipulator wont change the size it occupy in the viewport unlike other objects. Thank you for your help.

Share this post


Link to post
Share on other sites
Advertisement
Well, I don't understand. Could you post some images?
I don't know what Max and Maya has to do with your own application.
By manipulator do you mean the transform gizmo? Why don't you scale it just like the objects?

Share this post


Link to post
Share on other sites
yes I was talking about transform gizmo, but it is a sphere for rotation,

I solve the problem like this

float mp = 500.0f/viewportSize.x;

inv.x *= mp;
inv.y *= mp;
inv.z *= mp;


the problem was only showing it self when the width of the window changed so instead of scaling the object with the aspect ratio I only scale it the amount of changing in width of the viewport, because float xscale = yscale/aspect; this formula was protecting the change in height, scaling the object by the amaunt changed in width solve the problem.

in order to see what was happening you can look at a simple directx or opengl window which update projection when the windowsize changes, objects in the viewport whill shring and grow due to change in size

Share this post


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

  • Advertisement