//---------------------------------------------------------------------------- // 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( int nGseCtx, HWND hWnd, int nDriver, int b2Buff, int nColorBits, int nDepthBits) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; 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 nGseCtx, int nTopRed, int nTopGreen, int nTopBlue, int nBottomRed, int nBottomGreen, int nBottomBlue, BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; 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 EgtDraw( int nGseCtx) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // eseguo disegno pGseCtx->m_pScene->Draw() ; // valido la finestra disegnata ValidateRgn( pGseCtx->m_hWnd, NULL) ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtResize( int nGseCtx, int nW, int nH) { IEGrScene* pScene = GetScene( nGseCtx) ; VERIFY_SCENE( pScene, FALSE) // eseguo resize pScene->Resize( nW, nH) ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetShowMode( int nGseCtx, int nShowMode, BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; 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 ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetShowCurveDirection( int nGseCtx, int nShow, BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // imposto stato pGseCtx->m_pScene->SetShowCurveDirection( nShow != 0) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtZoom( int nGseCtx, int nZoom, BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; 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 nGseCtx, int nWinX, int nWinY, double dCoeff, BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; 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 EgtSetWinRect( int nGseCtx, int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; 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( int nGseCtx, BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; 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 nGseCtx, int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; 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 nGseCtx, int nView, BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; 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( int nGseCtx, double dAngVertDeg, double dAngHorizDeg, BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; 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( int nGseCtx, double ptP[3], BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; VERIFY_CTX_SCENE( pGseCtx, FALSE) // imposto vista pGseCtx->m_pScene->SetCenter( Point3d( ptP[0], ptP[1], ptP[2])) ; if ( bRedraw) pGseCtx->m_pScene->RedrawWindow() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtPanCamera( int nGseCtx, int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; 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 nGseCtx, int nPrevX, int nPrevY, int nCurrX, int nCurrY, BOOL bRedraw) { GseContext* pGseCtx = GetGseContext( nGseCtx) ; 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 nGseCtx, int* pnDir) { IEGrScene* pScene = GetScene( nGseCtx) ; VERIFY_SCENE( pScene, FALSE) // recupero direzione di vista if ( pnDir == nullptr) return FALSE ; *pnDir = pScene->GetCameraDir() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtUnProjectPoint( int nGseCtx, int nWinX, int nWinY, double ptP[3]) { IEGrScene* pScene = GetScene( nGseCtx) ; 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 0 ; ptP[0] = ptWorld.x ; ptP[1] = ptWorld.y ; ptP[2] = ptWorld.z ; return TRUE ; }