I am trying to make an easy way to rotate and zoom in a scene.
The problem with this code is that the view doesn’t change. When I output the camera parameters at each display() call, they are changing the way they should. Is there any blatant problem with why the screen is not updating?
Thanks,
Dave
void display(void)
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
DrawAxes(5, true);
Camera.Look();
glutSwapBuffers();
}
void CameraMouseMotion(int x, int y)
{
int verbosity = 1;
const int dx = x - Mouse.X;
const int dy = y - Mouse.Y;
if ( (dx == 0) && (dy == 0) )
return;
if (Mouse.Middle) //zoom
{
//Moving the mouse up zooms in
//Moving the mouse down zooms out
double scale = ((double)dy * .01);
geom_Vector3 MotionAlongView = Camera.ViewDirection().Normalized() * scale;
Camera.Position = Camera.Position + MotionAlongView;
Camera.ViewDepth += MotionAlongView.Magnitude();
}
else if (Mouse.Left) //rotate
{
double scale = .01;
Camera.theta += scale * dx;
Camera.phi += scale * dy;
}
else if (Mouse.Right) //translate
{
//moving the mouse left and right pans
//moving the mouse up and down moves the camera up and down
double scale = .01;
geom_Vector3 V(double(dx) * scale, double(dy) * scale, 0);
Camera.Position = Camera.Position + V;
}
Mouse.X = x;
Mouse.Y = y;
glutPostRedisplay();
}
void CameraClass::Look()
{
//cout << *this;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//gluLookAt(0, 10, 10, 0, 0, 0, 0, 1, 0);
gluLookAt(Position.getX(), Position.getY(), Position.getZ(), CenterOfView().getX(), CenterOfView().getY(), CenterOfView().getZ(), 0, 1, 0);
//eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz
}