diff --git a/EGrScene.cpp b/EGrScene.cpp index 39667d7..d312653 100644 --- a/EGrScene.cpp +++ b/EGrScene.cpp @@ -22,7 +22,7 @@ using namespace std ; //--------------------------- Constants -------------------------------------- static const double MIN_DIST_CAMERA = 10 ; static const double STD_DIST_CAMERA = 1000 ; -static const double MIN_EXTENSION = 100 ; +static const double MIN_EXTENSION = 50 ; //--------------------------- Structs ---------------------------------------- struct Vert3f { @@ -42,15 +42,15 @@ EGrScene::EGrScene( void) memset( &m_wglewc, 0, sizeof( WGLEWContext)) ; memset( &m_glewc, 0, sizeof( GLEWContext)) ; m_bNewWay = false ; + // Geom data + SetExtension( BBox3d( -MIN_EXTENSION, -MIN_EXTENSION, -MIN_EXTENSION, + MIN_EXTENSION, MIN_EXTENSION, MIN_EXTENSION)) ; // Viewport m_nViewportW = 0 ; m_nViewportH = 0 ; // View data - SetCenter( ORIG) ; - SetCamera( 0, 0) ; - // Geom data - SetExtension( BBox3d( -MIN_EXTENSION, -MIN_EXTENSION, -MIN_EXTENSION, - MIN_EXTENSION, MIN_EXTENSION, MIN_EXTENSION)) ; + m_ptCenter = ORIG ; + SetCamera( 0, 0, 0) ; } //---------------------------------------------------------------------------- @@ -60,7 +60,7 @@ EGrScene::~EGrScene( void) //---------------------------------------------------------------------------- bool -EGrScene::CreateContext( HDC hDC, bool bGenDriver, bool bDouBuff, int nColorBits, int nDepthBits) +EGrScene::CreateContext( HDC hDC, int nDriver, bool bDouBuff, int nColorBits, int nDepthBits) { // verifico validità Device Context if ( hDC == nullptr) @@ -81,7 +81,7 @@ EGrScene::CreateContext( HDC hDC, bool bGenDriver, bool bDouBuff, int nColorBits int nPixelFormat = ChoosePixelFormat( m_hDC, &pfd) ; if ( nPixelFormat == 0) return false ; - if ( bGenDriver) { + if ( nDriver == OD_SOFT) { int nPixFormGen = ChooseGenPixelFormat( nPixelFormat, bDouBuff, nColorBits, nDepthBits) ; if ( nPixFormGen != 0) nPixelFormat = nPixFormGen ; @@ -272,6 +272,8 @@ EGrScene::SetCenter( const Point3d& ptCenter) m_ptCenter = ptCenter ; // invalido ExtView m_bExtViewOk = false ; + // calcolo nuovi dati di Z clipping + CalcClippingPlanesFromExtView() ; return true ; } @@ -288,12 +290,14 @@ EGrScene::SetCamera( double dAngVertDeg, double dAngOrizzDeg, double dDist) // invalido Up e ExtView m_bUpOk = false ; m_bExtViewOk = false ; + // calcolo nuovi dati di Z clipping + CalcClippingPlanesFromExtView() ; return true ; } //---------------------------------------------------------------------------- bool -EGrScene::SetCamera( CameraDir nDir, double dDist) +EGrScene::SetCamera( int nDir, double dDist) { const double ANG_VERT_ISOVIEW = 54.73561032 ; double dAngVertDeg ; @@ -349,6 +353,43 @@ EGrScene::SetCamera( CameraDir nDir, double dDist) return SetCamera( dAngVertDeg, dAngOrizzDeg, dDist) ; } +//---------------------------------------------------------------------------- +void +EGrScene::GetCamera( double* pdAngVertDeg, double* pdAngOrizzDeg, double* pdDist) +{ + m_vtDirCamera.ToSpherical( nullptr, pdAngVertDeg, pdAngOrizzDeg) ; + if ( pdDist != nullptr) + *pdDist = m_dDistCamera ; +} + +//---------------------------------------------------------------------------- +int +EGrScene::GetCameraDir( void) +{ + if ( m_vtDirCamera.IsZplus()) + return CT_TOP ; + else if ( m_vtDirCamera.IsYminus()) + return CT_FRONT ; + else if ( m_vtDirCamera.IsXplus()) + return CT_RIGHT ; + else if ( m_vtDirCamera.IsYplus()) + return CT_BACK ; + else if ( m_vtDirCamera.IsXminus()) + return CT_LEFT ; + else if ( m_vtDirCamera.IsZminus()) + return CT_BOTTOM ; + else if ( AreSameVectorNear( m_vtDirCamera, Vector3d( SQRT1_3, - SQRT1_3, - SQRT1_3))) + return CT_ISO_SW ; + else if ( AreSameVectorNear( m_vtDirCamera, Vector3d( SQRT1_3, SQRT1_3, - SQRT1_3))) + return CT_ISO_SE ; + else if ( AreSameVectorNear( m_vtDirCamera, Vector3d( SQRT1_3, SQRT1_3, SQRT1_3))) + return CT_ISO_NE ; + else if ( AreSameVectorNear( m_vtDirCamera, Vector3d( SQRT1_3, - SQRT1_3, SQRT1_3))) + return CT_ISO_NW ; + else + return CT_NONE ; +} + //---------------------------------------------------------------------------- bool EGrScene::CalcDirUp( void) @@ -356,18 +397,17 @@ EGrScene::CalcDirUp( void) // verifico se il calcolo è necessario if ( m_bUpOk) return true ; - // direzione di vista - Vector3d vtView = - m_vtDirCamera ; // direzione perpendicolare giacente nel piano XY - Vector3d vtPerpXY = vtView ^ Z_AX ; + // ( m_vtDirCamera è opposta alla direzione in cui si guarda) + Vector3d vtPerpXY = m_vtDirCamera ^ Z_AX ; if ( ! vtPerpXY.Normalize()) { - if ( vtView.z > 0) + if ( m_vtDirCamera.z < 0) vtPerpXY = X_AX ; else vtPerpXY = - X_AX ; } // direzione Up - m_vtUp = vtPerpXY ^ vtView ; + m_vtUp = vtPerpXY ^ m_vtDirCamera ; m_bUpOk = m_vtUp.Normalize() ; // invalido ExtView m_bExtViewOk = false ; @@ -420,18 +460,30 @@ EGrScene::ZoomAll( void) return false ; m_ptCenter = ptExtCent ; m_bExtViewOk = false ; - // calcolo estensione nel riferimento di vista - if ( ! CalcExtView()) - return false ; - // calcolo dati di ingombro - Point3d ptMin ; - Point3d ptMax ; - m_b3ExtView.GetMinMax( ptMin, ptMax) ; - m_dHalfWidth = 1.05 * max( fabs( ptMin.x), fabs( ptMax.x)) ; - m_dHalfHeight = 1.05 * max( fabs( ptMin.y), fabs( ptMax.y)) ; + + // calcolo nuovi dati di ingombro CalcDimViewFromExtView() ; - m_dZNear = - ptMax.z - 100 ; - m_dZFar = - ptMin.z + 100 ; + CalcClippingPlanesFromExtView() ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +EGrScene::ZoomChange( double dCoeff) +{ + const double MIN_COEFF = 0.5 ; + const double MAX_COEFF = 2 ; + + // controllo i limiti + if ( dCoeff < MIN_COEFF) + dCoeff = MIN_COEFF ; + else if ( dCoeff > MAX_COEFF) + dCoeff = MAX_COEFF ; + // cambio le dimensioni di zoom + m_dHalfWidth *= dCoeff ; + m_dHalfHeight *= dCoeff ; + return true ; } @@ -439,12 +491,22 @@ EGrScene::ZoomAll( void) bool EGrScene::CalcDimViewFromExtView( void) { + // calcolo estensione nel riferimento di vista + if ( ! CalcExtView()) + return false ; + + // recupero gli ingombri Point3d ptMin ; Point3d ptMax ; - m_b3ExtView.GetMinMax( ptMin, ptMax) ; - double dHalfWidth = 1.05 * max( fabs( ptMin.x), fabs( ptMax.x)) ; - double dHalfHeight = 1.05 * max( fabs( ptMin.y), fabs( ptMax.y)) ; + if ( ! m_b3ExtView.GetMinMax( ptMin, ptMax)) + return false ; + // ricavo le dimensioni + const double COEFF = 1.05 ; + double dHalfWidth = COEFF * max( fabs( ptMin.x), fabs( ptMax.x)) ; + double dHalfHeight = COEFF * max( fabs( ptMin.y), fabs( ptMax.y)) ; + + // adatto le dimensioni a quelle della vista return AdjustDimView( dHalfWidth, dHalfHeight) ; } @@ -477,24 +539,69 @@ EGrScene::AdjustDimView( double dHalfWidth, double dHalfHeight) } //---------------------------------------------------------------------------- -void +bool +EGrScene::CalcClippingPlanesFromExtView( void) +{ + // calcolo estensione nel riferimento di vista + if ( ! CalcExtView()) + return false ; + + // recupero gli ingombri + Point3d ptCenter ; + Vector3d vtExtent ; + if ( ! m_b3ExtView.GetCenterExtent( ptCenter, vtExtent)) + return false ; + // ricavo la posizione dei piani di clipping sull'asse Z di vista + const double EXP_COEFF = 1.05 ; + double dExtent = __max( ( EXP_COEFF * vtExtent.z), MIN_EXTENSION) ; + m_dZNear = - ( ptCenter.z + dExtent) ; + m_dZFar = - ( ptCenter.z - dExtent) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +EGrScene::Reshape( int nW, int nH) +{ + if ( ! MakeCurrent()) + return true ; + + // assegno le dimensioni della vista + m_nViewportW = nW ; + m_nViewportH = nH ; + + // aggiorno la vista + glViewport( 0, 0, m_nViewportW, m_nViewportH) ; + + // aggiorno + AdjustDimView( m_dHalfWidth, m_dHalfHeight) ; + + // ridisegno + return Draw() ; +} + +//---------------------------------------------------------------------------- +bool EGrScene::Prepare( void) { - MakeCurrent() ; + // imposto il rendering corrente + if ( ! MakeCurrent()) + return false ; // imposto il colore dello sfondo - glClearColor( 0.0, 0.0, 1.0, 0.0) ; + glClearColor( 0.1f, 0.1f, 0.5f, 0.0f) ; // eventuale ricalcolo parametri di vista CalcDirUp() ; - // do other preparations here + // imposto matrice di proiezione glMatrixMode( GL_PROJECTION) ; glLoadIdentity() ; glOrtho( - m_dHalfWidth, m_dHalfWidth, - m_dHalfHeight, m_dHalfHeight, m_dZNear, m_dZFar) ; GLenum nErr = glGetError() ; + // imposto matrice modello/vista glMatrixMode( GL_MODELVIEW) ; glLoadIdentity() ; Point3d ptCamera = m_ptCenter + m_dDistCamera * m_vtDirCamera ; @@ -503,52 +610,36 @@ EGrScene::Prepare( void) m_vtUp.x, m_vtUp.y, m_vtUp.z) ; nErr = glGetError() ; + + return true ; } //---------------------------------------------------------------------------- -void -EGrScene::Reshape( int nW, int nH) -{ - if ( m_hDC == nullptr) - return ; - - // assegno le dimensioni della vista - m_nViewportW = nW ; - m_nViewportH = nH ; - - // aggiorno la vista - if ( MakeCurrent()) - glViewport( 0, 0, m_nViewportW, m_nViewportH) ; - - // aggiorno - AdjustDimView( m_dHalfWidth, m_dHalfHeight) ; - Prepare() ; - - // ridisegno - Draw() ; -} - -//---------------------------------------------------------------------------- -void +bool EGrScene::Draw( void) { + // imposto + if ( ! Prepare()) + return false ; - MakeCurrent() ; - - //-------------------------------- - - //-------------------------------- + // cancello glClear( GL_COLOR_BUFFER_BIT) ; + // disegno for ( int i = 0 ; i < NUM_VAO ; ++ i) { if ( m_vaoID[i] != 0) { glBindVertexArray( m_vaoID[i]) ; glDrawArrays( m_nMode[i], 0, m_nCount[i]) ; } } - //-------------------------------- + + // aggiorno glFlush() ; + + // scambio i buffer back e front (se previsti) SwapBuffers( m_hDC) ; + + return true ; } //---------------------------------------------------------------------------- @@ -591,6 +682,7 @@ EGrScene::SetSquare( void) if ( ! MakeCurrent()) return ; + // vertici size_t nSizeV3f = sizeof( Vert3f) ; Vert3f Point[4] ; SET_VERT3F( Point[0], -0.5f, -0.5f, 0.0f) @@ -598,6 +690,12 @@ EGrScene::SetSquare( void) SET_VERT3F( Point[2], 0.5f, 0.5f, 0.0f) SET_VERT3F( Point[3], 0.5f, -0.5f, 0.0f) + // dimensioni di ingombro + BBox3d b3Ext ; + for ( int i = 0 ; i < 4 ; ++ i) + b3Ext.Add( Point[i].x, Point[i].y, Point[i].z) ; + SetExtension( b3Ext) ; + // inizializzo VAOs a non allocati for ( int i = 0 ; i < NUM_VAO ; ++ i) m_vaoID[i] = 0 ; @@ -619,10 +717,13 @@ EGrScene::SetSquare( void) glBufferSubData( GL_ARRAY_BUFFER, 2 * nSizeV3f, nSizeV3f, &Point[2]) ; glBufferSubData( GL_ARRAY_BUFFER, 3 * nSizeV3f, nSizeV3f, &Point[3]) ; glBufferSubData( GL_ARRAY_BUFFER, 4 * nSizeV3f, nSizeV3f, &Point[0]) ; - glVertexAttribPointer( (GLuint)0, 4, GL_FLOAT, GL_FALSE, 0, 0) ; + glVertexAttribPointer( (GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0) ; glEnableVertexAttribArray( 0) ; glBindVertexArray( 0) ; } + else { + + } } //---------------------------------------------------------------------------- @@ -632,6 +733,7 @@ EGrScene::SetCube( void) if ( ! MakeCurrent()) return ; + // vertici size_t nSizeV3f = sizeof( Vert3f) ; Vert3f Point[8] ; SET_VERT3F( Point[0], -0.5f, -0.5f, 0.0f) @@ -643,6 +745,12 @@ EGrScene::SetCube( void) SET_VERT3F( Point[6], 0.5f, 0.5f, 1.0f) SET_VERT3F( Point[7], 0.5f, -0.5f, 1.0f) + // dimensioni di ingombro + BBox3d b3Ext ; + for ( int i = 0 ; i < 8 ; ++ i) + b3Ext.Add( Point[i].x, Point[i].y, Point[i].z) ; + SetExtension( b3Ext) ; + // inizializzo VAOs a non allocati for ( int i = 0 ; i < NUM_VAO ; ++ i) m_vaoID[i] = 0 ; @@ -707,21 +815,24 @@ EGrScene::SetCube( void) void EGrScene::SetTriangle( void) { - MakeCurrent() ; + if ( ! MakeCurrent()) + return ; - GLfloat TriangleA[] = { - -0.3f, 0.5f, -1.0f, 1.0f, - -0.8f, -0.5f, -1.0f, 1.0f, - 0.2f, -0.5f, -1.0f, 1.0f, - -0.3f, 0.5f, -1.0f, 1.0f - } ; + // vertici + size_t nSizeV3f = sizeof( Vert3f) ; + Vert3f Point[6] ; + SET_VERT3F( Point[0], -0.3f, 0.5f, -1.0f) + SET_VERT3F( Point[1], -0.8f, -0.5f, -1.0f) + SET_VERT3F( Point[2], 0.2f, -0.5f, -1.0f) + SET_VERT3F( Point[3], -0.2f, 0.5f, -1.0f) + SET_VERT3F( Point[4], 0.3f, -0.5f, -1.0f) + SET_VERT3F( Point[5], 0.8f, 0.5f, -1.0f) - GLfloat TriangleB[] = { - -0.2f, 0.5f, -1.0f, 1.0f, - 0.3f, -0.5f, -1.0f, 1.0f, - 0.8f, 0.5f, -1.0f, 1.0f, - -0.2f, 0.5f, -1.0f, 1.0f - } ; + // dimensioni di ingombro + BBox3d b3Ext ; + for ( int i = 0 ; i < 6 ; ++ i) + b3Ext.Add( Point[i].x, Point[i].y, Point[i].z) ; + SetExtension( b3Ext) ; // inizializzo VAOs a non allocati for ( int i = 0 ; i < NUM_VAO ; ++ i) @@ -735,22 +846,30 @@ EGrScene::SetTriangle( void) glBindVertexArray( m_vaoID[0]) ; glGenBuffers( 1, &m_vboID[0]) ; //VBO allocation glBindBuffer( GL_ARRAY_BUFFER, m_vboID[0]) ; - glBufferData( GL_ARRAY_BUFFER, sizeof(TriangleA), TriangleA, GL_STATIC_DRAW) ; - glVertexAttribPointer( (GLuint)0, 4, GL_FLOAT, GL_FALSE, 0, 0) ; - glEnableVertexAttribArray( 0) ; - glBindVertexArray( 0) ; m_nMode[0] = GL_LINE_STRIP ; m_nCount[0] = 4 ; + glBufferData( GL_ARRAY_BUFFER, 4 * nSizeV3f, NULL, GL_STATIC_DRAW) ; + glBufferSubData( GL_ARRAY_BUFFER, 0 * nSizeV3f, nSizeV3f, &Point[0]) ; + glBufferSubData( GL_ARRAY_BUFFER, 1 * nSizeV3f, nSizeV3f, &Point[1]) ; + glBufferSubData( GL_ARRAY_BUFFER, 2 * nSizeV3f, nSizeV3f, &Point[2]) ; + glBufferSubData( GL_ARRAY_BUFFER, 3 * nSizeV3f, nSizeV3f, &Point[0]) ; + glVertexAttribPointer( (GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0) ; + glEnableVertexAttribArray( 0) ; + glBindVertexArray( 0) ; // Second VAO setup glBindVertexArray( m_vaoID[1]) ; glGenBuffers( 1, &m_vboID[1]) ; //VBO allocation glBindBuffer( GL_ARRAY_BUFFER, m_vboID[1]) ; - glBufferData( GL_ARRAY_BUFFER, sizeof(TriangleB), TriangleB, GL_STATIC_DRAW) ; - glVertexAttribPointer( (GLuint)0, 4, GL_FLOAT, GL_FALSE, 0, 0) ; - glEnableVertexAttribArray( 0) ; - glBindVertexArray( 0) ; m_nMode[1] = GL_LINE_STRIP ; m_nCount[1] = 4 ; + glBufferData( GL_ARRAY_BUFFER, 4 * nSizeV3f, NULL, GL_STATIC_DRAW) ; + glBufferSubData( GL_ARRAY_BUFFER, 0 * nSizeV3f, nSizeV3f, &Point[3]) ; + glBufferSubData( GL_ARRAY_BUFFER, 1 * nSizeV3f, nSizeV3f, &Point[4]) ; + glBufferSubData( GL_ARRAY_BUFFER, 2 * nSizeV3f, nSizeV3f, &Point[5]) ; + glBufferSubData( GL_ARRAY_BUFFER, 3 * nSizeV3f, nSizeV3f, &Point[3]) ; + glVertexAttribPointer( (GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0) ; + glEnableVertexAttribArray( 0) ; + glBindVertexArray( 0) ; } } diff --git a/EGrScene.h b/EGrScene.h index 1b5ccfd..834d77e 100644 --- a/EGrScene.h +++ b/EGrScene.h @@ -26,28 +26,34 @@ class EGrScene { public : + enum OglDriver { OD_SOFT = 1, OD_OLD = 2, OD_NEW = 3} ; enum CameraDir { CT_NONE = 0, CT_TOP = 1, CT_FRONT = 2, CT_RIGHT = 3, CT_BACK = 4, CT_LEFT = 5, CT_BOTTOM = 6, CT_ISO_SW = 7, CT_ISO_SE = 8, CT_ISO_NE = 9, CT_ISO_NW = 10} ; public: EGrScene( void); virtual ~EGrScene( void); - bool CreateContext( HDC hDC, bool bGenDriver, bool bDouBuff, int nColorBits, int nDepthBits) ; + bool CreateContext( HDC hDC, int nDriver, bool bDouBuff, int nColorBits, int nDepthBits) ; bool IsValid( void) { return ( m_hDC != nullptr && m_hRC != nullptr) ; } std::string GetOpenGLInfo( void) ; std::string GetGLSLInfo( void) ; std::string GetPixelFormatInfo( void) ; - void Prepare( void) ; - void Reshape( int nW, int nH) ; - void Draw( void) ; + bool Prepare( void) ; + bool Reshape( int nW, int nH) ; + bool Draw( void) ; void Destroy( void) ; bool SetCenter( const Point3d& ptCenter) ; - bool SetCamera( double dAngVertDeg, double dAngOrizzDeg, double dDist = 0) ; - bool SetCamera( CameraDir nDir, double dDist = 0) ; + bool SetCamera( double dAngVertDeg, double dAngOrizzDeg, double dDist) ; + bool SetCamera( int nDir, double dDist = 0) ; + const Point3d& GetCenter( void) + { return m_ptCenter ; } + void GetCamera( double* pdAngVertDeg, double* pdAngOrizzDeg, double* pdDist = nullptr) ; + int GetCameraDir( void) ; bool SetExtension( const BBox3d& b3Ext) ; bool ZoomAll( void) ; + bool ZoomChange( double dCoeff) ; void SetData( int nType) ; void ResetData( void) ; @@ -64,6 +70,7 @@ class EGrScene bool CalcExtView( void) ; bool CalcDimViewFromExtView( void) ; bool AdjustDimView( double dHalfWidth, double dHalfHeight) ; + bool CalcClippingPlanesFromExtView( void) ; void SetTriangle( void) ; void SetSquare( void) ; diff --git a/TestEGr.rc b/TestEGr.rc index 189394c..641040b 100644 Binary files a/TestEGr.rc and b/TestEGr.rc differ diff --git a/TestEGr.vcxproj b/TestEGr.vcxproj index 3e3dc93..9bcdb7d 100644 --- a/TestEGr.vcxproj +++ b/TestEGr.vcxproj @@ -202,6 +202,11 @@ + + + + + diff --git a/TestEGr.vcxproj.filters b/TestEGr.vcxproj.filters index 43fa667..0fa3099 100644 --- a/TestEGr.vcxproj.filters +++ b/TestEGr.vcxproj.filters @@ -44,6 +44,21 @@ File di intestazione + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + diff --git a/TestEGrDlg.cpp b/TestEGrDlg.cpp index 42daffa..b976b7e 100644 --- a/TestEGrDlg.cpp +++ b/TestEGrDlg.cpp @@ -83,8 +83,11 @@ BEGIN_MESSAGE_MAP( CTestEGrDlg, CDialog) ON_WM_QUERYDRAGICON() ON_WM_SIZE() ON_WM_CLOSE() - ON_COMMAND( IDC_ZOOM_ALL, OnZoomAll) - ON_COMMAND( IDC_CLOSE, OnClose) + ON_BN_CLICKED( IDC_ZOOM_ALL, OnZoomAll) + ON_BN_CLICKED( IDC_ZOOM_P, OnZoomPlus) + ON_BN_CLICKED( IDC_ZOOM_M, OnZoomMinus) + ON_CONTROL_RANGE( BN_CLICKED, IDC_VIEW_TOP, IDC_VIEW_ISO, OnView) + ON_BN_CLICKED( IDC_CLOSE, OnClose) END_MESSAGE_MAP() //---------------------------------------------------------------------------- @@ -166,6 +169,7 @@ CTestEGrDlg::OnPaint( void) dc.DrawIcon( x, y, m_hIcon) ; } else { + //m_Scene.Reshape( 0, 0) ; m_Scene.Draw() ; m_View.ValidateRgn( NULL) ; CDialog::OnPaint() ; @@ -196,6 +200,14 @@ CTestEGrDlg::OnSize( UINT nType, int cx, int cy) if ( nType == SIZE_RESTORED || nType == SIZE_MAXIMIZED) { // spostamento bottoni MoveDlgItem( IDC_ZOOM_ALL, cx, cy) ; + MoveDlgItem( IDC_ZOOM_P, cx, cy) ; + MoveDlgItem( IDC_ZOOM_M, cx, cy) ; + MoveDlgItem( IDC_VIEW_TOP, cx, cy) ; + MoveDlgItem( IDC_VIEW_FRONT, cx, cy) ; + MoveDlgItem( IDC_VIEW_BACK, cx, cy) ; + MoveDlgItem( IDC_VIEW_LEFT, cx, cy) ; + MoveDlgItem( IDC_VIEW_RIGHT, cx, cy) ; + MoveDlgItem( IDC_VIEW_ISO, cx, cy) ; MoveDlgItem( IDC_CLOSE, cx, cy) ; // adattamento finestra if ( m_Scene.IsValid()) { @@ -209,6 +221,8 @@ CTestEGrDlg::OnSize( UINT nType, int cx, int cy) // salvo la nuova dimensione m_nPrevCx = cx ; m_nPrevCy = cy ; + // lancio ridisegno + Invalidate() ; } } @@ -244,12 +258,59 @@ CTestEGrDlg::OnZoomAll( void) RedrawWindow() ; } +//---------------------------------------------------------------------------- +void +CTestEGrDlg::OnZoomPlus( void) +{ + m_Scene.ZoomChange( 0.9) ; + RedrawWindow() ; +} + +//---------------------------------------------------------------------------- +void +CTestEGrDlg::OnZoomMinus( void) +{ + m_Scene.ZoomChange( 1.1) ; + RedrawWindow() ; +} + +//---------------------------------------------------------------------------- +void +CTestEGrDlg::OnView( UINT nID) +{ + switch ( nID) { + case IDC_VIEW_TOP : + m_Scene.SetCamera( EGrScene::CT_TOP) ; + break ; + case IDC_VIEW_FRONT : + m_Scene.SetCamera( EGrScene::CT_FRONT) ; + break ; + case IDC_VIEW_BACK : + m_Scene.SetCamera( EGrScene::CT_BACK) ; + break ; + case IDC_VIEW_LEFT : + m_Scene.SetCamera( EGrScene::CT_LEFT) ; + break ; + case IDC_VIEW_RIGHT : + m_Scene.SetCamera( EGrScene::CT_RIGHT) ; + break ; + case IDC_VIEW_ISO : + m_Scene.SetCamera( EGrScene::CT_ISO_SW) ; + break ; + default : + return ; + break ; + } + + RedrawWindow() ; +} + //---------------------------------------------------------------------------- void CTestEGrDlg::StartScene( void) { // recupero i parametri - bool bGenDriver = ( GetPrivateProfileInt( "OpenGL", "GenDriver", 0, AfxGetApp()->m_pszProfileName) == 1) ; + int nDriver = ( GetPrivateProfileInt( "OpenGL", "Driver", 2, AfxGetApp()->m_pszProfileName) == 1) ; bool bDouBuff = ( GetPrivateProfileInt( "OpenGL", "DoubleBuffer", 1, AfxGetApp()->m_pszProfileName) == 1) ; int nColorBits = GetPrivateProfileInt( "OpenGL", "ColorBits", 16, AfxGetApp()->m_pszProfileName) ; int nDepthBits = GetPrivateProfileInt( "OpenGL", "DepthBits", 16, AfxGetApp()->m_pszProfileName) ; @@ -264,18 +325,13 @@ CTestEGrDlg::StartScene( void) m_View.Create( this, IDC_SCENE) ; // creazione della scena - m_Scene.CreateContext( m_View.GetDC()->m_hDC, bGenDriver, bDouBuff, nColorBits, nDepthBits) ; + m_Scene.CreateContext( m_View.GetSafeHdc(), nDriver, bDouBuff, nColorBits, nDepthBits) ; // impostazione dati geometrie - m_Scene.SetData( 2) ; - m_Scene.SetExtension( BBox3d( -0.5, -0.5, 0, 0.5, 0.5, 1)) ; + m_Scene.SetData( 3) ; // impostazione dati di vista - m_Scene.SetCenter( Point3d( 100, 0, 0)) ; + m_Scene.SetCenter( Point3d( 0, 0, 0)) ; m_Scene.SetCamera( EGrScene::CT_ISO_SW) ; m_Scene.ZoomAll() ; - - // calcolo - m_Scene.Prepare() ; - } diff --git a/TestEGrDlg.h b/TestEGrDlg.h index 7bf9190..2a26959 100644 --- a/TestEGrDlg.h +++ b/TestEGrDlg.h @@ -35,6 +35,9 @@ class CTestEGrDlg : public CDialog afx_msg HCURSOR OnQueryDragIcon( void) ; afx_msg void OnSize( UINT nType, int cx, int cy) ; afx_msg void OnZoomAll( void) ; + afx_msg void OnZoomPlus( void) ; + afx_msg void OnZoomMinus( void) ; + afx_msg void OnView( UINT nID) ; afx_msg void OnClose( void) ; private : diff --git a/TestEGrView.h b/TestEGrView.h index b6de0c3..5cf9e3c 100644 --- a/TestEGrView.h +++ b/TestEGrView.h @@ -4,11 +4,23 @@ #include -// TestEgrView +//---------------------------------------------------------------------------- class TestEgrView : public CWnd { public : TestEgrView( void) ; + ~TestEgrView( void) ; bool Create( CWnd* pParent, int nID) ; + HDC GetSafeHdc( void) + { return ( ( m_pDC != nullptr) ? m_pDC->GetSafeHdc() : nullptr) ; } + + protected : + afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct) ; + afx_msg void OnPaint( void) ; + + private : + CClientDC* m_pDC ; + + DECLARE_MESSAGE_MAP() } ; \ No newline at end of file diff --git a/TestEgrView.cpp b/TestEgrView.cpp index 37c5c95..5f5f28e 100644 --- a/TestEgrView.cpp +++ b/TestEgrView.cpp @@ -1,15 +1,43 @@ -// TestEgrView - +//---------------------------------------------------------------------------- +// EgalTech 2013-2014 +//---------------------------------------------------------------------------- +// File : TestEGrView.cpp Data : 05.02.14 Versione : 1.5b3 +// Contenuto : Implementazione della classe gestione vista OpenGL. +// +// +// +// Modifiche : 29.01.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "TestEgrView.h" #include "resource.h" +//---------------------------------------------------------------------------- +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +//---------------------------------------------------------------------------- +BEGIN_MESSAGE_MAP( TestEgrView, CWnd) + ON_WM_CREATE() +END_MESSAGE_MAP() + //---------------------------------------------------------------------------- TestEgrView::TestEgrView( void) { + m_pDC = nullptr ; +} +//---------------------------------------------------------------------------- +TestEgrView::~TestEgrView( void) +{ + if ( m_pDC != nullptr) + delete m_pDC ; + m_pDC = nullptr ; } //---------------------------------------------------------------------------- @@ -21,7 +49,8 @@ TestEgrView::Create( CWnd* pParent, int nID) return false ; CString className = AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW | CS_OWNDC, - AfxGetApp()->LoadCursor( IDC_POINTER), NULL, NULL) ; + AfxGetApp()->LoadCursor( IDC_POINTER), + (HBRUSH)GetStockObject(WHITE_BRUSH), NULL) ; CRect rectWin ; pParent->GetDlgItem( nID)->GetWindowRect( rectWin) ; @@ -35,3 +64,17 @@ TestEgrView::Create( CWnd* pParent, int nID) else return false ; } + +//---------------------------------------------------------------------------- +int +TestEgrView::OnCreate( LPCREATESTRUCT lpCreateStruct) +{ + if ( CWnd::OnCreate( lpCreateStruct) == -1) + return -1 ; + + m_pDC = new CClientDC( this) ; + if ( m_pDC == nullptr) + return -1 ; + + return 0 ; +} diff --git a/resource.h b/resource.h index 5abf7f6..74a18a7 100644 Binary files a/resource.h and b/resource.h differ