TestEGr :

- spostata classe Scene nella libreria EgtGraphics.
This commit is contained in:
Dario Sassi
2014-02-13 18:19:13 +00:00
parent 3e3febb611
commit 3231a86583
15 changed files with 191 additions and 1403 deletions
+62 -40
View File
@@ -18,6 +18,7 @@
#include "/EgtDev/Include/EgtILogger.h"
#include "/EgtDev/Include/EgnStringUtils.h"
#include "/EgtDev/Include/EgnStringConverter.h"
#include "/EgtDev/Include/EGrScene.h"
//----------------------------------------------------------------------------
#ifdef _DEBUG
@@ -37,12 +38,17 @@ END_MESSAGE_MAP()
TestEgrView::TestEgrView( void)
{
m_pDC = nullptr ;
m_pScene = nullptr ;
m_nStatus = ST_NULL ;
m_PrevPoint.SetPoint( 0, 0) ;
}
//----------------------------------------------------------------------------
TestEgrView::~TestEgrView( void)
{
if ( m_pScene != nullptr)
delete m_pScene ;
m_pScene = nullptr ;
if ( m_pDC != nullptr)
delete m_pDC ;
m_pDC = nullptr ;
@@ -66,9 +72,10 @@ TestEgrView::Create( CWnd* pParent, int nID)
if ( CreateEx( 0, className, L"TestEgrView",
WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rectWin, pParent, nID) != 0) {
SetWindowPos( &wndTop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE) ;
m_pDC = new CClientDC( this) ;
SetCursor( AfxGetApp()->LoadCursor( IDC_POINTER)) ;
return true ;
m_pDC = new CClientDC( this) ;
m_pScene = CreateEGrScene() ;
return ( m_pDC != nullptr && m_pScene != nullptr) ;
}
else
return false ;
@@ -76,24 +83,24 @@ TestEgrView::Create( CWnd* pParent, int nID)
//----------------------------------------------------------------------------
bool
TestEgrView::StartScene( int nDriver, bool b2Buff, int nColorBits, int nDepthBits, ILogger* pLogger)
TestEgrView::StartScene( int nDriver, bool b2Buff, int nColorBits, int nDepthBits,
IGeomDB* pGeomDB, ILogger* pLogger)
{
// creazione della scena
m_Scene.Init( pLogger) ;
if ( ! m_Scene.CreateContext( GetSafeHdc(), nDriver, b2Buff, nColorBits, nDepthBits))
if ( m_pScene == nullptr)
return false ;
// impostazione dati geometrie
m_Scene.SetData( 3) ;
// creazione della scena
m_pScene->Init( pGeomDB, pLogger) ;
if ( ! m_pScene->CreateContext( GetSafeHdc(), nDriver, b2Buff, nColorBits, nDepthBits))
return false ;
// impostazione dati di vista
m_Scene.SetCenter( Point3d( 0, 0, 0)) ;
m_Scene.SetCamera( EGrScene::CT_ISO_SW) ;
m_Scene.ZoomAll() ;
m_pScene->SetCamera( CT_ISO_SW) ;
m_pScene->ZoomAll() ;
LOG_INFO( pLogger, m_Scene.GetOpenGLInfo().c_str())
LOG_INFO( pLogger, m_Scene.GetGLSLInfo().c_str())
LOG_INFO( pLogger, m_Scene.GetPixelFormatInfo().c_str())
LOG_INFO( pLogger, m_pScene->GetOpenGLInfo().c_str())
LOG_INFO( pLogger, m_pScene->GetGLSLInfo().c_str())
LOG_INFO( pLogger, m_pScene->GetPixelFormatInfo().c_str())
return true ;
}
@@ -102,8 +109,8 @@ TestEgrView::StartScene( int nDriver, bool b2Buff, int nColorBits, int nDepthBit
void
TestEgrView::Destroy( void)
{
m_Scene.ResetData() ;
m_Scene.Destroy() ;
if ( m_pScene != nullptr)
m_pScene->Destroy() ;
DestroyWindow() ;
}
@@ -112,11 +119,11 @@ bool
TestEgrView::Reshape( int nX, int nY, int nW, int nH)
{
// se non è ancora stata creata, esco subito
if ( m_pDC == nullptr)
if ( m_pDC == nullptr || m_pScene == nullptr)
return true ;
MoveWindow( nX, nY, nW, nH, FALSE) ;
m_Scene.Reshape( nW, nH) ;
m_pScene->Reshape( nW, nH) ;
return true ;
}
@@ -124,8 +131,11 @@ TestEgrView::Reshape( int nX, int nY, int nW, int nH)
void
TestEgrView::OnPaint( void)
{
if ( m_pScene == nullptr)
return ;
// ridisegno finestra OpenGL
m_Scene.Draw() ;
m_pScene->Draw() ;
ValidateRgn( NULL) ;
}
@@ -133,18 +143,21 @@ TestEgrView::OnPaint( void)
void
TestEgrView::Zoom( UINT nID)
{
if ( m_pScene == nullptr)
return ;
const double COEFF_PLUS = 0.9 ;
const double COEFF_MINUS = 1 / COEFF_PLUS ;
switch ( nID) {
case IDC_ZOOM_ALL :
m_Scene.ZoomAll() ;
m_pScene->ZoomAll() ;
break ;
case IDC_ZOOM_P :
m_Scene.ZoomChange( COEFF_PLUS) ;
m_pScene->ZoomChange( COEFF_PLUS) ;
break ;
case IDC_ZOOM_M :
m_Scene.ZoomChange( COEFF_MINUS) ;
m_pScene->ZoomChange( COEFF_MINUS) ;
break ;
default :
return ;
@@ -158,24 +171,27 @@ TestEgrView::Zoom( UINT nID)
void
TestEgrView::View( UINT nID)
{
if ( m_pScene == nullptr)
return ;
switch ( nID) {
case IDC_VIEW_TOP :
m_Scene.SetCamera( EGrScene::CT_TOP) ;
m_pScene->SetCamera( CT_TOP) ;
break ;
case IDC_VIEW_FRONT :
m_Scene.SetCamera( EGrScene::CT_FRONT) ;
m_pScene->SetCamera( CT_FRONT) ;
break ;
case IDC_VIEW_BACK :
m_Scene.SetCamera( EGrScene::CT_BACK) ;
m_pScene->SetCamera( CT_BACK) ;
break ;
case IDC_VIEW_LEFT :
m_Scene.SetCamera( EGrScene::CT_LEFT) ;
m_pScene->SetCamera( CT_LEFT) ;
break ;
case IDC_VIEW_RIGHT :
m_Scene.SetCamera( EGrScene::CT_RIGHT) ;
m_pScene->SetCamera( CT_RIGHT) ;
break ;
case IDC_VIEW_ISO :
m_Scene.SetCamera( EGrScene::CT_ISO_SW) ;
m_pScene->SetCamera( CT_ISO_SW) ;
break ;
default :
return ;
@@ -221,7 +237,8 @@ TestEgrView::OnMouseMove( UINT nFlags, CPoint point)
if ( m_nStatus == ST_ROT && nFlags & MK_MBUTTON) {
SetCursor( AfxGetApp()->LoadCursor( IDC_ROTATE)) ;
// eseguo la rotazione
m_Scene.RotateCamera( Point3d( m_PrevPoint.x, m_PrevPoint.y), Point3d( point.x, point.y)) ;
if ( m_pScene != nullptr)
m_pScene->RotateCamera( Point3d( m_PrevPoint.x, m_PrevPoint.y), Point3d( point.x, point.y)) ;
// aggiorno il disegno
RedrawWindow() ;
// salvo il punto di riferimento
@@ -231,7 +248,8 @@ TestEgrView::OnMouseMove( UINT nFlags, CPoint point)
else if ( m_nStatus == ST_PAN && nFlags & MK_MBUTTON) {
SetCursor( AfxGetApp()->LoadCursor( IDC_PAN)) ;
// eseguo il pan
m_Scene.PanCamera( Point3d( m_PrevPoint.x, m_PrevPoint.y), Point3d( point.x, point.y)) ;
if ( m_pScene != nullptr)
m_pScene->PanCamera( Point3d( m_PrevPoint.x, m_PrevPoint.y), Point3d( point.x, point.y)) ;
// aggiorno il disegno
RedrawWindow() ;
// salvo il punto di riferimento
@@ -257,7 +275,8 @@ TestEgrView::OnMouseWheel( UINT nFlags, short zDelta, CPoint point)
ScreenToClient( &point) ;
// eseguo lo zoom sul punto
m_Scene.ZoomOnPoint( Point3d( point.x, point.y), dCoeff) ;
if ( m_pScene != nullptr)
m_pScene->ZoomOnPoint( Point3d( point.x, point.y), dCoeff) ;
// aggiorno il disegno
RedrawWindow() ;
@@ -269,24 +288,27 @@ TestEgrView::OnMouseWheel( UINT nFlags, short zDelta, CPoint point)
void
TestEgrView::ShowCursorCoordinates( const Point3d& ptWin)
{
if ( m_pScene == nullptr)
return ;
// trasformo il punto da coordinate view a coordinate mondo
Point3d ptView( ptWin.x, ptWin.y, m_Scene.GetProjectedCenter().z) ;
Point3d ptView( ptWin.x, ptWin.y, m_pScene->GetProjectedCenter().z) ;
Point3d ptWorld ;
if ( ! m_Scene.UnProject( ptView, ptWorld))
if ( ! m_pScene->UnProject( ptView, ptWorld))
return ;
// visualizzo le coordinate
std::string sCoord ;
switch ( m_Scene.GetCameraDir()) {
case EGrScene::CT_TOP :
case EGrScene::CT_BOTTOM :
switch ( m_pScene->GetCameraDir()) {
case CT_TOP :
case CT_BOTTOM :
sCoord = "X=" + ToString( ptWorld.x, 3) + " Y=" + ToString( ptWorld.y, 3) ;
break ;
case EGrScene::CT_FRONT :
case EGrScene::CT_BACK :
case CT_FRONT :
case CT_BACK :
sCoord = "X=" + ToString( ptWorld.x, 3) + " Z=" + ToString( ptWorld.z, 3) ;
break ;
case EGrScene::CT_LEFT :
case EGrScene::CT_RIGHT :
case CT_LEFT :
case CT_RIGHT :
sCoord = "Y=" + ToString( ptWorld.y, 3) + " Z=" + ToString( ptWorld.z, 3) ;
break ;
default :