Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: converting from ortho to perspective view

  1. #11
    Junior Member Newbie bytebucket's Avatar
    Join Date
    Dec 2008
    Location
    Eastern PA, USA
    Posts
    23

    Re: converting from ortho to perspective view

    that's correct. it was a typo when I posted the code I'm calling glLoadIdentity first, then glTranslate.

  2. #12
    Junior Member Newbie
    Join Date
    Apr 2010
    Posts
    2

    Re: converting from ortho to perspective view

    I have the set the ortho for my data with these boundaries and can view view it.I followed the steps to convert ortho to perspective suggested in this thread and I get blank screen.Can you suggest the soultion..

    Xmin=398291.437500
    Xmax=400033.000000
    Ymin=135049.078125
    Ymx=137133.796875
    Zmin=-5.624723
    Zmax=84.187180

    Ortho
    =====

    void resizeGL(int w, int h)
    {
    if(h<=0) h=1 ;

    //To Preserve Aspect Ratio
    float fWorldW=sBoundingBox.fMaxX-sBoundingBox.fMinX;
    float fWorldH=sBoundingBox.fMaxY-sBoundingBox.fMinY;
    float fWorldR=fWorldW/fWorldH;
    float fViewportR=w/h;
    if(fWorldR>fViewportR)
    {
    glViewport(10,50,w,w/fWorldR);
    }
    else
    {
    glViewport(10,50,h*fWorldR,h);
    }

    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    //Assign Bounding Box Coordinates of Shapefile to glOrtho()
    glOrtho(sBoundingBox.fMinX, sBoundingBox.fMaxX,sBoundingBox.fMinY,sBoundingBox .fMaxY,sBoundingBox.fMinZ,sBoundingBox.fMaxZ);

    printf("xmin= %f,xmax=%f,ymin= %f,ymax=%f,zmin= %f,zmax=%f",sBoundingBox.fMinX, sBoundingBox.fMaxX,sBoundingBox.fMinY,sBoundingBox .fMaxY,sBoundingBox.fMinZ,sBoundingBox.fMaxZ);
    glMatrixMode(GL_MODELVIEW);
    }


    void GLDraw()
    {
    glClear (GL_COLOR_BUFFER_BIT);
    glLoadIdentity ();
    glColor4f(1.0,0.0,0.0,1.0);
    float xdelta=(sBoundingBox.fMinX+sBoundingBox.fMaxX)/2;
    float ydelta=(sBoundingBox.fMinY+sBoundingBox.fMaxY)/2;
    float zdelta=(sBoundingBox.fMinZ+sBoundingBox.fMaxZ)/2;

    glPushMatrix();
    glTranslatef(xdelta,ydelta,zdelta);
    glRotatef(-45.0f,1,0,0);
    glTranslatef(-xdelta,-ydelta,-zdelta);
    DrawPolygonShapefile1();//Rendering logic
    glPopMatrix();
    glFlush();
    }

    Perspective
    ==========

    double ConvertDegsToRads (double d)
    {
    return d * M_PI/180.0;
    }

    void resizeGL(int w, int h)
    {
    if(h<=0) h=1 ;
    //glViewport (0, 0, (GLsizei) w, (GLsizei) h);

    //To Preserve Aspect Ratio
    float fWorldW=sBoundingBox.fMaxX-sBoundingBox.fMinX;
    float fWorldH=sBoundingBox.fMaxY-sBoundingBox.fMinY;
    float fWorldR=fWorldW/fWorldH;
    float fViewportR=w/h;
    if(fWorldR>fViewportR)
    {
    glViewport(10,50,w,w/fWorldR);
    }
    else
    {
    glViewport(10,50,h*fWorldR,h);
    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    GLdouble vvLeft = sBoundingBox.fMinX;
    GLdouble vvRight = sBoundingBox.fMaxX;
    GLdouble vvBottom =sBoundingBox.fMinY;
    GLdouble vvTop = sBoundingBox.fMaxY;
    GLdouble vvNear = sBoundingBox.fMinZ;
    GLdouble vvFar = sBoundingBox.fMaxZ;

    GLdouble vvDepth = vvFar - vvNear;
    GLdouble vvHeight = vvTop - vvBottom;

    const GLdouble vvFovDegs = 45.0;
    GLdouble vvFovRads = ConvertDegsToRads(vvFovDegs);

    vvNear = (vvHeight / 2.0) / tan(vvFovRads / 2.0);
    vvFar = vvNear + vvDepth;

    glFrustum(vvLeft, vvRight, vvBottom, vvTop, vvNear, vvFar);

    glMatrixMode(GL_MODELVIEW);

    glTranslated(0,0,-(vvNear + (vvDepth / 2.0)));

    glLoadIdentity();

    }

    void GLDraw()
    {

    glClear (GL_COLOR_BUFFER_BIT);
    glLoadIdentity ();
    DrawPolygonShapefile1();
    glFlush();
    }

Posting Permissions

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