Jump to content

  • Log In with Google      Sign In   
  • Create Account

fixed size in viewport, aspect ratio


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 afraidofdark   Members   -  Reputation: 242

Like
0Likes
Like

Posted 08 August 2010 - 11:51 PM

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.

Sponsor:

#2 szecs   Members   -  Reputation: 2141

Like
0Likes
Like

Posted 09 August 2010 - 12:27 AM

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?

#3 afraidofdark   Members   -  Reputation: 242

Like
0Likes
Like

Posted 09 August 2010 - 12:36 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS