//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : API_Scene.cpp Data : 01.09.14 Versione : 1.5i1 // Contenuto : Funzioni Scene per API. // // // // Modifiche : 01.09.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "API.h" #include "API_Macro.h" #include "/EgtDev/Include/EInAPI.h" #include "/EgtDev/Include/EgtPointerOwner.h" using namespace std ; //----------------------------------------------------------------------------- BOOL __stdcall EgtInitScene( HWND hWnd, int nDriver, int b2Buff, int nColorBits, int nDepthBits) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX( pGseCtx, FALSE) // inizializzazione scena OpenGL PtrOwner pScene( CreateEGrScene()) ; VERIFY_NULL( Get( pScene), "Error in CreateEGrScene", FALSE) HDC hdc = GetDC( hWnd) ; if ( ! pScene->CreateContext( hdc, nDriver, ( b2Buff != 0), nColorBits, nDepthBits)) return FALSE ; pScene->SetBackground( WHITE, WHITE) ; pScene->SetShowMode( SM_SHADING) ; pScene->SetShowCurveDirection( false) ; pScene->SetCamera( CT_TOP) ; pScene->ZoomAll() ; pScene->SetWinRectAttribs( true, BLACK) ; pScene->SetMark( YELLOW) ; pScene->Init( pGseCtx->m_pGeomDB) ; // assegno la scena al contesto pGseCtx->m_hWnd = hWnd ; pGseCtx->m_pScene = Release( pScene) ; // log con info sulla scena string sSceneInfo = pGseCtx->m_pScene->GetOpenGLInfo() + '\n' + pGseCtx->m_pScene->GetGLSLInfo() + '\n' + pGseCtx->m_pScene->GetPixelFormatInfo() ; LOG_INFO( GetLogger(), sSceneInfo.c_str()) return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetBackground( int nTopRed, int nTopGreen, int nTopBlue, int nBottomRed, int nBottomGreen, int nBottomBlue, BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // imposto lo sfondo pGseCtx->m_pScene->SetBackground( Color( nTopRed, nTopGreen, nTopBlue), Color( nBottomRed, nBottomGreen, nBottomBlue)) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetMarkAttribs( int nRed, int nGreen, int nBlue) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // imposto il colore del Mark Color MKcol( nRed, nGreen, nBlue) ; return ( pGseCtx->m_pScene->SetMark( MKcol) ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetGeoLineAttribs( int nRed, int nGreen, int nBlue) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // imposto il colore della linea geometrica gestita direttamente dalla scena Color Glcol( nRed, nGreen, nBlue) ; return ( pGseCtx->m_pScene->SetGeoLineAttribs( Glcol) ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetWinRectAttribs( BOOL bOutline, int nRed, int nGreen, int nBlue, int nAlpha) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // imposto il colore della linea geometrica gestita direttamente dalla scena Color WRcol( nRed, nGreen, nBlue, nAlpha) ; return ( pGseCtx->m_pScene->SetWinRectAttribs( ( bOutline != FALSE), WRcol) ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtResize( int nW, int nH) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, FALSE) // eseguo resize pScene->Resize( nW, nH) ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtDraw( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // eseguo disegno pGseCtx->m_pScene->Draw() ; // valido la finestra disegnata ValidateRgn( pGseCtx->m_hWnd, NULL) ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSelect( int nWinX, int nWinY, int nSelW, int nSelH, int* pnSel) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // eseguo la selezione return ( pGseCtx->m_pScene->Select( Point3d( nWinX, nWinY), nSelW, nSelH, *pnSel) ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- int __stdcall EgtGetFirstSelectedObj( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // restituisco il primo oggetto selezionato return pGseCtx->m_pScene->GetFirstSelectedObj() ; } //----------------------------------------------------------------------------- int __stdcall EgtGetNextSelectedObj( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // restituisco il successivo oggetto selezionato return pGseCtx->m_pScene->GetNextSelectedObj() ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtGetSelectedSnapPoint( int nSnap, int nWinX, int nWinY, int nSelW, int nSelH, double ptP[3]) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // trovo il punto snap da selezione Point3d ptSnap ; if ( ! pGseCtx->m_pScene->GetSelectedSnapPoint( nSnap, Point3d( nWinX, nWinY), nSelW, nSelH, ptSnap)) return FALSE ; ptP[0] = ptSnap.x ; ptP[1] = ptSnap.y ; ptP[2] = ptSnap.z ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetShowMode( int nShowMode, BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // imposto il modo di visualizzazione if ( nShowMode >= SM_WIREFRAME && nShowMode <= SM_SHADING) { pGseCtx->m_pScene->SetShowMode( nShowMode) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } else return FALSE ; } //----------------------------------------------------------------------------- int __stdcall EgtGetShowMode( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // recupero il modo di visualizzazione return pGseCtx->m_pScene->GetShowMode() ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetShowCurveDirection( BOOL bShow, BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // imposto stato pGseCtx->m_pScene->SetShowCurveDirection( bShow != FALSE) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtGetShowCurveDirection( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // recupero lo stato return pGseCtx->m_pScene->GetShowCurveDirection() ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtZoom( int nZoom, BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) const double COEFF_IN = 0.9 ; const double COEFF_OUT = 1 / COEFF_IN ; switch ( nZoom) { case 1 : pGseCtx->m_pScene->ZoomAll() ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; break ; case 2 : pGseCtx->m_pScene->ZoomChange( COEFF_IN) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; break ; case 3 : pGseCtx->m_pScene->ZoomChange( COEFF_OUT) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; break ; } return FALSE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtZoomOnPoint( int nWinX, int nWinY, double dCoeff, BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // eseguo zoom pGseCtx->m_pScene->ZoomOnPoint( Point3d( nWinX, nWinY), dCoeff) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetGeoLine( const double ptP1[3], const double ptP2[3], BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // disegno linea per distanza o similari pGseCtx->m_pScene->SetGeoLine( ptP1, ptP2) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtResetGeoLine( BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // cancello linea per distanza o similari pGseCtx->m_pScene->ResetGeoLine() ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetWinRect( int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // disegno finestra per zoom pGseCtx->m_pScene->SetWinRect( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtResetWinRect( BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // cancello finestra per zoom pGseCtx->m_pScene->ResetWinRect() ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtZoomWin( int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // eseguo zoom su finestra pGseCtx->m_pScene->ZoomWin( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetView( int nView, BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // imposto vista if ( nView >= CT_TOP && nView <= CT_ISO_NW) { pGseCtx->m_pScene->SetCamera( nView) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } else return FALSE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetGenericView( double dAngVertDeg, double dAngHorizDeg, BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // imposto vista pGseCtx->m_pScene->SetCamera( dAngVertDeg, dAngHorizDeg, 0) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetViewCenter( const double ptP[3], BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // imposto vista pGseCtx->m_pScene->SetCenter( ptP) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtPanCamera( int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // eseguo panoramica pGseCtx->m_pScene->PanCamera( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtRotateCamera( int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // eseguo rotazione camera pGseCtx->m_pScene->RotateCamera( Point3d( nPrevX, nPrevY), Point3d( nCurrX, nCurrY)) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtGetCameraDir( int* pnDir) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, FALSE) // recupero direzione di vista if ( pnDir == nullptr) return FALSE ; *pnDir = pScene->GetCameraDir() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtUnProjectPoint( int nWinX, int nWinY, double ptP[3]) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, FALSE) // eseguo l'inverso della proiezione (considero Z punto su centro) Point3d ptView( nWinX, nWinY, pScene->GetProjectedCenter().z) ; Point3d ptWorld ; if ( ! pScene->UnProject( ptView, ptWorld)) return FALSE ; ptP[0] = ptWorld.x ; ptP[1] = ptWorld.y ; ptP[2] = ptWorld.z ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtProjectPoint( const double ptP[3], double ptWin[3]) { IEGrScene* pScene = GetCurrScene() ; VERIFY_SCENE( pScene, FALSE) // eseguo la proiezione Point3d ptView ; if ( ! pScene->Project( ptP, ptView)) return FALSE ; ptWin[0] = ptView.x ; ptWin[1] = ptView.y ; ptWin[2] = ptView.z ; return TRUE ; }