View Full Version : weird zoom-in with simulated earth

07-24-2008, 01:48 PM
My world has a coordinate system that represents the earth as a sphere. I can pan around my earth, and zoom in/out of my earth.

I pan by calling gluLookAt(x, y, z, 0, 0, 0, 0, 0, 1), where x, y, z is the center point of my canvas. The user uses the arrow keys to pan, each of which change the center point by some small amount in a certain direction.

I zoom by calling glOrtho(l, r, b, t, n, f), where l, r, b, and t are a function of my current zoom level, and n/f (z-ratio) is consistently between .001 and .002. As my zoom level changes, as does l, r, b, and t. That is, when I zoom in, the 4 variables get smaller, and vice-versa for zooming out.

To test something, I am drawing a small square at the center of the screen.

I call gluUnproject to convert the center-screen coordinates to world coordinates, and then make glVertex calls to draw the square. This works fine when I am zoomed out. However, when I zoom in very close, my square starts to get drawn inaccurately. It will be a quadrilateral, but certainly not a square. Again, when I am zoomed out, no problem, the square it drawn correctly.

I noticed that if I am panned to a point that is parallel to a plane (xz, yz, etc), the square is drawn correctly at all zoom levels. For example, when I am panned to the equivalent of 0 degrees latitude, 0 degrees longitude, where the square is parallel to the YZ-plane, there is no problem. Same with 0 degrees latitude, 90 degrees longitude (parallel to XZ-plane). But if I draw the square at 0 degrees latitude, 45 degrees latitude, is it drawn wonky.

Does this make sense to anyone? Why would I only see the problem in certain cases but not others?

I have tried switching to using gluPerspective instead (just to test), and I see the same issues.
I have tried all sorts of z-ratios, to no avail.

This is my code for setting the perspective.

-mViewingAlt is changed every time the user zooms in or out.
-mCenterLat and mCenterLon are changed every time the user pans.
-geodeticToXyz is just assuming a spherical earth.

void setPerspective()
double near_plane = 0.1;
double far_plane = 63781377*1.1;

glOrtho(-mViewingAlt, mViewingAlt, -mViewingAlt, mViewingAlt,
near_plane, far_plane);
double x, y, z;
geodeticToXyz(mCenterLat, mCenterLon, mViewingAlt, x, y, z);
gluLookAt(x, y, z, 0, 0, 0, 0, 0, 1);


This is my init. code:

void InitGL()
glClearColor(0.0, 0.0, 0.0, 0.0);

int w, h;
GetClientSize(&w, &h);
glViewport(0, 0, w, h);