Click here to Skip to main content
15,895,786 members
Articles / Desktop Programming / MFC

PicZoom: A Photo Viewer Created in OpenGL

Rate me:
Please Sign up or sign in to vote.
4.86/5 (64 votes)
16 Feb 2011CPOL16 min read 161K   11.6K   151  
PicZoom: A Photo Viewer created in OpenGL
#include "StdAfx.h"
#include "UnProject.h"
#include "gl\gl.h"
#include "gl\glu.h"
#include "Consts.h"

UnProject::UnProject( float& fZoom_i, float& fPanX_i, float& fPanY_i, int& nRotateIndex_i )
: m_fZoom( fZoom_i )
, m_fPanX( fPanX_i )
, m_fPanY( fPanY_i )
, m_nRotateIndex( nRotateIndex_i )
{
}

UnProject::~UnProject(void)
{
}

void UnProject::SetImageArea( const int nLeft, const int nTop_i, 
                  const int nWidth_i, const int nHeight_i )
{
    m_nLeft = nLeft;
    m_nTop = nTop_i;
    m_nRight = nLeft + nWidth_i;
    m_nBottom = nTop_i + nHeight_i;
}
bool UnProject::IsWithinRange( const int nX_i, const int nY_i )
{
    GLint viewport[4];
    GLdouble modelview[16];
    GLdouble projection[16];
    GLfloat winX, winY, winZ;
    GLdouble posX, posY, posZ;

    glMatrixMode( GL_MODELVIEW );
    glPushMatrix();
    glLoadIdentity();
    glTranslatef( m_fPanX, -m_fPanY, 0.0 );
    glScalef( m_fZoom, m_fZoom, 1.0 );
    float fRotationAngle = ROTATION_ANGLES[m_nRotateIndex];
    glRotatef( fRotationAngle, 0, 0, 1.0 );

    glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
    glGetDoublev( GL_PROJECTION_MATRIX, projection );
    glGetIntegerv( GL_VIEWPORT, viewport );

    winX = (float)nX_i;
    winY = (float) viewport[3] - nY_i;
    winZ = 0.0;
    gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);

    glPopMatrix();
    return( m_nLeft <= posX && posX <= m_nRight &&
        m_nTop <= posY && posY <= m_nBottom );

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions