fixed size in viewport, aspect ratio

Started by
1 comment, last by afraidofdark 13 years, 8 months ago
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.
www.lostchamber.com
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?
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
www.lostchamber.com

This topic is closed to new replies.

Advertisement