Questions about glFrustum()

Hello;

I’m pretty much a newbie with openGL and wonderring few things about glFrustum() usage.
I tried using it in my program:


    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    // I kinda messed with the values until I get something correct.
    glFrustum(-15.0f, 15.0f, -60.0f, -35.0f, 50.0f, 400.0f); 

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

And noticed few things:

For some reason, after using glFrustum(), glTranslatef() on Y axis, seems to provoke a rotation instead of a translation ? Why ? o:
X, and Y axes are still fine.

I then don’t know if I’m kinda going crazy, but I truely feel like that both my X and Y axis are inverted.
When applying a translation with a negative X value, the scene is moving to the right and vice versa…
Is it because objects are rendered with a negative Z value ?

I then call glTranslatef():


// (Position.x and Position.z are 2 floats set at 0.0f by default)
glTranslatef(0.0f + position.x, -110.0f, 0.0f + position.z);

Here is what I get:

Which point a last problem, since glTranslatef() provokes a rotation (which fits what I want here), the Cubes are being slightly distorted.
Is there any way to deal with this ? How ?

This is the current way I’m drawing my cubes (using VBO)


void	Cube::Draw()
{
    glPushMatrix();
    
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_DEPTH_TEST);

    glMatrixMode(GL_MODELVIEW);
    glTranslatef(position.x, position.y, position.z);

    Texture_->bind();
    
    glBindBuffer(GL_ARRAY_BUFFER, CubeBuffers[0]);
    glVertexPointer(3, GL_FLOAT, 5 * sizeof(float), 0);
    glTexCoordPointer(2, GL_FLOAT, 5 * sizeof(float), (GLvoid*)(sizeof(float)*3));

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, CubeBuffers[1]);

    glEnableClientState( GL_VERTEX_ARRAY );
    glEnableClientState( GL_TEXTURE_COORD_ARRAY );

    glDrawElements(GL_TRIANGLE_STRIP, 36, GL_UNSIGNED_INT, 0);

    glDisableClientState( GL_TEXTURE_COORD_ARRAY );
    glDisableClientState( GL_VERTEX_ARRAY );

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_TEXTURE_2D);

    glPopMatrix();
}

In case it’d eventually come from it :confused:

Also a last question: I plan on trying to integrated the Frustum Culling, would the rotation provokated by glTranslatef() have an impact on that ?
And if I was rotating before calling glFrustum() ?

Sorry for asking so many questions, but i need to clear my mind :stuck_out_tongue:
Also sorry for any grammar / spelling mistake, english is not my main language ;o

Thanks a lot for your help !

[QUOTE=EvilSakray;1240015]…wonderring few things about glFrustum() usage.


    // I kinda messed with the values until I get something correct.
    glFrustum(-15.0f, 15.0f, -60.0f, -35.0f, 50.0f, 400.0f); 

[/QUOTE]

Ok, so you’ve got an asymmetric (off-axis) perspective view frustum, looking forward and down in EYE-SPACE. EYE-SPACE has +X right, +Y up, and +Z pointing out of the screen toward the eyepoint.

If you’re just messing with the values, you probably want an symmetric (on-axis) perspective view frustum. Try changing the bottom and top values to -15, 15 (i.e. bottom = -top).

For some reason, after using glFrustum(), glTranslatef() on Y axis, seems to provoke a rotation instead of a translation ? Why ?

No clue. However, I can tell you that what you see in asymmetric frustums can look pretty weird. Retry with a symmetric frustum. Also just to get your bearings, you might try an orthographic frustum (glOrtho instead of glFrustum).

I’d whack the position.x and position.z from that translation just to make sure that you’re doing what you think you’re doing.

Is it because objects are rendered with a negative Z value ?

In EYE-SPACE, only positions with negative Z values get rendered when you’re using a perspective view frustum. Specifically, those with Z values between -near and -far.

You don’t typically render your objects with their vertices already in EYE-SPACE though. You use the MODELVIEW matrix to transform them from OBJECT-SPACE through WORLD-SPACE to EYE-SPACE. One of the first things you usually stack on the MODELVIEW (after loading identity) is the VIEWING transform (this takes you from WORLD-SPACE to EYE-SPACE). See gluLookAt() for this. Then you stack on MODELING transforms after that.

Which point a last problem, since glTranslatef() provokes a rotation (which fits what I want here), the Cubes are being slightly distorted.
Is there any way to deal with this ? How ?

A perspective frustum will distort based on distance. Try a symmetric perspective frustum first. If you want to get rid of all distortion flip to an orthographic frustum.

Also a last question: I plan on trying to integrated the Frustum Culling, would the rotation provokated by glTranslatef() have an impact on that ?
And if I was rotating before calling glFrustum() ?

There are lots of ways to do culling. But it’s most straightforward to do it in EYE-SPACE. You use the MODELVIEW you’d use to draw the object to take the object (or more efficiently, it’s bounding primitive – e.g. bounding sphere) to EYE-SPACE. Then you frustum-cull it there. In this sense, your frustum is “fixed” in EYE-SPACE and it’s just your objects that move into EYE-SPACE to get culled.

You could of course do this differently – for instance cull in OBJECT-SPACE. This means transforming your view planes back into the OBJECT-SPACE of each object, but this is just extra work and the culling math tends to be less efficient that way (you end up having to cull against 6 arbitrary planes).

Also sorry for any grammar / spelling mistake, english is not my main language ;o

You’re doing great! Don’t worry about it.