Zoom out to show all content
I am having a hard time trying to figure out how to solve my problem, which technically should be very easy.
What I have is any sized grid of tiles (say 15 high, an 20 wide, with a tile size of 20 units). What I am trying to do is determine how far to zoom the camera out so that all the tiles are displayed on screen (which is not a fixed size).
In this particular case glOrtho will not fit the situation as the camera is needed to follow a trackball, that part works fine.
Any help would be highly appreciated. I have a feeling that the answer is going to make me feel dumb for not thinking of it.
What I have is any sized grid of tiles (say 15 high, an 20 wide, with a tile size of 20 units). What I am trying to do is determine how far to zoom the camera out so that all the tiles are displayed on screen (which is not a fixed size).
In this particular case glOrtho will not fit the situation as the camera is needed to follow a trackball, that part works fine.
Any help would be highly appreciated. I have a feeling that the answer is going to make me feel dumb for not thinking of it.
the fovy angle you pass to gluPerspective determines a rightangled triangle, with the right corner at the center of the trackball. Once you've determined the radius of the circle you want to be visible in the view, you can use that radius as the opposite side of the right triangle and a bit of simple trigonometry to find the length of the adjacent side, A.K.A the distance of the camera.
I'm sure someone will draw a diagram if you can't follow that ^_^
I'm sure someone will draw a diagram if you can't follow that ^_^
I must not be thinking properly, or I am just doing it wrong. But here is what I have from your suggestion.
I want to find the radius, which I have as 200 (20 tiles * 20 tile width * 0.5) and a length for the first side of 150 (15 tiles * 20 tile width * 0.5).
When I find the long side of the triangle I am getting 250, which still does not show the full grid. When I zoom out manually it appears that 260 is the number I want to have as a result of my calculation.
Would the size of glViewport effect the calculation?
I want to find the radius, which I have as 200 (20 tiles * 20 tile width * 0.5) and a length for the first side of 150 (15 tiles * 20 tile width * 0.5).
When I find the long side of the triangle I am getting 250, which still does not show the full grid. When I zoom out manually it appears that 260 is the number I want to have as a result of my calculation.
Would the size of glViewport effect the calculation?
No, glViewport doesn't affect the calculation.
Your radius seems off to me, I expected to see a sqrt(width * width + height * height) in there, but I don't know quite what you're rendering.
The radius and opposite side length are the same thing...
Your radius seems off to me, I expected to see a sqrt(width * width + height * height) in there, but I don't know quite what you're rendering.
The radius and opposite side length are the same thing...
Sorry, I left that part out.
I was doing sqrt((200 * 200) + (150 * 150)), which is where I was getting the 250 value from.
This does display all the content for the width, but still does not display all the content for the height. That is where I got the 261 value from, with that zoom I can display all the content. But that changes of course if I change the size of the grid or tile size.
I was doing sqrt((200 * 200) + (150 * 150)), which is where I was getting the 250 value from.
This does display all the content for the width, but still does not display all the content for the height. That is where I got the 261 value from, with that zoom I can display all the content. But that changes of course if I change the size of the grid or tile size.
You might not be taking into account the ratio of width to height of your frustum. I'd use the lesser of the two...
Which number would I apply the ratio to?
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
How to zoom with a status bar strip  melobrien  2  2,843 
Oct 7, 2009 04:41 PM Last Post: melobrien 

show another name please !  imaumac  0  1,554 
Oct 25, 2008 08:29 AM Last Post: imaumac 

textures sometimes show garbled banding?  WhatMeWorry  2  2,714 
Jul 31, 2005 01:23 PM Last Post: WhatMeWorry 