EgtGraphics 1.5j1 :
- aggiunta gestione selezione con mouse - aggiunta gestione selezione punti notevoli (snap points).
This commit is contained in:
+238
@@ -0,0 +1,238 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2014-2014
|
||||
//----------------------------------------------------------------------------
|
||||
// File : SceneDirect.cpp Data : 09.10.14 Versione : 1.5j1
|
||||
// Contenuto : Implementazione disegno diretto nella scena.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 25.02.14 DS Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "ObjOldGraphics.h"
|
||||
#include "ObjNewGraphics.h"
|
||||
#include "Scene.h"
|
||||
#include "GraphObjs.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 ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::SetGeoLineAttribs( Color GLcol)
|
||||
{
|
||||
m_colorGL = GLcol ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::SetGeoLine( const Point3d& ptP1, const Point3d& ptP2)
|
||||
{
|
||||
m_bGeoLine = true ;
|
||||
m_ptGeoLineP1 = ptP1 ;
|
||||
m_ptGeoLineP2 = ptP2 ;
|
||||
|
||||
return ( ! AreSamePointApprox( m_ptGeoLineP1, m_ptGeoLineP2)) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::ResetGeoLine( void)
|
||||
{
|
||||
bool bOld = m_bGeoLine ;
|
||||
m_bGeoLine = false ;
|
||||
|
||||
return bOld ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
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 ( ! AreSamePointApprox( m_ptWinRectP1, m_ptWinRectP2)) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::ResetWinRect( void)
|
||||
{
|
||||
bool bOld = m_bWinRect ;
|
||||
m_bWinRect = false ;
|
||||
|
||||
return bOld ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::DrawDirect( void)
|
||||
{
|
||||
// eseguo disegni diretti
|
||||
bool bOk = true ;
|
||||
if ( m_bGeoLine) {
|
||||
if ( ! DrawGeoLine())
|
||||
bOk = false ;
|
||||
}
|
||||
if ( m_bWinRect) {
|
||||
if ( ! DrawWinRect())
|
||||
bOk = false ;
|
||||
}
|
||||
|
||||
return bOk ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::DrawGeoLine( void)
|
||||
{
|
||||
// disegno linea in geometria globale
|
||||
glBegin( GL_LINES) ;
|
||||
glColor3f( m_colorGL.GetRed(), m_colorGL.GetGreen(), m_colorGL.GetBlue()) ;
|
||||
glVertex3f( float( m_ptGeoLineP1.x), float( m_ptGeoLineP1.y), float( m_ptGeoLineP1.z)) ;
|
||||
glVertex3f( float( m_ptGeoLineP2.x), float( m_ptGeoLineP2.y), float( m_ptGeoLineP2.z)) ;
|
||||
glEnd() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::DrawWinRect( void)
|
||||
{
|
||||
// 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 ;
|
||||
}
|
||||
Reference in New Issue
Block a user