Two-point perspective projection

Hello,
I am trying to impelement a two-point perspective projection and don’t really know how to fill custom matrix for such a case.
The problem is as follows.

  1. My camera is placed at camZ offset and camY height and looking at the origin point, which in turn the rotation center of the zx surface about Y axis.
  2. All objects are disposed on this zx surface.
  3. I need to create two-point perspective in order to eliminate any distortion along Y axis. In this case lines parallel to Y axis will remain parallel.
    I could not find any code examples written in openGL.
    Does anyone know how to do it?

Thank you in advance

alex

You would get that result by pointing the camera along the Z axis at the point (0, 0, camY) and only using the lower part of the rendered image, centered around the origin. To get that as your full image, you need to skew the view frustum.
Assuming your positive Y axis is up and negative Z is forward, this is the camera matrix you need to use:
1 0 0 0
0 1 -camY/camZ 0
0 0 1 -camZ
0 0 0 1

// Instead of your current camera matrix setup:
GLfloat cam[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, -camY/camZ, -camZ, 0, 0, 0, 0, 1 };
glLoadMatrixf(cam);

Hi Georg,
Thank you for reply. I tried to implement your suggestion and lost the building at all:)
The code I previously had was as follows:


    glViewport(0, 0, w, h);
        
    fAspect = (GLfloat)w / (GLfloat)h;

    // Reset the coordinate system before modifying
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    GLfloat zNear, zFar;
    zFar = 1000;
    // Set the clipping volume
    glFrustumf(-5*fAspect, 5*fAspect, -5, 5, 10, zFar);
    ugluLookAtf(0, camY, camZ, 0, camY, 0, 0, 1, 0);

    //GLfloat cam[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, -camY/camZ, -camZ, 0, 0, 0, 0, 1 };
    //glLoadMatrixf(cam);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    DrawBuilding();

If I replace ugluLookAtf() by matrix you suggested:
GLfloat cam[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, -camY/camZ, -camZ, 0, 0, 0, 0, 1 };
glLoadMatrixf(cam);
I don’t see the building.

I also moved glLoadMatrixf before glFrustum and received my building cut. Moving around didn’t show the whole building.
What can be wrong?

Thank you for attention.
The positive Z is toward viewer, Y is up.

Your use of ugluLookAtf doesn’t fit your initial description as you’re looking at the point (0, camY, 0), not the origin.

The code I suggested was intended to replace the initial setup of the modelview matrix, not the projection matrix. glLoadMatrix replaces the current matrix, so the way you use it overwrites the projection set up with glFrustum.
In general, the view/camera transformation (not to be confused with the projection) should be part of the modelview matrix.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLfloat zNear, zFar;
zFar = 1000;
// Set the clipping volume
glFrustumf(-5*fAspect, 5*fAspect, -5, 5, 10, zFar);

glMatrixMode(GL_MODELVIEW);
#if TWO_POINT
GLfloat cam[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, -camY/camZ, -camZ, 0, 0, 0, 0, 1 };
glLoadMatrixf(cam);
#else
glLoadIdentity();
ugluLookAtf(0, camY, camZ, 0, camY, 0, 0, 1, 0);
#endif

DrawBuilding();

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.