diff --git a/EGrUtils.h b/EGrUtils.h
index 37b0891..bf2d30d 100644
--- a/EGrUtils.h
+++ b/EGrUtils.h
@@ -51,8 +51,8 @@ FrameToOpenGlMatrix( const Frame3d& frFrame, double Matrix[OGLMAT_DIM])
inline bool
OpenGlMatrixToFrame( const double Matrix[OGLMAT_DIM], Frame3d& frFrame)
{
+ // imposto solo Origine, VersZ e VersNearX per non avere errori di ortogonalità
return frFrame.Set( Point3d( Matrix[12], Matrix[13], Matrix[14]),
- Vector3d( Matrix[0], Matrix[1], Matrix[2]),
- Vector3d( Matrix[4], Matrix[5], Matrix[6]),
- Vector3d( Matrix[8], Matrix[9], Matrix[10])) ;
+ Vector3d( Matrix[8], Matrix[9], Matrix[10]),
+ Vector3d( Matrix[0], Matrix[1], Matrix[2])) ;
}
diff --git a/EgtGraphics.rc b/EgtGraphics.rc
index 13186c9..466f662 100644
Binary files a/EgtGraphics.rc and b/EgtGraphics.rc differ
diff --git a/EgtGraphics.vcxproj b/EgtGraphics.vcxproj
index 8129c45..c45c096 100644
--- a/EgtGraphics.vcxproj
+++ b/EgtGraphics.vcxproj
@@ -221,6 +221,7 @@ copy $(TargetPath) \EgtProg\Dll64
+
diff --git a/EgtGraphics.vcxproj.filters b/EgtGraphics.vcxproj.filters
index 980a10f..7ebd736 100644
--- a/EgtGraphics.vcxproj.filters
+++ b/EgtGraphics.vcxproj.filters
@@ -72,6 +72,9 @@
File di intestazione
+
+ File di intestazione
+
diff --git a/ObjEGrGraphics.h b/ObjEGrGraphics.h
index a0caa0a..7309cc3 100644
--- a/ObjEGrGraphics.h
+++ b/ObjEGrGraphics.h
@@ -43,7 +43,7 @@ class ObjEGrGraphics : public IObjGraphics
virtual bool AddTriangle( const Triangle3d& Tria, const TriFlags3d& TFlags, const TriNormals3d& TNrms) = 0 ;
virtual bool EndTriangles( void) = 0 ;
virtual bool Draw( int nStat, int nMark, bool bSurfSha, int nAlpha, bool ShowAux) = 0 ;
- virtual bool GetLocalBBox( BBox3d& b3Loc) = 0 ;
+ virtual bool GetLocalBBox( BBox3d& b3Loc) const = 0 ;
} ;
//----------------------------------------------------------------------------
diff --git a/ObjNewGraphics.h b/ObjNewGraphics.h
index b589451..10e0bc5 100644
--- a/ObjNewGraphics.h
+++ b/ObjNewGraphics.h
@@ -77,7 +77,7 @@ class ObjNewGraphics : public ObjEGrGraphics
virtual bool AddTriangle( const Triangle3d& Tria, const TriFlags3d& TFlags, const TriNormals3d& TNrms) ;
virtual bool EndTriangles( void) ;
virtual bool Draw( int nStat, int nMark, bool bSurfSha, int nAlpha, bool bShowAux) ;
- virtual bool GetLocalBBox( BBox3d& b3Loc)
+ virtual bool GetLocalBBox( BBox3d& b3Loc) const
{ b3Loc = m_b3Loc ; return ! m_b3Loc.IsEmpty() ; }
public :
diff --git a/ObjOldGraphics.h b/ObjOldGraphics.h
index b54721d..9f8101e 100644
--- a/ObjOldGraphics.h
+++ b/ObjOldGraphics.h
@@ -81,7 +81,7 @@ class ObjOldGraphics : public ObjEGrGraphics
virtual bool AddTriangle( const Triangle3d& Tria, const TriFlags3d& TFlags, const TriNormals3d& TNrms) ;
virtual bool EndTriangles( void) ;
virtual bool Draw( int nStat, int nMark, bool bSurfSha, int nAlpha, bool bShowAux) ;
- virtual bool GetLocalBBox( BBox3d& b3Loc)
+ virtual bool GetLocalBBox( BBox3d& b3Loc) const
{ b3Loc = m_b3Loc ; return ! m_b3Loc.IsEmpty() ; }
public :
diff --git a/Scene.h b/Scene.h
index 3a748e8..8b525ec 100644
--- a/Scene.h
+++ b/Scene.h
@@ -46,6 +46,7 @@ struct SelRec { // record di selezione per OpenGL (buffer di GLuint)
//----------------------------------------------------------------------------
struct AlphaSurf {
+ Frame3d frModView ;
ObjEGrGraphics* pGraph ;
int nStat ;
int nMark ;
@@ -53,8 +54,8 @@ struct AlphaSurf {
bool bShowAux ;
double dZmin ;
double dZmax ;
- AlphaSurf( ObjEGrGraphics* pG, int nS, int nM, int nA, bool bSA, double dZm, double dZM)
- : pGraph( pG), nStat( nS), nMark( nM), nAlpha( nA), bShowAux( bSA), dZmin( dZm), dZmax( dZM) {}
+ AlphaSurf( const Frame3d& frMV, ObjEGrGraphics* pG, int nS, int nM, int nA, bool bSA, double dZm, double dZM)
+ : frModView( frMV), pGraph( pG), nStat( nS), nMark( nM), nAlpha( nA), bShowAux( bSA), dZmin( dZm), dZmax( dZM) {}
} ;
typedef std::vector ASURFVECTOR ;
@@ -87,7 +88,7 @@ class Scene : public IEGrScene
virtual int GetNextSelectedObj( void) ;
virtual double GetSelectedObjWinZ( int nSel = - 1) ;
virtual double GetSelectedObjMinWinZ( int nSel = - 1) ;
- virtual bool GetPointFromSelect( int nSelId, const Point3d& ptView, Point3d& ptSel) ;
+ virtual bool GetPointFromSelect( int nSelId, const Point3d& ptView, Point3d& ptSel, int& nAux) ;
virtual bool Project( const Point3d& ptWorld, Point3d& ptView) ;
virtual bool UnProject( const Point3d& ptView, Point3d& ptWorld) ;
virtual void Destroy( void) ;
diff --git a/SceneBasic.cpp b/SceneBasic.cpp
index b8e4406..27b52ce 100644
--- a/SceneBasic.cpp
+++ b/SceneBasic.cpp
@@ -692,6 +692,8 @@ Scene::Draw( void)
case SM_HIDDENLINE :
// disabilito illuminazione
glDisable( GL_LIGHTING) ;
+ // disegno griglia senza illuminazione (già impostato)
+ DrawGrid() ;
// disegno le geometrie del DB
// prima passata per superfici solo per aggiornare Zbuffer (poligoni riempiti e offsettati)
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL) ;
@@ -701,8 +703,6 @@ Scene::Draw( void)
DrawGroup( GDB_ID_ROOT, 1, MdStMkCol( GDB_MD_STD, GDB_ST_ON, GDB_MK_OFF, m_colDef)) ;
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) ;
glDisable( GL_POLYGON_OFFSET_FILL) ;
- // disegno griglia senza illuminazione (già impostato)
- DrawGrid() ;
// seconda passata per tutto in forma 0dim e curve
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE) ;
DrawGroup( GDB_ID_ROOT, 2, MdStMkCol( GDB_MD_STD, GDB_ST_ON, GDB_MK_OFF, m_colDef)) ;
diff --git a/SceneGeom.cpp b/SceneGeom.cpp
index 89ffc70..0c1a0b5 100644
--- a/SceneGeom.cpp
+++ b/SceneGeom.cpp
@@ -355,8 +355,8 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
pGraphics->GetLocalBBox( b3Box) ;
b3Box.ToGlob( frModView) ;
// inserisco i dati nel vettore
- m_vAlphaSurf.emplace_back( pGraphics, siObj.nStat, siObj.nMark, nAlpha, bShowAux,
- b3Box.GetMin().z, b3Box.GetMax().z) ;
+ m_vAlphaSurf.emplace_back( frModView, pGraphics, siObj.nStat, siObj.nMark,
+ nAlpha, bShowAux, b3Box.GetMin().z, b3Box.GetMax().z) ;
return true ;
}
}
@@ -384,8 +384,18 @@ Scene::DrawAlphaSurfVector( void)
// eseguo visualizzazione
for ( int i = 0 ; i < int( m_vAlphaSurf.size()) ; ++i) {
- if ( ! m_vAlphaSurf[i].pGraph->Draw( m_vAlphaSurf[i].nStat, m_vAlphaSurf[i].nMark, true,
- m_vAlphaSurf[i].nAlpha, m_vAlphaSurf[i].bShowAux))
+ // imposto matrice MODELVIEW
+ double Matrix[OGLMAT_DIM] ;
+ FrameToOpenGlMatrix( m_vAlphaSurf[i].frModView, Matrix) ;
+ glPushMatrix() ;
+ glLoadMatrixd( Matrix) ;
+ // eseguo visualizzazione
+ bool bOk = m_vAlphaSurf[i].pGraph->Draw( m_vAlphaSurf[i].nStat, m_vAlphaSurf[i].nMark, true,
+ m_vAlphaSurf[i].nAlpha, m_vAlphaSurf[i].bShowAux) ;
+ // ripristino matrice
+ glPopMatrix() ;
+ // in caso di errore, esco
+ if ( ! bOk)
return false ;
}
return true ;
diff --git a/SceneSelect.cpp b/SceneSelect.cpp
index a65e21a..c5d4565 100644
--- a/SceneSelect.cpp
+++ b/SceneSelect.cpp
@@ -15,13 +15,16 @@
#include "stdafx.h"
#include "Scene.h"
#include "GraphObjs.h"
+#include "ObjEGrGraphics.h"
#include "DllMain.h"
#include "/EgtDev/Include/EgkGeoPoint3d.h"
#include "/EgtDev/Include/EgkGeoVector3d.h"
#include "/EgtDev/Include/EGkFrame3d.h"
#include "/EgtDev/Include/EGkCurve.h"
#include "/EgtDev/Include/EGkDistPointCurve.h"
+#include "/EgtDev/Include/EGkSurfTriMesh.h"
#include "/EgtDev/Include/EGkExtText.h"
+#include "/EgtDev/Include/EGkIntersLineSurfTm.h"
#include "/EgtDev/Include/EGkGdbConst.h"
#include "/EgtDev/Include/EGkGeomDB.h"
#include
@@ -209,12 +212,16 @@ Scene::UnselectableFind( int nId)
/*------------------------------------------------------------------------------------------*/
bool
-Scene::GetPointFromSelect( int nSelId, const Point3d& ptView, Point3d& ptSel)
+Scene::GetPointFromSelect( int nSelId, const Point3d& ptView, Point3d& ptSel, int& nAux)
{
// recupera il punto di mira proiettato sull'oggetto appena selezionato
// (va eseguito subito dopo la Select da cui si è derivato l'Id)
// è simile a GetSelectedSnapPoint
+ // verifico parametri di ritorno
+ if ( &ptSel == nullptr || &nAux == nullptr)
+ return false ;
+
// rendo corrente l'entità selezionata
bool bFound = false ;
for ( int nId = GetFirstSelectedObj() ; nId != GDB_ID_NULL ; nId = GetNextSelectedObj()) {
@@ -236,6 +243,8 @@ Scene::GetPointFromSelect( int nSelId, const Point3d& ptView, Point3d& ptSel)
if ( ! m_pGeomDB->GetGlobFrame( nSelId, frEnt))
return false ;
+ // inizializzo indice ausiliario (Id del sotto-oggetto : curva semplice o triangolo)
+ nAux = 0 ;
// se punto
if ( pGObj->GetType() == GEO_PNT3D) {
// recupero il geo-punto
@@ -278,8 +287,10 @@ Scene::GetPointFromSelect( int nSelId, const Point3d& ptView, Point3d& ptSel)
if ( dstPtCurve.GetMinDistInfo( 0, mdInfo)) {
Point3d ptP = mdInfo.ptQ ;
ptP.ToGlob( frEnt) ;
- if ( VerifySnapPoint( ptP, ptView, dMinSqDist))
+ if ( VerifySnapPoint( ptP, ptView, dMinSqDist)) {
ptSel = ptP ;
+ nAux = int( mdInfo.dPar) ;
+ }
}
// eventuale verifica dell'estruso
double dTh ;
@@ -298,11 +309,47 @@ Scene::GetPointFromSelect( int nSelId, const Point3d& ptView, Point3d& ptSel)
Point3d ptP = mdInfo.ptQ ;
ptP.ToGlob( frEnt) ;
ptP += vtExtr ;
- if ( VerifySnapPoint( ptP, ptView, dMinSqDist))
+ if ( VerifySnapPoint( ptP, ptView, dMinSqDist)) {
ptSel = ptP ;
+ nAux = int( mdInfo.dPar) ;
+ }
}
}
}
+ // se superficie trimesh
+ else if ( pGObj->GetType() == SRF_TRIMESH) {
+ // recupero la superficie
+ const ISurfTriMesh* pStm = GetSurfTriMesh( pGObj) ;
+ // il punto di riferimento deriva da XY su viewport e Z da selezione
+ Point3d ptWinZ( ptView.x, ptView.y, GetSelectedObjWinZ()) ;
+ // lo porto da spazio grafico a spazio geometrico globale
+ Point3d ptRef ;
+ UnProject( ptWinZ, ptRef) ;
+ // lo porto nel frame della curva
+ ptRef.ToLoc( frEnt) ;
+ // recupero la direzione di mira e la porto nel riferimento della superficie
+ Vector3d vtDir = - m_vtDirCamera ;
+ vtDir.ToLoc( frEnt) ;
+ // recupero il raggio del box di ingombro
+ double dBlRad = 1000 ;
+ const ObjEGrGraphics* pGraphics = GetObjEGrGraphics( pStm) ;
+ if ( pGraphics != nullptr) {
+ BBox3d b3Loc ;
+ if ( pGraphics->GetLocalBBox( b3Loc))
+ b3Loc.GetRadius( dBlRad) ;
+ }
+ // punto davanti all'oggetto lungo il raggio di mira
+ Point3d ptMir = ptRef - vtDir * 2 * dBlRad ;
+ double dLenMir = 4 * dBlRad ;
+ // cerco i triangoli intersecati dalla linea di mira
+ ILSIVECTOR vInfo ;
+ if ( ! IntersLineSurfTm( ptMir, vtDir, dLenMir, *pStm, vInfo) || vInfo.size() == 0)
+ return false ;
+ // recupero il primo punto
+ ptSel = vInfo[0].ptI ;
+ ptSel.ToGlob( frEnt) ;
+ nAux = vInfo[0].nT ;
+ }
// se testo
else if ( pGObj->GetType() == EXT_TEXT) {
// recupero il testo
diff --git a/SceneSnap.cpp b/SceneSnap.cpp
index b4d543a..8e90280 100644
--- a/SceneSnap.cpp
+++ b/SceneSnap.cpp
@@ -14,17 +14,19 @@
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "Scene.h"
+#include "ObjEGrGraphics.h"
#include "/EgtDev/Include/EGkGeomDB.h"
#include "/EgtDev/Include/EgkGeoPoint3d.h"
#include "/EgtDev/Include/EgkGeoVector3d.h"
#include "/EgtDev/Include/EGkFrame3d.h"
#include "/EgtDev/Include/EGkCurve.h"
+#include "/EgtDev/Include/EGkCurveArc.h"
#include "/EgtDev/Include/EGkCurveComposite.h"
#include "/EgtDev/Include/EGkDistPointCurve.h"
#include "/EgtDev/Include/EGkSurfTriMesh.h"
#include "/EgtDev/Include/EGkExtText.h"
#include "/EgtDev/Include/EgkIntersCurveCurve.h"
-#include "/EgtDev/Include/EgkIntersLineTria.h"
+#include "/EgtDev/Include/EGkIntersLineSurfTm.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
@@ -359,7 +361,13 @@ Scene::FindCurveSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame
bFound = true ;
m_nLastSnapId = nId ;
m_ptLastSnapPnt = ptP ;
- m_bLastSnapDirOk = false ;
+ if ( pCrv->GetType() == CRV_ARC) {
+ m_bLastSnapDirOk = true ;
+ m_vtLastSnapDir = GetCurveArc( pCrv)->GetNormVersor() ;
+ m_vtLastSnapDir.ToGlob( frEnt) ;
+ }
+ else
+ m_bLastSnapDirOk = false ;
}
}
break ;
@@ -414,11 +422,18 @@ Scene::FindCurveSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame
bool
Scene::VerifySnapPoint( const Point3d& ptP, const Point3d& ptWin, double& dMinSqDist)
{
- // proietto il punto sulla viewport
- Point3d ptWinP ;
- Project( ptP, ptWinP) ;
- // confronto le distanze
- double dSqDist = SqDistXY( ptWin, ptWinP) ;
+ // il punto di riferimento deriva da XY su viewport e Z minima (più vicina a osservatore) da selezione
+ Point3d ptWinZ( ptWin.x, ptWin.y, GetSelectedObjMinWinZ()) ;
+ // punto di riferimento nello spazio geometrico 3d
+ Point3d ptRef ;
+ if ( ! UnProject( ptWinZ, ptRef))
+ return false ;
+ // recupero la direzione di mira
+ Vector3d vtDir = - m_vtDirCamera ;
+ // il punto di confronto è quello sulla linea di mira a minima distanza dal punto dato
+ Point3d ptCfr = ptRef + (( ptP - ptRef) * vtDir) * vtDir ;
+ // determino la distanza e la confronto con il minimo
+ double dSqDist = SqDist( ptP, ptCfr) ;
if ( dSqDist < dMinSqDist) {
dMinSqDist = dSqDist ;
return true ;
@@ -538,64 +553,172 @@ Scene::FindSurfTMSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
// recupero la direzione di mira e la porto nel riferimento della superficie
Vector3d vtDir = - m_vtDirCamera ;
vtDir.ToLoc( frEnt) ;
- // salvo stato precedente di snap
- bool bPrevFound = ( m_nLastSnapId != GDB_ID_NULL) ;
- // cerco il vertice a minor distanza dalla linea
- bool bFound = false ;
- int nVert ;
- Point3d ptMin ;
- Point3d ptP ;
- int nIv = pStm->GetFirstVertex( ptP) ;
- while ( nIv != SVT_NULL) {
- // in generale (shading e hiddenline) il punto di confronto è quello di riferimento
- Point3d ptCfr = ptRef ;
- // se wireframe, il punto di confronto è quello della linea di mira a minima distanza dal vertice
- if ( m_nShowMode == SM_WIREFRAME)
- ptCfr = ptRef + (( ptP - ptRef) * vtDir) * vtDir ;
- // determino la distanza e la confronto con il minimo
- double dSqDist = SqDist( ptP, ptCfr) ;
- if ( dSqDist < dMinSqDist) {
- bFound = true ;
- nVert = nIv ;
- ptMin = ptCfr ;
- dMinSqDist = dSqDist ;
- ptP.ToGlob( frEnt) ;
- m_nLastSnapId = nId ;
- m_ptLastSnapPnt = ptP ;
- m_bLastSnapDirOk = false ;
- }
- // passo al successivo
- nIv = pStm->GetNextVertex( nIv, ptP) ;
+ // recupero il raggio del box di ingombro
+ double dBlRad = 1000 ;
+ const ObjEGrGraphics* pGraphics = GetObjEGrGraphics( pStm) ;
+ if ( pGraphics != nullptr) {
+ BBox3d b3Loc ;
+ if ( pGraphics->GetLocalBBox( b3Loc))
+ b3Loc.GetRadius( dBlRad) ;
}
- // se è la prima selezione e non è modalità wireframe, la favorisco perchè davanti
- if ( bFound && ! bPrevFound && m_nShowMode != SM_WIREFRAME)
- dMinSqDist = 0 ;
- // se trovato punto, cerco la faccia
- if ( bFound) {
- // cerco i triangoli intorno al vertice
- INTVECTOR vTria ;
- bool bCirc ;
- int nTtot = pStm->GetAllTriaAroundVertex( nVert, vTria, bCirc) ;
- // tra quelli che intersecano la linea di mira prendo il più vicino al punto Minimo
- double dMinSqDistFace = INFINITO * INFINITO ;
- for ( int i = 0 ; i < int( vTria.size()) ; ++ i) {
- Triangle3d Tria ;
- if ( ! pStm->GetTriangle( vTria[i], Tria))
- continue ;
- Point3d ptInt ;
- int nRes = IntersLineTria( ptRef - vtDir * 1000, vtDir, 2000, Tria, ptInt) ;
- if ( nRes == ILTT_IN || nRes == ILTT_EDGE || nRes == ILTT_VERT) {
- double dSqDist = SqDist( ptInt, ptMin) ;
- if ( dSqDist < dMinSqDistFace) {
- dMinSqDistFace = dSqDist ;
- m_bLastSnapDirOk = true ;
- pStm->GetVertexSmoothNormal( nVert, vTria[i], m_vtLastSnapDir) ;
- m_vtLastSnapDir.ToGlob( frEnt) ;
+ // punto davanti all'oggetto lungo il raggio di mira
+ Point3d ptMir = ptRef - vtDir * 2 * dBlRad ;
+ double dLenMir = 4 * dBlRad ;
+
+ // se richiesto il centro di gravità (baricentro, centroide)
+ if ( nSnap == SP_CENTROID) {
+ Point3d ptP ;
+ bool bFound = false ;
+ if ( pStm->GetCentroid( ptP)) {
+ // il punto di confronto è quello sulla linea di mira a minima distanza dal vertice
+ Point3d ptCfr = ptRef + (( ptP - ptRef) * vtDir) * vtDir ;
+ // determino la distanza e la confronto con il minimo
+ double dSqDist = SqDist( ptP, ptCfr) ;
+ if ( dSqDist < dMinSqDist) {
+ bFound = true ;
+ dMinSqDist = dSqDist ;
+ m_nLastSnapId = nId ;
+ m_ptLastSnapPnt = ptP ;
+ m_ptLastSnapPnt.ToGlob( frEnt) ;
+ m_bLastSnapDirOk = false ;
+ }
+ }
+ return bFound ;
+ }
+
+ // cerco i triangoli intersecati dalla linea di mira
+ ILSIVECTOR vInfo ;
+ if ( ! IntersLineSurfTm( ptMir, vtDir, dLenMir, *pStm, vInfo))
+ return false ;
+
+ // elaborazione a seconda del tipo di snap
+ bool bFound = false ;
+ switch ( nSnap) {
+ case SP_END :
+ {
+ // con wireframe devo provare tutti i triangoli intersecati, con shading e hiddenline solo il primo
+ int nTtot = (( m_nShowMode == SM_WIREFRAME) ? int( vInfo.size()) : 1) ;
+ for ( int i = 0 ; i < nTtot ; ++ i) {
+ // punto di intersezione
+ Point3d ptInt = vInfo[i].ptI ;
+ // punto finale più vicino
+ int nF = pStm->GetFacetFromTria( vInfo[i].nT) ;
+ Point3d ptEnd ;
+ Vector3d vtN ;
+ if ( pStm->GetFacetNearestEndPoint( nF, ptInt, ptEnd, vtN)) {
+ // il punto di confronto è quello sulla linea di mira a minima distanza dal vertice
+ Point3d ptCfr = ptRef + (( ptEnd - ptRef) * vtDir) * vtDir ;
+ // determino la distanza e la confronto con il minimo
+ double dSqDist = SqDist( ptEnd, ptCfr) ;
+ if ( dSqDist < dMinSqDist) {
+ bFound = true ;
+ dMinSqDist = dSqDist ;
+ m_nLastSnapId = nId ;
+ m_ptLastSnapPnt = ptEnd ;
+ m_ptLastSnapPnt.ToGlob( frEnt) ;
+ m_bLastSnapDirOk = true ;
+ m_vtLastSnapDir = vtN ;
+ m_vtLastSnapDir.ToGlob( frEnt) ;
+ }
}
}
}
+ break ;
+ case SP_MID :
+ {
+ // con wireframe devo provare tutti i triangoli intersecati, con shading e hiddenline solo il primo
+ int nTtot = (( m_nShowMode == SM_WIREFRAME) ? int( vInfo.size()) : 1) ;
+ for ( int i = 0 ; i < nTtot ; ++ i) {
+ // punto di intersezione
+ Point3d ptInt = vInfo[i].ptI ;
+ // punto medio più vicino
+ int nF = pStm->GetFacetFromTria( vInfo[i].nT) ;
+ Point3d ptMid ;
+ Vector3d vtN ;
+ if ( pStm->GetFacetNearestMidPoint( nF, ptInt, ptMid, vtN)) {
+ // il punto di confronto è quello sulla linea di mira a minima distanza dal punto medio
+ Point3d ptCfr = ptRef + (( ptMid - ptRef) * vtDir) * vtDir ;
+ // determino la distanza e la confronto con il minimo
+ double dSqDist = SqDist( ptMid, ptCfr) ;
+ if ( dSqDist < dMinSqDist) {
+ bFound = true ;
+ dMinSqDist = dSqDist ;
+ m_nLastSnapId = nId ;
+ m_ptLastSnapPnt = ptMid ;
+ m_ptLastSnapPnt.ToGlob( frEnt) ;
+ m_bLastSnapDirOk = true ;
+ m_vtLastSnapDir = vtN ;
+ m_vtLastSnapDir.ToGlob( frEnt) ;
+ }
+ }
+ }
+ }
+ break ;
+ case SP_CENTER :
+ {
+ // con wireframe devo provare tutti i triangoli intersecati, con shading e hiddenline solo il primo
+ int nTtot = (( m_nShowMode == SM_WIREFRAME) ? int( vInfo.size()) : 1) ;
+ for ( int i = 0 ; i < nTtot ; ++ i) {
+ // centro più vicino
+ int nF = pStm->GetFacetFromTria( vInfo[i].nT) ;
+ Point3d ptCen ;
+ Vector3d vtN ;
+ if ( pStm->GetFacetCenter( nF, ptCen, vtN)) {
+ // il punto di confronto è quello sulla linea di mira a minima distanza dal centro
+ Point3d ptCfr = ptRef + (( ptCen - ptRef) * vtDir) * vtDir ;
+ // determino la distanza e la confronto con il minimo
+ double dSqDist = SqDist( ptCen, ptCfr) ;
+ if ( dSqDist < dMinSqDist) {
+ bFound = true ;
+ dMinSqDist = dSqDist ;
+ m_nLastSnapId = nId ;
+ m_ptLastSnapPnt = ptCen ;
+ m_ptLastSnapPnt.ToGlob( frEnt) ;
+ m_bLastSnapDirOk = true ;
+ m_vtLastSnapDir = vtN ;
+ m_vtLastSnapDir.ToGlob( frEnt) ;
+ }
+ }
+ }
+ }
+ break ;
+ case SP_NEAR :
+ case SP_TANG :
+ case SP_PERP :
+ case SP_MINDIST :
+ // considero solo il primo triangolo intersecato
+ // la distanza è nulla e la confronto con il minimo
+ if ( 0 < dMinSqDist) {
+ bFound = true ;
+ dMinSqDist = 0 ;
+ m_nLastSnapId = nId ;
+ // punto
+ Point3d ptInt = vInfo[0].ptI ;
+ m_ptLastSnapPnt = ptInt ;
+ m_ptLastSnapPnt.ToGlob( frEnt) ;
+ // direzione
+ Triangle3d Tria ;
+ TriNormals3d Tnorms ;
+ Vector3d vtNorm ;
+ if ( pStm->GetTriangle( vInfo[0].nT, Tria) &&
+ pStm->GetTriangleSmoothNormals( vInfo[0].nT, Tnorms) &&
+ CalcNormal( ptInt, Tria, Tnorms, vtNorm)) {
+ m_bLastSnapDirOk = true ;
+ m_vtLastSnapDir = vtNorm ;
+ m_vtLastSnapDir.ToGlob( frEnt) ;
+ }
+ else
+ m_bLastSnapDirOk = false ;
+ }
+ break ;
+ default :
+ break ;
}
- // risultato dello snap su questo oggetto
+
+ // se trovato e modalità shading o hiddenline, la favorisco perchè davanti alle possibili successive
+ if ( bFound && m_nShowMode != SM_WIREFRAME)
+ dMinSqDist = 0 ;
+
return bFound ;
}
@@ -617,7 +740,7 @@ Scene::FindTextSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame3
m_nLastSnapId = nId ;
m_ptLastSnapPnt = ptP ;
m_bLastSnapDirOk = true ;
- m_vtLastSnapDir = pTxt->GetDirVersor() ;
+ m_vtLastSnapDir = pTxt->GetNormVersor() ;
m_vtLastSnapDir.ToGlob( frEnt) ;
}
}
@@ -629,7 +752,7 @@ Scene::FindTextSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame3
m_nLastSnapId = nId ;
m_ptLastSnapPnt = ptP ;
m_bLastSnapDirOk = true ;
- m_vtLastSnapDir = pTxt->GetDirVersor() ;
+ m_vtLastSnapDir = pTxt->GetNormVersor() ;
m_vtLastSnapDir.ToGlob( frEnt) ;
}
}
@@ -641,7 +764,7 @@ Scene::FindTextSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame3
m_nLastSnapId = nId ;
m_ptLastSnapPnt = ptP ;
m_bLastSnapDirOk = true ;
- m_vtLastSnapDir = pTxt->GetDirVersor() ;
+ m_vtLastSnapDir = pTxt->GetNormVersor() ;
m_vtLastSnapDir.ToGlob( frEnt) ;
}
}
@@ -653,7 +776,7 @@ Scene::FindTextSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame3
m_nLastSnapId = nId ;
m_ptLastSnapPnt = ptP ;
m_bLastSnapDirOk = true ;
- m_vtLastSnapDir = pTxt->GetDirVersor() ;
+ m_vtLastSnapDir = pTxt->GetNormVersor() ;
m_vtLastSnapDir.ToGlob( frEnt) ;
}
}
@@ -667,7 +790,7 @@ Scene::FindTextSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame3
m_nLastSnapId = nId ;
m_ptLastSnapPnt = ptP ;
m_bLastSnapDirOk = true ;
- m_vtLastSnapDir = pTxt->GetDirVersor() ;
+ m_vtLastSnapDir = pTxt->GetNormVersor() ;
m_vtLastSnapDir.ToGlob( frEnt) ;
}
}
@@ -680,7 +803,9 @@ Scene::FindTextSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame3
bFound = true ;
m_nLastSnapId = nId ;
m_ptLastSnapPnt = ptP ;
- m_bLastSnapDirOk = false ;
+ m_bLastSnapDirOk = true ;
+ m_vtLastSnapDir = pTxt->GetNormVersor() ;
+ m_vtLastSnapDir.ToGlob( frEnt) ;
}
}
break ;