Question about glFrustum and gluLookAt

Started by TimmerCA, June 25, 2011, 19:50:51

Previous topic - Next topic

TimmerCA

Hi,

I'm building a sort of "world explorer" applet that allows users to pan and zoom around in my game world in much the same way that Google Maps allows you to do so for the real world.  The major difference is that I'm actually giving my users a 3D view rather than just stitching together 2D pictures.

So, in my initialization routing, I'm calling:

float aspect_ratio = (float)displayParent.getWidth() / (float)displayParent.getHeight();
GL11.glViewport(0, 0, displayParent.getWidth(), displayParent.getHeight());
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glFrustum(-aspect_ratio, aspect_ratio, -1.0f, 1.0f, 1.0f, 1000.0f);


First question: what units are the first four parameters to glFrustum in?  Are they "unit" units, or radians, or what?  What would sensible values be for essentially a top-down bird's eye view of terrain be?  It seems that values around 1.0 or 2.0 work well, but I'd like to know exactly what I'm specifying here.

Then, in my game loop, I'm calling:

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GLU.gluLookAt(location_x, location_y, location_z, location_x, location_y, -1000.0f, 0.0f, 1.0f, 0.0f);

float tile_radius = 100.0f;
float tile_stride = 10.0f;

float start_x = (float)Math.floor(location_x - tile_radius) * aspect_ratio;
float start_y = (float)Math.floor(location_y - tile_radius);

float end_x = (float)Math.ceil(location_x + tile_radius) * aspect_ratio;
float end_y = (float)Math.ceil(location_y + tile_radius);

for (float x = start_x; x <= end_x; x += tile_stride) {
  for (float y = start_y; y <= end_y; y += tile_stride) {
    // calculate elevations...

    GL11.glBegin(GL11.GL_POLYGON);
    GL11.glVertex3f(x, y, elevation_top_left);
    GL11.glVertex3f(x + tile_stride, y, elevation_top_right);
    GL11.glVertex3f(x, y + tile_stride, elevation_bottom_left);
    GL11.glEnd();
  }
}


Note: Yes, I realize that I'm only drawing one triangle when I ought to be drawing two; I'm just drawing the one for now so that I can see the different polygons better for debugging purposes.

This mostly works - I can see polygons on the screen and they appear to be rendered at the correct elevations and so on.  However: when I change location_x or location_y, I would expect that the elevations of the polygons should change, but the X and Y coordinates relative to the viewport should remain the same.  That is, when I drag the map left or right, the portion of the map that I'm looking at should change, but the location of the polygons in the viewport ought to remain the same.  Interestingly, the Y-axis behaves correctly, but the X axis does not - it is possible for me to drag all the polygons off the left or right side of the viewport.

What am I doing wrong here?

TimmerCA

For what it's worth, I answered my first question by using gluPerspective instead.  I still would love to know what units the first four parameters are to be given in.

Also, the second problem went away after some other updates, so I'm chalking that up to an errant variable or something.