PDA

View Full Version : Qt-OpenGL Zoom Problem



sujan.dasmahapatra
1st November 2009, 19:12
Dear Friends
I am suceessfully able to zoom in/out in Qt application but on opengl graphics.
For zooming I am using the steps as 0.2 and intializing the zoomFactor = 1.0.
But When the value gets lower than 0.2 the it's getting out of visibility.

What kind of steps should I use so that it zooms properly as long as the object is present.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static float steps = 1.0
MyGlWidget::mouseMoveEvent(QMouseEvent *me)
{
if(me->button()==Qt::RightButton)
{
if(me->y() > lastPos.y())
{
//zoom in
zoomFactor -= steps;
if(zoomFactor <0)
zoomFactor = 0.0;
if(zoomFactor > 6.0)
zoomFactor = 6.0;
setProjection(width(),height());
}
}
}
MyGlWidget::setProjection(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30*zoomFactor,(GLfloat)w/(GLfloat)h,1.0,100.0);
glMatrixMode(GL_MODELVIEW);
updateGL();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This code is zooming in but the zoomfactor starts from 1.0 and goes upto 0.2 after 0.2 it just disappears from the screen

// how can I control this steps so that as it gets closer the zoomFactor should slow down
//and we can see larger onto the core of the object.
//
//Any help would be appreciated !

JohannesMunk
1st November 2009, 23:54
Hi!

The first parameter to gluperspective is the vertical angle in degrees spanned between the camera position and the near planes borders.

Have a look at the projection tutor here: http://www.xmission.com/~nate/tutors.html

I don't think, that the FOV parameter is supposed to be lower than 1. If you need more zoom, just move your camera closer to the model. You can use gluLookAt(cam.position,cam.lookat,upvector) for that.

This topic is not quite Qt related.. You might find better suited forums for opengl specific questions..

Johannes