CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    Unhappy Is my ortho projection correct

    Dear Friends
    I am using orthographic projection to render my 3d model. As I rotate the geometry the model gets distorted near the edeges at the top. Can u tell me anyone why is it happening. please check my code snippet.

    Code:
    void CRevolutionProjView::orthogonalStart()
    {
    	glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
        glOrtho(left_side*AR, right_side*AR, top_side, bottom_side, near_side, far_side);
    	glScalef(zoomFactor,zoomFactor,1);
    	glTranslatef(trans[0], trans[1], trans[2]);
    	glRotatef(rot[0], 1.0f, 0.0f, 0.0f);
    	glRotatef(rot[1], 0.0f, 1.0f, 0.0f);
    	glRotatef(rot[2], 0.0f, 0.0f, 1.0f);
        glMatrixMode(GL_MODELVIEW);
    }
    
    void CRevolutionProjView::orthogonalEnd()
    {
        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
        glMatrixMode(GL_MODELVIEW);
    }
    
    void CRevolutionProjView::DrawScene(CDC *pDC)
    {
    	wglMakeCurrent(pDC->m_hDC, m_hrc);
    	//---------------------------------
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glEnable(GL_DEPTH_TEST);
    	orthogonalStart();
    	glCallList(axes);
    	glCallList(object);
    	glPrintX("X");
        glPrintY("Y");
        glPrintZ("Z");
    	glFlush();
    	orthogonalEnd();
    	SwapBuffers(pDC->m_hDC);
    	wglMakeCurrent(NULL, NULL);
    }
    
    void CRevolutionProjView::Reshape(CDC *pDC, int w, int h)
    {
    	AR = (double)w/(double)h;
    	wd = w;
    	ht = h;
    	wglMakeCurrent(pDC->m_hDC, m_hrc);
    	//---------------------------------
    	glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
    	glMatrixMode (GL_PROJECTION);
    	glLoadIdentity ();
    	gluPerspective (45, (GLfloat)w / (GLfloat)h, 0.1, 1000.0);
     	glMatrixMode (GL_MODELVIEW);
    	Invalidate();
    	wglMakeCurrent(NULL, NULL);
    }
    Is my projection correct ??

  2. #2
    Join Date
    Sep 2011
    Posts
    75

    Re: Is my ortho projection correct

    I am a Noobie, but why are you setting up a perspective view when you are going to use Orthogonal view later?
    I beleive you need to make calls to
    Code:
    glViewport (0,0, width, height);
    
    	glMatrixMode (GL_PROJECTION);
    
    	glLoadIdentity();
    
    	// ORTHOGRAPHIC VIEW
    	
          glOrtho(-aspectRatio*VERTEX_SCALE, aspectRatio*VERTEX_SCALE, 
    		VERTEX_SCALE, -VERTEX_SCALE,zNear, zFar);
    	
    
    	glMatrixMode(GL_MODELVIEW);
    
    	glLoadIdentity();
    as you call orthogonalStart() as you are currently not switching to modify the projection matrix

    EDIT: Also, Holy Crap you have a lot of topics up here. Ever try using google?
    Last edited by kingting; November 2nd, 2011 at 05:29 PM.

  3. #3
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    Re: Is my ortho projection correct

    Dear Friends Please give me suggestions why is it coming breaking the model. isn't my code correct ??
    My drawscene and reshape functions are like this
    Code:
    void CRevolutionProjView::DrawScene(CDC *pDC)
    {
    	wglMakeCurrent(pDC->m_hDC, m_hrc);
    	//---------------------------------
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glEnable(GL_DEPTH_TEST);
    	glPushMatrix();
    	glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
    	if (wd <= ht)
        glOrtho(-range, range, -range*ht/wd, range*ht/wd, -range, range);
        else
    	glOrtho(-range*wd/ht, range*wd/ht, -range, range, -range, range);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	glTranslatef(trans[0], trans[1], trans[2]);
    	glRotatef(rot[0], 1.0f, 0.0f, 0.0f);
    	glRotatef(rot[1], 0.0f, 1.0f, 0.0f);
    	glRotatef(rot[2], 0.0f, 0.0f, 1.0f);
    	glScalef(zoomFactor,zoomFactor,zoomFactor);
    	glCallList(object);
    	glCallList(axes);
    	glPrintX("X");
        glPrintY("Y");
    	glPrintZ("Z");
    	glPopMatrix();
    	glFlush();
    	SwapBuffers(pDC->m_hDC);
    	wglMakeCurrent(NULL, NULL);
    }
    
    void CRevolutionProjView::Reshape(CDC *pDC, int w, int h)
    {
    	AR = (double)w/(double)h;
    	wd = w;
    	ht = h;
    	wglMakeCurrent(pDC->m_hDC, m_hrc);
    	//---------------------------------
    	glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
    	glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
    	glMatrixMode (GL_MODELVIEW);
    	wglMakeCurrent(NULL, NULL);
    }
    Please give some comment where it's till going wrong. ?? Thanks a lot for reply. Sujan

  4. #4
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    Re: Is my ortho projection correct

    check this file pic 1 is no distorsion and pic2 is distorted.....Please help me resolving this why is it happening......When I zoom in make the model large then its breaking at the top edge.
    Attached Images Attached Images   

  5. #5
    Join Date
    Jan 2009
    Posts
    596

    Re: Is my ortho projection correct

    Quote Originally Posted by sujan.dasmahapatra View Post
    check this file pic 1 is no distorsion and pic2 is distorted.....Please help me resolving this why is it happening......When I zoom in make the model large then its breaking at the top edge.
    That isn't distortion, it's clipping at the front clip plane. Do what kingting suggested to set the ortho view up, and make sure the zNear is small enough.

  6. #6
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    Re: Is my ortho projection correct

    Thanks friends for your helps....my problem is solved. I needed to decraese the4 znear and increase zfar..That solved my problem. PLease help me in findijng bottom view and north aest and southeast view of my isometric view on my other threads. Thanks sujan

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured