Results 1 to 4 of 4

Thread: two-point perspective projection

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    3

    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

  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: two-point perspective projection

    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

    Code :
    // 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);
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  3. #3
    Junior Member
    Join Date
    May 2009
    Posts
    3

    Re: two-point perspective projection

    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:
    Code :
        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.

  4. #4
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: two-point perspective projection

    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.

    Code :
    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();
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

Similar Threads

  1. Orthogonal and perspective projection at the same time.
    By Insight77 in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 04-06-2009, 09:38 AM
  2. Problem with Vincent 3D Library and perspective projection
    By Bomber81 in forum OpenGL ES 1.X - fixed function hardware
    Replies: 3
    Last Post: 03-23-2009, 08:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •