EgtGraphics 1.5b5 :
- aggiunto ZoomWin - aggiunto DrawRectWin.
This commit is contained in:
Binary file not shown.
@@ -225,6 +225,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
|
||||
<ClCompile Include="SceneBasic.cpp" />
|
||||
<ClCompile Include="SceneCamera.cpp" />
|
||||
<ClCompile Include="SceneGeom.cpp" />
|
||||
<ClCompile Include="SceneAux.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
|
||||
@@ -92,6 +92,9 @@
|
||||
<ClCompile Include="SceExecutor.cpp">
|
||||
<Filter>File di origine</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SceneAux.cpp">
|
||||
<Filter>File di origine</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="EgtGraphics.rc">
|
||||
|
||||
@@ -33,7 +33,6 @@ class Scene : public IEGrScene
|
||||
virtual std::string GetGLSLInfo( void) ;
|
||||
virtual std::string GetPixelFormatInfo( void) ;
|
||||
virtual bool RedrawWindow( void) ;
|
||||
virtual bool SetExtension( const BBox3d& b3Ext) ;
|
||||
virtual bool Reshape( int nW, int nH) ;
|
||||
virtual bool SetBackground( Color BackTop, Color BackBottom) ;
|
||||
virtual bool Prepare( void) ;
|
||||
@@ -55,8 +54,14 @@ class Scene : public IEGrScene
|
||||
virtual bool ZoomAll( void) ;
|
||||
virtual bool ZoomChange( double dCoeff) ;
|
||||
virtual bool ZoomOnPoint( const Point3d& ptWin, double dCoeff) ;
|
||||
virtual bool ZoomWin( const Point3d& ptWin1, const Point3d& ptWin2) ;
|
||||
// Geometry
|
||||
virtual bool SetExtension( const BBox3d& b3Ext) ;
|
||||
virtual bool UpdateExtension( void) ;
|
||||
// Aux
|
||||
virtual bool SetWinRectAttribs( bool bOutline, Color WRcol) ;
|
||||
virtual bool SetWinRect( const Point3d& ptWinRectP1, const Point3d& ptWinRectP2) ;
|
||||
virtual bool ResetWinRect( void) ;
|
||||
|
||||
public :
|
||||
// Basic
|
||||
@@ -78,13 +83,16 @@ class Scene : public IEGrScene
|
||||
// Camera
|
||||
bool VerifyCamera( void) ;
|
||||
bool CalcDirUp( void) ;
|
||||
bool CalcCameraFrame( Frame3d& frView) ;
|
||||
// Geometry
|
||||
bool DrawGroup( int nId) ;
|
||||
bool DrawGeoObj( IGeoObj* pGeoObj) ;
|
||||
bool DeleteObjGraphicsGroup( int nId) ;
|
||||
// Aux
|
||||
bool DrawWinRect( void) ;
|
||||
|
||||
private :
|
||||
IGeomDB* m_pGeomDB ;
|
||||
IGeomDB* m_pGeomDB ; // puntatore al DB geometrico
|
||||
|
||||
HDC m_hDC ; // Device Context
|
||||
HGLRC m_hRC ; // OpenGL Rendering Context
|
||||
@@ -106,8 +114,14 @@ class Scene : public IEGrScene
|
||||
BBox3d m_b3ExtWorld ; // estensione della geometria nel riferimento globale (mondo)
|
||||
BBox3d m_b3ExtView ; // estensione nel riferimento di vista
|
||||
bool m_bExtViewOk ; // flag per stato aggiornamento di EView
|
||||
double m_dHalfWidth ;
|
||||
double m_dHalfHeight ;
|
||||
double m_dZNear ;
|
||||
double m_dZFar ;
|
||||
double m_dHalfWidth ; // semialtezza della vista
|
||||
double m_dHalfHeight ; // semilarghezza della vista
|
||||
double m_dZNear ; // distanza del piano di clipping vicino
|
||||
double m_dZFar ; // distanza del piano di clipping lontano
|
||||
|
||||
bool m_bOutlineWR ; // flag per disegno WinRect con solo contorno o pieno
|
||||
Color m_colorWR ; // colore per WinRect
|
||||
bool m_bWinRect ; // flag esistenza rettangolo temporaneo in finestra
|
||||
Point3d m_ptWinRectP1 ; // primo estremo del rettangolo temporaneo
|
||||
Point3d m_ptWinRectP2 ; // secondo estremo del rettangolo temporaneo
|
||||
} ;
|
||||
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2014-2014
|
||||
//----------------------------------------------------------------------------
|
||||
// File : SceneAux.cpp Data : 25.02.14 Versione : 1.5b4
|
||||
// Contenuto : Implementazione della gestione ausiliari della classe scena.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 25.02.14 DS Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "Scene.h"
|
||||
#include "ObjOldGraphics.h"
|
||||
#include "ObjNewGraphics.h"
|
||||
#include "/EgtDev/Include/EgtILogger.h"
|
||||
#include "/EgtDev/Include/EGnStringUtils.h"
|
||||
#include "/EgtDev/Include/EGkFrame3d.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
#include "/EgtDev/Include/EGkGdbIterator.h"
|
||||
#include "/EgtDev/Include/EGkCurve.h"
|
||||
|
||||
using namespace std ;
|
||||
|
||||
//------------------------------ Constants -----------------------------------
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::SetWinRectAttribs( bool bOutline, Color WRcol)
|
||||
{
|
||||
m_bOutlineWR = bOutline ;
|
||||
m_colorWR = WRcol ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::SetWinRect( const Point3d& ptWinRectP1, const Point3d& ptWinRectP2)
|
||||
{
|
||||
m_bWinRect = true ;
|
||||
m_ptWinRectP1 = ptWinRectP1 ;
|
||||
m_ptWinRectP2 = ptWinRectP2 ;
|
||||
|
||||
return ( ! AreSamePointNear( m_ptWinRectP1, m_ptWinRectP2)) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::ResetWinRect( void)
|
||||
{
|
||||
bool bOld = m_bWinRect ;
|
||||
m_bWinRect = false ;
|
||||
|
||||
return bOld ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::DrawWinRect( void)
|
||||
{
|
||||
// verifico sia da disegnare
|
||||
if ( ! m_bWinRect)
|
||||
return true ;
|
||||
|
||||
// rendo neutre matrici di proiezione e di modello/vista
|
||||
glMatrixMode( GL_PROJECTION) ;
|
||||
glPushMatrix() ;
|
||||
glLoadIdentity() ;
|
||||
glMatrixMode( GL_MODELVIEW) ;
|
||||
glPushMatrix() ;
|
||||
glLoadIdentity() ;
|
||||
|
||||
// recupero le dimensioni della viewport
|
||||
GLint vPort[ 4] ;
|
||||
glGetIntegerv( GL_VIEWPORT, vPort) ;
|
||||
|
||||
// estremi del rettangolo nel riferimento Win ( 0,0 in alto a sinistra e Y verso il basso)
|
||||
double dWinXmin = __min( m_ptWinRectP1.x, m_ptWinRectP2.x) ;
|
||||
double dWinXmax = __max( m_ptWinRectP1.x, m_ptWinRectP2.x) ;
|
||||
double dWinYmin = __min( m_ptWinRectP1.y, m_ptWinRectP2.y) ;
|
||||
double dWinYmax = __max( m_ptWinRectP1.y, m_ptWinRectP2.y) ;
|
||||
// estremi del rettangolo nel riferimento View (0,0 in centro, quindi estremi -1,-1 e +1,+1 assi soliti)
|
||||
float dViewXmin = float( - 1 + 2 * ( 1 + dWinXmin) / ( vPort[2] + 1)) ;
|
||||
float dViewXmax = float( - 1 + 2 * ( 1 + dWinXmax) / ( vPort[2] + 1)) ;
|
||||
float dViewYmin = float( - 1 + 2 * ( vPort[3] - dWinYmax) / ( vPort[3] + 1)) ;
|
||||
float dViewYmax = float( - 1 + 2 * ( vPort[3] - dWinYmin) / ( vPort[3] + 1)) ;
|
||||
|
||||
// eseguo il disegno del rettangolo
|
||||
if ( ! m_bNewWay) {
|
||||
if ( m_bOutlineWR) {
|
||||
glBegin( GL_LINE_LOOP) ;
|
||||
glColor3f( m_colorWR.GetRed(), m_colorWR.GetGreen(), m_colorWR.GetBlue()) ;
|
||||
glVertex3f( dViewXmin, dViewYmin, 0.5) ;
|
||||
glVertex3f( dViewXmax, dViewYmin, 0.5) ;
|
||||
glVertex3f( dViewXmax, dViewYmax, 0.5) ;
|
||||
glVertex3f( dViewXmin, dViewYmax, 0.5) ;
|
||||
glEnd() ;
|
||||
}
|
||||
else {
|
||||
glEnable( GL_BLEND) ;
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
|
||||
glBegin( GL_TRIANGLE_STRIP) ;
|
||||
glColor4f( m_colorWR.GetRed(), m_colorWR.GetGreen(), m_colorWR.GetBlue(), m_colorWR.GetAlpha()) ;
|
||||
glVertex3f( dViewXmin, dViewYmin, 0.5) ;
|
||||
glVertex3f( dViewXmax, dViewYmin, 0.5) ;
|
||||
glVertex3f( dViewXmin, dViewYmax, 0.5) ;
|
||||
glVertex3f( dViewXmax, dViewYmax, 0.5) ;
|
||||
glEnd() ;
|
||||
glDisable( GL_BLEND) ;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
// predispongo VAO e VBO usa e getta
|
||||
unsigned int nVaoId ;
|
||||
unsigned int nVboId ;
|
||||
// definizione
|
||||
glGenVertexArrays( 1, &nVaoId) ;
|
||||
if ( nVaoId == 0)
|
||||
return false ;
|
||||
glBindVertexArray( nVaoId) ;
|
||||
glGenBuffers( 1, &nVboId) ;
|
||||
glBindBuffer( GL_ARRAY_BUFFER, nVboId) ;
|
||||
glBufferData( GL_ARRAY_BUFFER, 4 * SIZEV3F, NULL, GL_STATIC_DRAW) ;
|
||||
glVertexPointer( 3, GL_FLOAT, SIZEV3F, ((void*)(0))) ;
|
||||
glEnableClientState( GL_VERTEX_ARRAY) ;
|
||||
// se contorno
|
||||
if ( m_bOutlineWR) {
|
||||
// assegno i vertici (ordine S)
|
||||
Vert3f v3V ;
|
||||
v3V.Set( dViewXmin, dViewYmin, 0.5) ;
|
||||
glBufferSubData( GL_ARRAY_BUFFER, 0 * SIZEV3F, SIZEV3F, &v3V) ;
|
||||
v3V.Set( dViewXmax, dViewYmin, 0.5) ;
|
||||
glBufferSubData( GL_ARRAY_BUFFER, 1 * SIZEV3F, SIZEV3F, &v3V) ;
|
||||
v3V.Set( dViewXmax, dViewYmax, 0.5) ;
|
||||
glBufferSubData( GL_ARRAY_BUFFER, 2 * SIZEV3F, SIZEV3F, &v3V) ;
|
||||
v3V.Set( dViewXmin, dViewYmax, 0.5) ;
|
||||
glBufferSubData( GL_ARRAY_BUFFER, 3 * SIZEV3F, SIZEV3F, &v3V) ;
|
||||
// imposto colore
|
||||
glColor3f( m_colorWR.GetRed(), m_colorWR.GetGreen(), m_colorWR.GetBlue()) ;
|
||||
// disegno
|
||||
glDrawArrays( GL_LINE_LOOP, 0, 4) ;
|
||||
}
|
||||
// altrimenti area
|
||||
else {
|
||||
// assegno i vertici (ordine S)
|
||||
Vert3f v3V ;
|
||||
v3V.Set( dViewXmin, dViewYmin, 0.5) ;
|
||||
glBufferSubData( GL_ARRAY_BUFFER, 0 * SIZEV3F, SIZEV3F, &v3V) ;
|
||||
v3V.Set( dViewXmax, dViewYmin, 0.5) ;
|
||||
glBufferSubData( GL_ARRAY_BUFFER, 1 * SIZEV3F, SIZEV3F, &v3V) ;
|
||||
v3V.Set( dViewXmin, dViewYmax, 0.5) ;
|
||||
glBufferSubData( GL_ARRAY_BUFFER, 2 * SIZEV3F, SIZEV3F, &v3V) ;
|
||||
v3V.Set( dViewXmax, dViewYmax, 0.5) ;
|
||||
glBufferSubData( GL_ARRAY_BUFFER, 3 * SIZEV3F, SIZEV3F, &v3V) ;
|
||||
// imposto blending e colore
|
||||
glEnable( GL_BLEND) ;
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
|
||||
glColor4f( m_colorWR.GetRed(), m_colorWR.GetGreen(), m_colorWR.GetBlue(), m_colorWR.GetAlpha()) ;
|
||||
// disegno
|
||||
glDrawArrays( GL_TRIANGLE_STRIP, 0, 4) ;
|
||||
// disabilito blending
|
||||
glDisable( GL_BLEND) ;
|
||||
}
|
||||
// cancello VAO e VBO
|
||||
glBindBuffer( GL_ARRAY_BUFFER, 0) ;
|
||||
glDeleteBuffers( 1, &nVboId) ;
|
||||
glBindVertexArray( 0) ;
|
||||
glDeleteVertexArrays( 1, &nVaoId) ;
|
||||
}
|
||||
|
||||
// ripristino le matrici di proiezione e di modello/vista originali
|
||||
glMatrixMode( GL_PROJECTION) ;
|
||||
glPopMatrix() ;
|
||||
glMatrixMode( GL_MODELVIEW) ;
|
||||
glPopMatrix() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
+9
-5
@@ -54,6 +54,10 @@ Scene::Scene( void)
|
||||
// View data
|
||||
m_ptCenter = ORIG ;
|
||||
SetCamera( 0, 0, 0) ;
|
||||
// WinRect
|
||||
m_bOutlineWR = true ;
|
||||
m_colorWR.Set( 0, 0, 0) ;
|
||||
m_bWinRect = false ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -346,10 +350,7 @@ Scene::CalcExtView( void)
|
||||
return false ;
|
||||
// calcolo il riferimento di vista
|
||||
Frame3d frView ;
|
||||
Vector3d vtZ = m_vtDirCamera ;
|
||||
Vector3d vtY = m_vtUp ;
|
||||
Vector3d vtX = vtY ^ vtZ ;
|
||||
if ( ! frView.Set( m_ptCenter + m_dDistCamera * vtZ, vtX, vtY, vtZ))
|
||||
if ( ! CalcCameraFrame( frView))
|
||||
return false ;
|
||||
// calcolo l'estensione nel riferimento di vista
|
||||
m_b3ExtView = m_b3ExtWorld ;
|
||||
@@ -609,9 +610,12 @@ Scene::Draw( void)
|
||||
// colore di default
|
||||
glColor4f( 1, 1, 1, 1) ;
|
||||
|
||||
// disegno
|
||||
// disegno le geometrie del DB
|
||||
DrawGroup( GDB_ID_ROOT) ;
|
||||
|
||||
// aggiungo disegni diretti
|
||||
DrawWinRect() ;
|
||||
|
||||
// aggiorno
|
||||
glFlush() ;
|
||||
|
||||
|
||||
@@ -191,6 +191,23 @@ Scene::CalcDirUp( void)
|
||||
return m_bUpOk ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::CalcCameraFrame( Frame3d& frView)
|
||||
{
|
||||
// verifico direzione camera Up
|
||||
if ( ! CalcDirUp())
|
||||
return false ;
|
||||
// eseguo il calcolo
|
||||
Vector3d vtZ = m_vtDirCamera ;
|
||||
Vector3d vtY = m_vtUp ;
|
||||
Vector3d vtX = vtY ^ vtZ ;
|
||||
if ( ! frView.Set( m_ptCenter + m_dDistCamera * vtZ, vtX, vtY, vtZ))
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::PanCamera( const Point3d& ptWinOld, const Point3d& ptWinNew)
|
||||
@@ -294,3 +311,38 @@ Scene::ZoomOnPoint( const Point3d& ptWin, double dCoeff)
|
||||
// eseguo lo zoom
|
||||
return ZoomChange( dCoeff) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::ZoomWin( const Point3d& ptWin1, const Point3d& ptWin2)
|
||||
{
|
||||
// porto i punti in coordinate mondo
|
||||
Point3d ptWorld1 ;
|
||||
if ( ! UnProject( Point3d( ptWin1.x, ptWin1.y, GetProjectedCenter().z), ptWorld1))
|
||||
return false ;
|
||||
Point3d ptWorld2 ;
|
||||
if ( ! UnProject( Point3d( ptWin2.x, ptWin2.y, GetProjectedCenter().z), ptWorld2))
|
||||
return false ;
|
||||
|
||||
// recupero il riferimento della camera (vista)
|
||||
Frame3d frView ;
|
||||
if ( ! CalcCameraFrame( frView))
|
||||
return false ;
|
||||
|
||||
// porto i punti in coordinate camera (vista)
|
||||
Point3d ptView1 = ptWorld1 ;
|
||||
ptView1.ToLoc( frView) ;
|
||||
Point3d ptView2 = ptWorld2 ;
|
||||
ptView2.ToLoc( frView) ;
|
||||
|
||||
// imposto il nuovo centro di vista
|
||||
Point3d ptNewCen = 0.5 * ( ptWorld1 + ptWorld2) ;
|
||||
SetCenter( ptNewCen) ;
|
||||
|
||||
// imposto il nuovo zoom
|
||||
double dHalfWidth = 0.5 * fabs( ptView1.x - ptView2.x) ;
|
||||
double dHalfHeight = 0.5 * fabs( ptView1.y - ptView2.y) ;
|
||||
|
||||
// adatto le dimensioni a quelle della vista
|
||||
return AdjustDimView( dHalfWidth, dHalfHeight) ;
|
||||
}
|
||||
Reference in New Issue
Block a user