PDA

View Full Version : Setting model in the middle of the screen.



AeroSujan
09-29-2011, 09:25 AM
Dear Friends
I have a profile...a curve of GL_LINES

How can I display my curve or model in the middle of the screen. Some parts of the curve is getting out of the visibility. While loading the curve I want to show them just in middle of the screen and fitting the size of the computer screen to the maximum possible size.
Please give me some idea.

Currently I calculating the xmin,xmax and ymin, ymax.

the calculating the middle point position like this.
double x_middle = xmin + (xmax-xmin)/2;
double y_middle = ymin + (ymax-ymin)/2;

Then using glTranslate(); like this
trans[0] = x_middle;
trans[0] = - y_middle;
glTranslatef(trans[0], trans[1], trans[2]);

Whats the best value for intial trans[2]...Currently I am using
trans[2] = -130.0f

Please give me some suggestions friends. Thanks Sujan

Aleksandar
09-29-2011, 03:20 PM
You are probably using perspective projection, since the object becomes smaller with the translation along the -Z-axis. It is an elementary trigonometric problem.

trans[2] = -max((ymax-ymin)/(2*tan(FOVy/2)), (xmax-xmin)/(2*tan(FOVy*aspect/2)))

where FOVy is a vertical field of view, and aspect is the aspect of your window/viewport.

AeroSujan
10-03-2011, 12:19 PM
Thanks a lot for your suggestion I'll impplement it. Thanks a lot. sujan