Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ac78227f0b | |||
| 8eff351f17 | |||
| 0405079553 | |||
| 50b446c371 | |||
| a68b502938 |
Binary file not shown.
+7
-8
@@ -22,14 +22,14 @@
|
||||
<ProjectGuid>{4EC970B1-B4D9-4088-8A31-B462CF72116E}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>EgtGraphics</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.20348.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
@@ -42,7 +42,7 @@
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
@@ -108,7 +108,7 @@
|
||||
<CompileAs>CompileAsCpp</CompileAs>
|
||||
<DisableSpecificWarnings>
|
||||
</DisableSpecificWarnings>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@@ -135,7 +135,7 @@ copy $(TargetPath) \EgtProg\DllD32</Command>
|
||||
<OpenMPSupport>true</OpenMPSupport>
|
||||
<DisableSpecificWarnings>
|
||||
</DisableSpecificWarnings>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>-Wno-tautological-undefined-compare</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@@ -171,7 +171,7 @@ copy $(TargetPath) \EgtProg\DllD64</Command>
|
||||
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
|
||||
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@@ -209,7 +209,7 @@ copy $(TargetPath) \EgtProg\Dll32</Command>
|
||||
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
|
||||
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
|
||||
<CompileAs>CompileAsCpp</CompileAs>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>-Wno-tautological-undefined-compare</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@@ -263,7 +263,6 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
|
||||
<ClCompile Include="SceneCamera.cpp" />
|
||||
<ClCompile Include="SceneGeom.cpp" />
|
||||
<ClCompile Include="SceneDirect.cpp" />
|
||||
<ClCompile Include="SceneGlobCube.cpp" />
|
||||
<ClCompile Include="SceneGlobFrame.cpp" />
|
||||
<ClCompile Include="SceneGrid.cpp" />
|
||||
<ClCompile Include="SceneImage.cpp" />
|
||||
|
||||
@@ -140,9 +140,6 @@
|
||||
<ClCompile Include="ImageMgr.cpp">
|
||||
<Filter>File di origine</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SceneGlobCube.cpp">
|
||||
<Filter>File di origine</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="EgtGraphics.rc">
|
||||
|
||||
+6
-5
@@ -1,7 +1,7 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2014-2023
|
||||
// EgalTech 2014-2024
|
||||
//----------------------------------------------------------------------------
|
||||
// File : ObjEGrGraphics.h Data : 08.07.23 Versione : 2.5g1
|
||||
// File : ObjEGrGraphics.h Data : 09.03.24 Versione : 2.6c2
|
||||
// Contenuto : Dichiarazione della classe grafica di un oggetto geometrico.
|
||||
//
|
||||
//
|
||||
@@ -31,8 +31,9 @@ class ObjEGrGraphics : public IObjGraphics
|
||||
virtual bool IsValid( void) = 0 ;
|
||||
virtual void SetScene( Scene* pScene) = 0 ;
|
||||
virtual Scene* GetScene( void) = 0 ;
|
||||
virtual bool SetCurrent( int nCurr) { return false ; }
|
||||
virtual bool SetCurrent( int nCurr) = 0 ;
|
||||
virtual void Clear( void) = 0 ;
|
||||
virtual bool Validate( void) = 0 ;
|
||||
virtual bool AddColor( const Color& colC) = 0 ;
|
||||
virtual bool AddMaterial( const Color& colAmb, const Color& colDiff,
|
||||
const Color& colSpec, float fShin) = 0 ;
|
||||
@@ -40,8 +41,8 @@ class ObjEGrGraphics : public IObjGraphics
|
||||
virtual bool AddLineStipple( int nFactor, int nPattern) = 0 ;
|
||||
virtual bool AddPoint( const Point3d& ptP, bool bAux = false) = 0 ;
|
||||
virtual bool AddPoints( const PNTVECTOR& vPnt, bool bAux = false) = 0 ;
|
||||
virtual bool AddLines( const PNTVECTOR& vPnt, bool bAux = false) = 0 ;
|
||||
virtual bool AddPolyLine( const PolyLine& PL, bool bAux = false) = 0 ;
|
||||
virtual bool AddLines( const PNTVECTOR& vPnt, bool bAux = false, bool bSurfSha = false) = 0 ;
|
||||
virtual bool AddPolyLine( const PolyLine& PL, bool bAux = false, bool bSurfSha = false) = 0 ;
|
||||
virtual bool StartTriangles( int nNum, bool bAux = false) = 0 ;
|
||||
virtual bool AddTriangle( const Triangle3d& Tria, const TriFlags3d& TFlags, const TriNormals3d& TNrms) = 0 ;
|
||||
virtual bool EndTriangles( void) = 0 ;
|
||||
|
||||
+19
-8
@@ -13,7 +13,6 @@
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "/EgtDev/Include/EGkColor.h"
|
||||
#include "ObjMultiGraphics.h"
|
||||
#include "ObjNewGraphics.h"
|
||||
#include "ObjOldGraphics.h"
|
||||
@@ -34,7 +33,7 @@ void
|
||||
ObjMultiGraphics::Reset( void)
|
||||
{
|
||||
m_bValid = false ;
|
||||
m_nCurr = - 1 ;
|
||||
m_nCurr = -1 ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -52,8 +51,8 @@ void
|
||||
ObjMultiGraphics::SetScene( Scene* pScene)
|
||||
{
|
||||
m_pScene = pScene ;
|
||||
for ( size_t i = 0 ; i < m_vOEGR.size() ; ++ i)
|
||||
m_vOEGR[i]->SetScene( pScene) ;
|
||||
for ( auto& pOEGR : m_vOEGR)
|
||||
pOEGR->SetScene( pScene) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -78,6 +77,18 @@ ObjMultiGraphics::Clear( void)
|
||||
m_vOEGR[m_nCurr]->Clear() ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjMultiGraphics::Validate( void)
|
||||
{
|
||||
if ( ! m_bValid) {
|
||||
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
||||
return false ;
|
||||
m_bValid = m_vOEGR[m_nCurr]->Validate() ;
|
||||
}
|
||||
return m_bValid ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjMultiGraphics::AddColor( const Color& colC)
|
||||
@@ -137,22 +148,22 @@ ObjMultiGraphics::AddPoints( const PNTVECTOR& vPnt, bool bAux)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjMultiGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux)
|
||||
ObjMultiGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux, bool bSurfSha)
|
||||
{
|
||||
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
||||
return false ;
|
||||
m_bValid = true ;
|
||||
return m_vOEGR[m_nCurr]->AddLines( vPnt, bAux) ;
|
||||
return m_vOEGR[m_nCurr]->AddLines( vPnt, bAux, bSurfSha) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjMultiGraphics::AddPolyLine( const PolyLine& PL, bool bAux)
|
||||
ObjMultiGraphics::AddPolyLine( const PolyLine& PL, bool bAux, bool bSurfSha)
|
||||
{
|
||||
if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size()))
|
||||
return false ;
|
||||
m_bValid = true ;
|
||||
return m_vOEGR[m_nCurr]->AddPolyLine( PL, bAux) ;
|
||||
return m_vOEGR[m_nCurr]->AddPolyLine( PL, bAux, bSurfSha) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
+3
-2
@@ -32,6 +32,7 @@ class ObjMultiGraphics : public ObjEGrGraphics
|
||||
{ return m_pScene ; }
|
||||
bool SetCurrent( int nCurr) override ;
|
||||
void Clear( void) override ;
|
||||
bool Validate( void) override ;
|
||||
bool AddColor( const Color& colC) override ;
|
||||
bool AddMaterial( const Color& colAmb, const Color& colDiff,
|
||||
const Color& colSpec, float fShin) override ;
|
||||
@@ -39,8 +40,8 @@ class ObjMultiGraphics : public ObjEGrGraphics
|
||||
bool AddLineStipple( int nFactor, int nPattern) override ;
|
||||
bool AddPoint( const Point3d& ptP, bool bAux = false) override ;
|
||||
bool AddPoints( const PNTVECTOR& vPnt, bool bAux = false) override ;
|
||||
bool AddLines( const PNTVECTOR& vPnt, bool bAux = false) override ;
|
||||
bool AddPolyLine( const PolyLine& PL, bool bAux = false) override ;
|
||||
bool AddLines( const PNTVECTOR& vPnt, bool bAux = false, bool bSurfSha = false) override ;
|
||||
bool AddPolyLine( const PolyLine& PL, bool bAux = false, bool bSurfSha = false) override ;
|
||||
bool StartTriangles( int nNum, bool bAux = false) override ;
|
||||
bool AddTriangle( const Triangle3d& Tria, const TriFlags3d& TFlags, const TriNormals3d& TNrms) override ;
|
||||
bool EndTriangles( void) override ;
|
||||
|
||||
+25
-9
@@ -52,6 +52,15 @@ ObjNewGraphics::Clear( void)
|
||||
m_nCurrMode = GL_NONE ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjNewGraphics::Validate( void)
|
||||
{
|
||||
if ( ! m_bValid)
|
||||
m_bValid = m_ngaVect.empty() ;
|
||||
return m_bValid ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjNewGraphics::AddColor( const Color& colC)
|
||||
@@ -165,7 +174,7 @@ ObjNewGraphics::AddPoints( const PNTVECTOR& vPnt, bool bAux)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjNewGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux)
|
||||
ObjNewGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux, bool bSurfSha)
|
||||
{
|
||||
if ( m_pScene == nullptr || ! m_pScene->MakeCurrent())
|
||||
return false ;
|
||||
@@ -195,7 +204,7 @@ ObjNewGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux)
|
||||
glEnableClientState( GL_VERTEX_ARRAY) ;
|
||||
glBindVertexArray( 0) ;
|
||||
// aggiungo i dati in lista
|
||||
AddNgaVerts( GL_LINES, nCount, nVaoId, nVboId, bAux) ;
|
||||
AddNgaVerts( GL_LINES, nCount, nVaoId, nVboId, bAux, bSurfSha) ;
|
||||
// dichiaro valida la grafica
|
||||
m_bValid = true ;
|
||||
|
||||
@@ -204,7 +213,7 @@ ObjNewGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjNewGraphics::AddPolyLine( const PolyLine& PL, bool bAux)
|
||||
ObjNewGraphics::AddPolyLine( const PolyLine& PL, bool bAux, bool bSurfSha)
|
||||
{
|
||||
if ( m_pScene == nullptr || ! m_pScene->MakeCurrent())
|
||||
return false ;
|
||||
@@ -236,7 +245,7 @@ ObjNewGraphics::AddPolyLine( const PolyLine& PL, bool bAux)
|
||||
glEnableClientState( GL_VERTEX_ARRAY) ;
|
||||
glBindVertexArray( 0) ;
|
||||
// aggiungo i dati in lista
|
||||
AddNgaVerts( GL_LINE_STRIP, nCount, nVaoId, nVboId, bAux) ;
|
||||
AddNgaVerts( GL_LINE_STRIP, nCount, nVaoId, nVboId, bAux, bSurfSha) ;
|
||||
// dichiaro valida la grafica
|
||||
m_bValid = true ;
|
||||
|
||||
@@ -377,9 +386,9 @@ ObjNewGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
float fSelMarkCol[4] = { 1, 1, 1, 1} ;
|
||||
float fSelMarkBackCol[4] = { 0.75, 0.75, 0.75, 1} ;
|
||||
if ( bSurfSha) {
|
||||
if ( nMark == GDB_MK_ON) {
|
||||
if ( nMark == GDB_MK_ON || nMark == GDB_MK_ON_2) {
|
||||
bStdCol = false ;
|
||||
Color colMark = m_pScene->GetMark() ;
|
||||
Color colMark = m_pScene->GetMark( nMark) ;
|
||||
colMark.SetAlpha( nAlpha) ;
|
||||
colMark.GetFloat( fSelMarkCol) ;
|
||||
Color colMarkBack = GetSurfBackColor( colMark) ;
|
||||
@@ -424,6 +433,13 @@ ObjNewGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
glBindVertexArray( 0) ;
|
||||
}
|
||||
break ;
|
||||
case NgAtom::VERTS_S :
|
||||
if ( bSurfSha && Nga.m_nCount > 0 && Nga.m_nVaoId != 0) {
|
||||
glBindVertexArray( Nga.m_nVaoId) ;
|
||||
glDrawArrays( Nga.m_nMode, 0, Nga.m_nCount) ;
|
||||
glBindVertexArray( 0) ;
|
||||
}
|
||||
break ;
|
||||
case NgAtom::COLOR :
|
||||
glColor4fv( ( bStdCol ? AdjustColor( Nga.m_fCol, bDark) : fSelMarkCol)) ;
|
||||
break ;
|
||||
@@ -461,7 +477,7 @@ ObjNewGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
}
|
||||
|
||||
// se marcato e non superficie in shading, disegno halo
|
||||
if ( nMark == GDB_MK_ON && ! bSurfSha) {
|
||||
if ( ( nMark == GDB_MK_ON || nMark == GDB_MK_ON_2) && ! bSurfSha) {
|
||||
// cambio test di depth per non sovrascrivere il disegno appena fatto
|
||||
glDepthFunc( GL_LESS) ;
|
||||
|
||||
@@ -470,7 +486,7 @@ ObjNewGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
glLineWidth( (float) m_pScene->GetMarkLineWidth()) ;
|
||||
|
||||
// colore di marcatura
|
||||
Color colMark = m_pScene->GetMark() ;
|
||||
Color colMark = m_pScene->GetMark( nMark) ;
|
||||
glColor4f( colMark.GetRed(), colMark.GetGreen(), colMark.GetBlue(), colMark.GetAlpha()) ;
|
||||
|
||||
// ciclo di disegno
|
||||
@@ -514,7 +530,7 @@ ObjNewGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
}
|
||||
|
||||
// se necessario, ripristino la normale visualizzazione
|
||||
if ( nStat == GDB_ST_SEL || nMark == GDB_MK_ON) {
|
||||
if ( nStat == GDB_ST_SEL || nMark == GDB_MK_ON || nMark == GDB_MK_ON_2) {
|
||||
glPointSize( (float) m_pScene->GetPointSize()) ;
|
||||
glLineWidth( (float) m_pScene->GetLineWidth()) ;
|
||||
}
|
||||
|
||||
+11
-10
@@ -14,7 +14,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "ObjEGrGraphics.h"
|
||||
|
||||
#include "OpenGL.h"
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Definizione di NgAtom
|
||||
@@ -23,8 +23,8 @@ class NgAtom {
|
||||
NgAtom( void) : m_nType( NONE), m_nMode( 0), m_nCount( 0), m_nVaoId( 0), m_nVboId( 0) {}
|
||||
|
||||
public :
|
||||
enum GrType { NONE = 0, VERTS = 1, VERTS_A = 2, COLOR = 3,
|
||||
MAT_A = 4, MAT_D = 5, MAT_S = 6, MAT_SH = 7, MAT_B = 8, LINE_STIPPLE = 9} ;
|
||||
enum GrType { NONE = 0, VERTS = 1, VERTS_A = 2, VERTS_S = 3, COLOR = 4,
|
||||
MAT_A = 5, MAT_D = 6, MAT_S = 7, MAT_SH = 8, MAT_B = 9, LINE_STIPPLE = 10} ;
|
||||
|
||||
public :
|
||||
GrType m_nType ;
|
||||
@@ -69,7 +69,10 @@ class ObjNewGraphics : public ObjEGrGraphics
|
||||
{ m_pScene = pScene ; }
|
||||
Scene* GetScene( void) override
|
||||
{ return m_pScene ; }
|
||||
bool SetCurrent( int nCurr) override
|
||||
{ return ( nCurr == 0) ; }
|
||||
void Clear( void) override ;
|
||||
bool Validate( void) override ;
|
||||
bool AddColor( const Color& colC) override ;
|
||||
bool AddMaterial( const Color& colAmb, const Color& colDiff,
|
||||
const Color& colSpec, float fShin) override ;
|
||||
@@ -77,19 +80,17 @@ class ObjNewGraphics : public ObjEGrGraphics
|
||||
bool AddLineStipple( int nFactor, int nPattern) override ;
|
||||
bool AddPoint( const Point3d& ptP, bool bAux = false) override ;
|
||||
bool AddPoints( const PNTVECTOR& vPnt, bool bAux = false) override ;
|
||||
bool AddLines( const PNTVECTOR& vPnt, bool bAux = false) override ;
|
||||
bool AddPolyLine( const PolyLine& PL, bool bAux = false) override ;
|
||||
bool AddLines( const PNTVECTOR& vPnt, bool bAux = false, bool bSurfSha = false) override ;
|
||||
bool AddPolyLine( const PolyLine& PL, bool bAux = false, bool bSurfSha = false) override ;
|
||||
bool StartTriangles( int nNum, bool bAux = false) override ;
|
||||
bool AddTriangle( const Triangle3d& Tria, const TriFlags3d& TFlags, const TriNormals3d& TNrms) override ;
|
||||
bool EndTriangles( void) override ;
|
||||
bool Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlpha, bool bShowAux) override ;
|
||||
|
||||
|
||||
bool GetLocalBBox( BBox3d& b3Loc) const override
|
||||
{ b3Loc = m_b3Loc ; return ! m_b3Loc.IsEmpty() ; }
|
||||
|
||||
public :
|
||||
ObjNewGraphics( void) : m_pScene( nullptr), m_bValid( false) {}
|
||||
ObjNewGraphics( void) : m_pScene( nullptr), m_bValid( false), m_nCurrMode( GL_NONE) {}
|
||||
|
||||
private :
|
||||
bool DeleteVaoVbo( void) ;
|
||||
@@ -97,9 +98,9 @@ class ObjNewGraphics : public ObjEGrGraphics
|
||||
{ try { m_ngaVect.push_back( nga) ; }
|
||||
catch(...) { return false ; }
|
||||
return true ; }
|
||||
bool AddNgaVerts( int nMode, int nCount, unsigned int nVaoId, unsigned int nVboId, bool bAux = false)
|
||||
bool AddNgaVerts( int nMode, int nCount, unsigned int nVaoId, unsigned int nVboId, bool bAux = false, bool bSurfSha = false)
|
||||
{ NgAtom nga ;
|
||||
nga.m_nType = ( bAux ? NgAtom::VERTS_A : NgAtom::VERTS) ;
|
||||
nga.m_nType = ( bSurfSha ? NgAtom::VERTS_S : ( bAux ? NgAtom::VERTS_A : NgAtom::VERTS)) ;
|
||||
nga.m_nMode = nMode ; nga.m_nCount = nCount ;
|
||||
nga.m_nVaoId = nVaoId ; nga.m_nVboId = nVboId ;
|
||||
return AddNgAtom( nga) ; }
|
||||
|
||||
+42
-19
@@ -48,6 +48,15 @@ ObjOldGraphics::Clear( void)
|
||||
m_nCurrMode = GL_NONE ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjOldGraphics::Validate( void)
|
||||
{
|
||||
if ( ! m_bValid)
|
||||
m_bValid = m_ogaVect.empty() ;
|
||||
return m_bValid ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjOldGraphics::AddColor( const Color& colC)
|
||||
@@ -129,7 +138,7 @@ ObjOldGraphics::AddPoints( const PNTVECTOR& vPnt, bool bAux)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjOldGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux)
|
||||
ObjOldGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux, bool bSurfSha)
|
||||
{
|
||||
// modo corrente deve essere nullo
|
||||
if ( m_nCurrMode != GL_NONE)
|
||||
@@ -137,7 +146,7 @@ ObjOldGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux)
|
||||
// riservo memoria per vettore
|
||||
m_ogaVect.reserve( VECT_HEAP + vPnt.size()) ;
|
||||
// start
|
||||
AddOgaStart( GL_LINES, bAux) ;
|
||||
AddOgaStart( GL_LINES, bAux, bSurfSha) ;
|
||||
// inserisco i vertici + aggiorno bbox
|
||||
for ( int i = 0 ; i < int( vPnt.size()) ; ++ i) {
|
||||
AddOgaVert3f( vPnt[i]) ;
|
||||
@@ -153,7 +162,7 @@ ObjOldGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
ObjOldGraphics::AddPolyLine( const PolyLine& PL, bool bAux)
|
||||
ObjOldGraphics::AddPolyLine( const PolyLine& PL, bool bAux, bool bSurfSha)
|
||||
{
|
||||
// modo corrente deve essere nullo
|
||||
if ( m_nCurrMode != GL_NONE)
|
||||
@@ -161,7 +170,7 @@ ObjOldGraphics::AddPolyLine( const PolyLine& PL, bool bAux)
|
||||
// riservo memoria per vettore
|
||||
m_ogaVect.reserve( VECT_HEAP + PL.GetPointNbr()) ;
|
||||
// start
|
||||
AddOgaStart( GL_LINE_STRIP, bAux) ;
|
||||
AddOgaStart( GL_LINE_STRIP, bAux, bSurfSha) ;
|
||||
// inserisco i nuovi vertici + aggiorno bbox
|
||||
Point3d ptP ;
|
||||
for ( bool bFound = PL.GetFirstPoint( ptP) ; bFound ; bFound = PL.GetNextPoint( ptP)) {
|
||||
@@ -245,6 +254,9 @@ AdjustColor( const float fCol[4], bool bDark)
|
||||
bool
|
||||
ObjOldGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlpha, bool bShowAux)
|
||||
{
|
||||
if ( ! m_bValid || m_pScene == nullptr || ! m_pScene->MakeCurrent())
|
||||
return false ;
|
||||
|
||||
// se vuoto non faccio alcunché
|
||||
if ( m_ogaVect.size() == 0)
|
||||
return true ;
|
||||
@@ -262,9 +274,9 @@ ObjOldGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
float fSelMarkCol[4] = { 1, 1, 1, 1} ;
|
||||
float fSelMarkBackCol[4] = { 0.75, 0.75, 0.75, 1} ;
|
||||
if ( bSurfSha) {
|
||||
if ( nMark == GDB_MK_ON) {
|
||||
if ( nMark == GDB_MK_ON || nMark == GDB_MK_ON_2) {
|
||||
bStdCol = false ;
|
||||
Color colMark = ( ( GetScene() != nullptr) ? GetScene()->GetMark() : Color( 255, 255, 0)) ;
|
||||
Color colMark = m_pScene->GetMark( nMark) ;
|
||||
colMark.SetAlpha( nAlpha) ;
|
||||
colMark.GetFloat( fSelMarkCol) ;
|
||||
Color colMarkBack = GetSurfBackColor( colMark) ;
|
||||
@@ -273,7 +285,7 @@ ObjOldGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
}
|
||||
else if ( nStat == GDB_ST_SEL) {
|
||||
bStdCol = false ;
|
||||
Color colSelSurf = ( ( GetScene() != nullptr) ? GetScene()->GetSelSurf() : Color( 255, 255, 192)) ;
|
||||
Color colSelSurf = m_pScene->GetSelSurf() ;
|
||||
colSelSurf.SetAlpha( nAlpha) ;
|
||||
colSelSurf.GetFloat( fSelMarkCol) ;
|
||||
Color colSelSurfBack = GetSurfBackColor( colSelSurf) ;
|
||||
@@ -292,34 +304,45 @@ ObjOldGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
}
|
||||
|
||||
// ciclo di disegno
|
||||
bool bStartA = false ;
|
||||
bool bSkip = false ;
|
||||
bool bLineStipple = false ;
|
||||
for ( const auto& Oga : m_ogaVect) {
|
||||
switch ( Oga.m_nType) {
|
||||
case OgAtom::START :
|
||||
glBegin( Oga.m_nMode) ;
|
||||
bStartA = false ;
|
||||
bSkip = false ;
|
||||
break ;
|
||||
case OgAtom::START_A :
|
||||
if ( bShowAux)
|
||||
if ( bShowAux) {
|
||||
glBegin( Oga.m_nMode) ;
|
||||
bStartA = true ;
|
||||
bSkip = false ;
|
||||
}
|
||||
else
|
||||
bSkip = true ;
|
||||
break ;
|
||||
case OgAtom::START_S :
|
||||
if ( bSurfSha) {
|
||||
glBegin( Oga.m_nMode) ;
|
||||
bSkip = false ;
|
||||
}
|
||||
else
|
||||
bSkip = true ;
|
||||
break ;
|
||||
case OgAtom::END :
|
||||
if ( ! bStartA || bShowAux)
|
||||
if ( ! bSkip)
|
||||
glEnd() ;
|
||||
bStartA = false ;
|
||||
bSkip = false ;
|
||||
break ;
|
||||
case OgAtom::VERT :
|
||||
if ( ! bStartA || bShowAux)
|
||||
if ( ! bSkip)
|
||||
glVertex3fv( Oga.m_fVal) ;
|
||||
break ;
|
||||
case OgAtom::BND_FLAG :
|
||||
if ( ! bStartA || bShowAux)
|
||||
if ( ! bSkip )
|
||||
glEdgeFlag( Oga.m_nFlag) ;
|
||||
break ;
|
||||
case OgAtom::NORMAL :
|
||||
if ( ! bStartA || bShowAux)
|
||||
if ( ! bSkip)
|
||||
glNormal3fv( Oga.m_fVal) ;
|
||||
break ;
|
||||
case OgAtom::COLOR :
|
||||
@@ -359,7 +382,7 @@ ObjOldGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
}
|
||||
|
||||
// se marcato e non superficie in shading, disegno halo
|
||||
if ( nMark == GDB_MK_ON && ! bSurfSha) {
|
||||
if ( ( nMark == GDB_MK_ON || nMark == GDB_MK_ON_2) && ! bSurfSha) {
|
||||
// cambio test di depth per non sovrascrivere il disegno appena fatto
|
||||
glDepthFunc( GL_LESS) ;
|
||||
|
||||
@@ -368,7 +391,7 @@ ObjOldGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
glLineWidth( (float) m_pScene->GetMarkLineWidth()) ;
|
||||
|
||||
// colore di marcatura
|
||||
Color colMark = ( ( GetScene() != nullptr) ? GetScene()->GetMark() : Color( 192, 192, 0)) ;
|
||||
Color colMark = m_pScene->GetMark( nMark) ;
|
||||
glColor4f( colMark.GetRed(), colMark.GetGreen(), colMark.GetBlue(), colMark.GetAlpha()) ;
|
||||
|
||||
// ciclo di disegno
|
||||
@@ -422,7 +445,7 @@ ObjOldGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
|
||||
}
|
||||
|
||||
// se necessario, ripristino la normale visualizzazione
|
||||
if ( nStat == GDB_ST_SEL || nMark == GDB_MK_ON) {
|
||||
if ( nStat == GDB_ST_SEL || nMark == GDB_MK_ON || nMark == GDB_MK_ON_2) {
|
||||
glPointSize( (float) m_pScene->GetPointSize()) ;
|
||||
glLineWidth( (float) m_pScene->GetLineWidth()) ;
|
||||
}
|
||||
|
||||
+9
-7
@@ -26,8 +26,8 @@ class OgAtom {
|
||||
OgAtom( void) : m_nType( NONE), m_fX( 0), m_fY( 0), m_fZ( 0), m_fW( 1) {}
|
||||
|
||||
public :
|
||||
enum GrType { NONE = 0, START = 1, START_A = 2, END = 3, VERT = 4, BND_FLAG = 5, NORMAL = 6,
|
||||
COLOR = 7, MAT_A = 8, MAT_D = 9, MAT_S = 10, MAT_SH = 11, MAT_B = 12, LINE_STIPPLE = 13} ;
|
||||
enum GrType { NONE = 0, START = 1, START_A = 2, START_S = 3, END = 4, VERT = 5, BND_FLAG = 6, NORMAL = 7,
|
||||
COLOR = 8, MAT_A = 9, MAT_D = 10, MAT_S = 11, MAT_SH = 12, MAT_B = 13, LINE_STIPPLE = 14} ;
|
||||
|
||||
public :
|
||||
GrType m_nType ;
|
||||
@@ -74,7 +74,10 @@ class ObjOldGraphics : public ObjEGrGraphics
|
||||
{ m_pScene = pScene ; }
|
||||
Scene* GetScene( void) override
|
||||
{ return m_pScene ; }
|
||||
bool SetCurrent( int nCurr) override
|
||||
{ return ( nCurr == 0) ; }
|
||||
void Clear( void) override ;
|
||||
bool Validate( void) override ;
|
||||
bool AddColor( const Color& colC) override ;
|
||||
bool AddMaterial( const Color& colAmb, const Color& colDiff,
|
||||
const Color& colSpec, float fShin) override ;
|
||||
@@ -82,13 +85,12 @@ class ObjOldGraphics : public ObjEGrGraphics
|
||||
bool AddLineStipple( int nFactor, int nPattern) override ;
|
||||
bool AddPoint( const Point3d& ptP, bool bAux = false) override ;
|
||||
bool AddPoints( const PNTVECTOR& vPnt, bool bAux = false) override ;
|
||||
bool AddLines( const PNTVECTOR& vPnt, bool bAux = false) override ;
|
||||
bool AddPolyLine( const PolyLine& PL, bool bAux = false) override ;
|
||||
bool AddLines( const PNTVECTOR& vPnt, bool bAux = false, bool bSurfSha = false) override ;
|
||||
bool AddPolyLine( const PolyLine& PL, bool bAux = false, bool bSurfSha = false) override ;
|
||||
bool StartTriangles( int nNum, bool bAux = false) override ;
|
||||
bool AddTriangle( const Triangle3d& Tria, const TriFlags3d& TFlags, const TriNormals3d& TNrms) override ;
|
||||
bool EndTriangles( void) override ;
|
||||
bool Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlpha, bool bShowAux) override ;
|
||||
|
||||
bool GetLocalBBox( BBox3d& b3Loc) const override
|
||||
{ b3Loc = m_b3Loc ; return ! m_b3Loc.IsEmpty() ; }
|
||||
|
||||
@@ -100,9 +102,9 @@ class ObjOldGraphics : public ObjEGrGraphics
|
||||
{ try { m_ogaVect.push_back( oga) ; }
|
||||
catch(...) { return false ; }
|
||||
return true ; }
|
||||
bool AddOgaStart( int nMode, bool bAux = false)
|
||||
bool AddOgaStart( int nMode, bool bAux = false, bool bSurfSha = false)
|
||||
{ OgAtom oga ;
|
||||
oga.m_nType = ( bAux ? OgAtom::START_A : OgAtom::START) ;
|
||||
oga.m_nType = ( bSurfSha ? OgAtom::START_S : ( bAux ? OgAtom::START_A : OgAtom::START)) ;
|
||||
oga.m_nMode = nMode ;
|
||||
return AddOgAtom( oga) ; }
|
||||
bool AddOgaEnd( void)
|
||||
|
||||
@@ -111,11 +111,9 @@ class Scene : public IEGrScene
|
||||
bool ZoomChange( double dCoeff) override ;
|
||||
bool ZoomOnPoint( const Point3d& ptWin, double dCoeff) override ;
|
||||
bool ZoomWin( const Point3d& ptWin1, const Point3d& ptWin2) override ;
|
||||
bool RotateCameraWithCube() ;
|
||||
bool RotateCameraWithBlockedAngle( Vector3d vDirS, Vector3d vDirE, double dDist, int nAdaptSpeed,
|
||||
int nBlockedAngle, double dTheta_orig, double dPhi_orig,
|
||||
double& dTheta_new, double& dPhi_new) ;
|
||||
void GetOrthoCamParam( double* pdWidth, double* pdHeight, double* pdNear, double* pdFar) const override ;
|
||||
bool SetCameraType( bool bOrthoOrPersp) override ;
|
||||
bool SetZoomType( int nZoomMode) override ;
|
||||
// ShowMode
|
||||
bool SetShowMode( int nShowMode) override
|
||||
{ if ( nShowMode != SM_WIREFRAME &&
|
||||
@@ -142,16 +140,11 @@ class Scene : public IEGrScene
|
||||
{ m_nShowText = nMode ; }
|
||||
int GetShowText( void) const override
|
||||
{ return m_nShowText ; }
|
||||
// Colors
|
||||
void SetSceneColors( Color cColX, Color cColY, Color cColZ, Color cColXm, Color cColYm, Color cColZm,
|
||||
Color cColEdge, Color cColCorner) override
|
||||
{ m_cColX = cColX ; m_cColY = cColY ; m_cColZ = cColZ ;
|
||||
m_cColXm = cColXm ; m_cColYm = cColYm ; m_cColZm = cColZm ;
|
||||
m_cColEdge = cColEdge ; m_cColCorner = cColCorner ; }
|
||||
// Geometry
|
||||
bool SetExtension( const BBox3d& b3Ext) override ;
|
||||
bool UpdateExtension( void) override ;
|
||||
bool SetMark( Color colMark) override ;
|
||||
bool SetMark2( Color colMark) override ;
|
||||
bool SetSelSurf( Color colSelSurf) override ;
|
||||
bool SetLineWidth( int nW) override ;
|
||||
// Grid
|
||||
@@ -162,17 +155,8 @@ class Scene : public IEGrScene
|
||||
bool SetGridColor( Color colMinLine, Color colMajLine) override ;
|
||||
void GetGridParam( double& dSnapStep, int& nExtStep) const override ;
|
||||
bool GetShowGrid() override ;
|
||||
// Axis Frame
|
||||
// Glob Frame
|
||||
bool SetGlobFrameShow( bool bShow) override ;
|
||||
bool SetGlobFrameParameters( int nPosFlag, double dDistX, double dDistY,
|
||||
double dLenLine, double dWidthLine) override ;
|
||||
// Glob Cube
|
||||
bool DrawCube( bool bSurf) override ;
|
||||
bool CreateFlatPart( ISurfTriMesh* pSrf) override ;
|
||||
bool CreateEdgePart( ISurfTriMesh* pSrf) override ;
|
||||
bool CreateCornerPart( ISurfTriMesh* pSrf) override ;
|
||||
bool GetAngleByCubeFace( int nFaceId, double& dTheta, double& dPhi) ;
|
||||
bool SetGlobCubeParameters( int nPosFlag, double dDistX, double dDistY, double dLenEdge) override ;
|
||||
// Direct
|
||||
bool SetGeoLineAttribs( Color GLcol) override ;
|
||||
bool SetGeoLine( const Point3d& ptP1, const Point3d& ptP2) override ;
|
||||
@@ -247,8 +231,8 @@ class Scene : public IEGrScene
|
||||
double GetFrameLineWidth( void) const
|
||||
{ return m_dFrameLineWidth ; }
|
||||
// Geometry
|
||||
Color GetMark( void) const
|
||||
{ return m_colMark ; }
|
||||
Color GetMark( int nMark) const
|
||||
{ return ( nMark == GDB_MK_ON_2 ? m_colMark2 : m_colMark) ; }
|
||||
Color GetSelSurf( void) const
|
||||
{ return m_colSelSurf ; }
|
||||
|
||||
@@ -262,10 +246,13 @@ class Scene : public IEGrScene
|
||||
bool MyDraw( bool bSwapBF) ;
|
||||
bool Background( void) ;
|
||||
bool Prepare( void) ;
|
||||
bool GetPixelZ( const Point3d& ptWin, double& dWinZ) ;
|
||||
// Camera
|
||||
bool VerifyCamera( bool bUseOrizzOffsCamera = false) ;
|
||||
bool CalcDirUp( bool bUseOrizzOffsCamera = false) ;
|
||||
bool CalcCameraFrame( Frame3d& frView) ;
|
||||
double CalcMinCameraDistance() ;
|
||||
bool CalcDistCamera() ;
|
||||
// Geometry
|
||||
bool DrawGroup( int nId, int nPass, const MdStMkCol& siParent) ;
|
||||
bool DrawGroup( const IGdbIterator& iIter, int nPass, const MdStMkCol& siParent) ;
|
||||
@@ -279,11 +266,8 @@ class Scene : public IEGrScene
|
||||
static Frame3d frGrid ;
|
||||
return frGrid ; }
|
||||
bool DrawGrid( void) ;
|
||||
bool DrawRectangularGrid( void) ;
|
||||
// Glob Frame
|
||||
bool DrawGlobFrame( void) ;
|
||||
// Glob Cube
|
||||
bool DrawGlobCube( bool bSurf) ;
|
||||
// Direct
|
||||
bool DrawDirect( void) ;
|
||||
bool DrawGeoLine( void) ;
|
||||
@@ -316,24 +300,18 @@ class Scene : public IEGrScene
|
||||
HGLRC m_hRC ; // OpenGL Rendering Context
|
||||
int m_nOglVer ; // OpenGL Version
|
||||
bool m_bNewWay ; // flag che indica nuova modalità (OpenGL 3.0 in poi)
|
||||
// Colors
|
||||
Color m_cColX ; // colore asse x
|
||||
Color m_cColXm ; // colore asse -x
|
||||
Color m_cColY ; // colore asse y
|
||||
Color m_cColYm ; // colore asse -y
|
||||
Color m_cColZ ; // colore asse z
|
||||
Color m_cColZm ; // colore asse -z
|
||||
Color m_cColEdge ; // colore per Edge ( per cubetto)
|
||||
Color m_cColCorner ; // colore per Corner ( per cubetto)
|
||||
// Camera
|
||||
Point3d m_ptCenter ; // centro verso cui è rivolta la camera
|
||||
Vector3d m_vtDirCamera ; // versore direzione dal centro alla camera
|
||||
int m_nOrizzOffsCamera ; // offset orizzontale viste camera in multipli di 90deg
|
||||
double m_dDistCamera ; // distanza dal centro alla camera
|
||||
bool m_bDistOk ; // flag per stato aggiornamento di dDistCamera
|
||||
Vector3d m_vtUp ; // versore direzione Su della camera
|
||||
bool m_bUpOk ; // flag per stato aggiornamento di Up
|
||||
int m_nViewportW ; // larghezza della finestra
|
||||
int m_nViewportH ; // altezza della finestra
|
||||
bool m_bOrthographic ; // flag che indica se camera ortografica o prospettica
|
||||
int m_nPerspZoomType ; // flag che indica tipologia di zoom in vista prospettica ( standard, dolly)
|
||||
// Textures
|
||||
TextureMgr m_TextMgr ; // gestore di textures
|
||||
// Background
|
||||
@@ -368,7 +346,7 @@ class Scene : public IEGrScene
|
||||
SelRec m_nSelBuff[DIM_SEL_BUF] ; // buffer per selezione con OpenGL
|
||||
// Snap
|
||||
// lo snap a oggetti usa la select, quindi anche per esso valgono m_nObjFilterForSelect e m_Unsel
|
||||
int m_nLastSnapId ; // Id dell'entit� generatrice dell'ultimo punto snap
|
||||
int m_nLastSnapId ; // Id dell'entità generatrice dell'ultimo punto snap
|
||||
Point3d m_ptLastSnapPnt ; // ultimo punto di snap
|
||||
bool m_bLastSnapDirOk ; // flag validità direzione associata a ultimo punto snap
|
||||
Vector3d m_vtLastSnapDir ; // direzione associata a ultimo punto snap
|
||||
@@ -376,6 +354,7 @@ class Scene : public IEGrScene
|
||||
IGeomDB* m_pGeomDB ; // puntatore al DB geometrico
|
||||
Color m_colDef ; // colore di default
|
||||
Color m_colMark ; // colore per marcatura
|
||||
Color m_colMark2 ; // colore per marcatura di tipo 2
|
||||
Color m_colSelSurf ; // colore di superficie selezionata
|
||||
// Superfici semitrasparenti
|
||||
ASURFVECTOR m_vAlphaSurf ; // vettore temporaneo di superfici semitrasparenti
|
||||
@@ -400,23 +379,9 @@ class Scene : public IEGrScene
|
||||
double m_dGridMaxY ; // massima estensione in Y della griglia
|
||||
Color m_colMinLine ; // colore delle linee minori
|
||||
Color m_colMajLine ; // colore delle linee maggiori
|
||||
// Axis Frame
|
||||
// Glob Frame
|
||||
bool m_bShowGlobFrame ; // flag di visualizzazione del riferimento globale
|
||||
int m_nAxisFrame_Flag ; // flag per quadrante di visualizzazione del frame
|
||||
double m_dFrame_DistX ; // X del Centro del frame sullo schermo
|
||||
double m_dFrame_DistY ; // Y del Centro del frame sullo schetrmo
|
||||
double m_dFrameLineL ; // lunghezza delle linee del frame
|
||||
double m_dFrameLineW ; // spessore delle linee del frame
|
||||
// Glob Cube
|
||||
ISURFTMPOVECTOR m_vStm_Cube ; // vettore contenente le superificie del cubo ( 26 in totale)
|
||||
bool m_bShowGlobCube ; // flag di visualizzazione del cubetto
|
||||
Point3d m_ptOrigCube ; // centro del cubo in cordinate globali
|
||||
int m_nCube_Flag ; // flag per posizione negli angoli del cubetto
|
||||
double m_dCubeEdge ; // lunghezza del lato del cubo
|
||||
double m_dCubeX ; // X del Centro del cubo sullo schermo
|
||||
double m_dCubeY ; // Y del Centro del cubo sullo schermo
|
||||
int m_nStartFaceId ; // nuovo id iniziale utilizzato per assegnare un id univoco e non in uso alle facce del cubo
|
||||
// Direct
|
||||
// Direct
|
||||
Color m_colorGL ; // colore per GeoLine
|
||||
bool m_bGeoLine ; // flag esistenza linea diretta in finestra
|
||||
Point3d m_ptGeoLineP1 ; // primo estremo della linea diretta
|
||||
@@ -432,3 +397,10 @@ class Scene : public IEGrScene
|
||||
Point3d m_ptWinRectP1 ; // primo estremo del rettangolo diretto
|
||||
Point3d m_ptWinRectP2 ; // secondo estremo del rettangolo diretto
|
||||
} ;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static const double PERSPECTIVE_NEAR_PLANE = 10 ;
|
||||
static const double PERSPECTIVE_STD_FOV = 45 ;
|
||||
static const double PERSPECTIVE_MAX_FOV = 100 ;
|
||||
static const double PERSPECTIVE_TAN_MAX_FOV = tan( 0.5 * PERSPECTIVE_MAX_FOV * DEGTORAD) ;
|
||||
|
||||
+100
-45
@@ -51,27 +51,20 @@ Scene::Scene( void)
|
||||
m_hRC = nullptr ;
|
||||
m_nOglVer = 0 ;
|
||||
m_bNewWay = false ;
|
||||
// Colors
|
||||
m_cColX = Color( 255, 0, 0, 1) ;
|
||||
m_cColXm = Color( 167, 27, 11, 1) ;
|
||||
m_cColY = Color( 0, 255, 0, 1) ;
|
||||
m_cColYm = Color( 36, 163, 25, 1) ;
|
||||
m_cColZ = Color( 0, 0, 255, 1) ;
|
||||
m_cColZm = Color( 36, 17, 120, 1) ;
|
||||
m_cColEdge = Color( 200, 200, 200, 1) ;
|
||||
m_cColCorner = Color( 200, 200, 200, 1) ;
|
||||
// Camera e viewport
|
||||
m_ptCenter = ORIG ;
|
||||
m_nOrizzOffsCamera = 0 ;
|
||||
SetCamera( 0, 0, 0) ;
|
||||
m_nViewportW = 0 ;
|
||||
m_nViewportH = 0 ;
|
||||
m_bOrthographic = true ;
|
||||
m_nPerspZoomType = ZT_STD ;
|
||||
// Textures
|
||||
m_TextMgr.SetScene( this) ;
|
||||
// Sfondo
|
||||
m_colBackTop.Set( 176, 176, 176) ;
|
||||
m_colBackBottom.Set( 176, 176, 176) ;
|
||||
// Modalit� di visualizzazione
|
||||
// Modalità di visualizzazione
|
||||
m_nShowMode = SM_WIREFRAME ;
|
||||
m_bShowCurveDirection = false ;
|
||||
m_bShowTriaAdvanced = true ;
|
||||
@@ -98,6 +91,7 @@ Scene::Scene( void)
|
||||
m_pGeomDB = nullptr ;
|
||||
m_colDef.Set( 0, 0, 0) ;
|
||||
m_colMark.Set( 255, 255, 0) ;
|
||||
m_colMark2.Set( 255, 64, 64) ;
|
||||
m_colSelSurf.Set( 255, 255, 192) ;
|
||||
// Superfici semitrasparenti
|
||||
m_vAlphaSurf.reserve( 100) ;
|
||||
@@ -146,7 +140,7 @@ Scene::Init( IGeomDB* pGeomDB)
|
||||
bool
|
||||
Scene::CreateContext( HDC hDC, int nDriver, bool b2Buff, int nColorBits, int nDepthBits)
|
||||
{
|
||||
// verifico validit� Device Context
|
||||
// verifico validità Device Context
|
||||
if ( hDC == nullptr)
|
||||
return false ;
|
||||
m_hDC = hDC ;
|
||||
@@ -223,7 +217,7 @@ Scene::CreateContext( HDC hDC, int nDriver, bool b2Buff, int nColorBits, int nDe
|
||||
LOG_INFO( GetEGrLogger(), "WGL_ARB_create_context missing !")
|
||||
}
|
||||
|
||||
// verifico validit� Rendering Context
|
||||
// verifico validità Rendering Context
|
||||
if ( m_hRC == nullptr)
|
||||
return false ;
|
||||
|
||||
@@ -234,7 +228,7 @@ Scene::CreateContext( HDC hDC, int nDriver, bool b2Buff, int nColorBits, int nDe
|
||||
if ( GlewInitResult != GLEW_OK)
|
||||
LOG_INFO( GetEGrLogger(), "GLEW is not initialized !")
|
||||
|
||||
// verifico se posso lavorare in modalit� nuova
|
||||
// verifico se posso lavorare in modalità nuova
|
||||
m_bNewWay = ( nDriver == OD_NEW && glewIsSupported( "GL_VERSION_3_0") == 1) ;
|
||||
if ( ! m_bNewWay)
|
||||
LOG_INFO( GetEGrLogger(), "OpenGL old way rendering !")
|
||||
@@ -296,11 +290,11 @@ Scene::ChooseGenPixelFormat( int nPfd, bool b2Buff, int nColorBits, int nDepthBi
|
||||
bool
|
||||
Scene::MakeCurrent( void) const
|
||||
{
|
||||
// se RC della scena non � definito, errore
|
||||
// se RC della scena non è definito, errore
|
||||
if ( m_hRC == nullptr)
|
||||
return false ;
|
||||
|
||||
// se RC della scena � quello corrente, ok
|
||||
// se RC della scena è quello corrente, ok
|
||||
HGLRC hRC = wglGetCurrentContext() ;
|
||||
if ( m_hRC == hRC)
|
||||
return true ;
|
||||
@@ -427,7 +421,7 @@ Scene::SetExtension( const BBox3d& b3Ext)
|
||||
bool
|
||||
Scene::CalcExtView( void)
|
||||
{
|
||||
// verifico se il calcolo � necessario
|
||||
// verifico se il calcolo è necessario
|
||||
if ( m_bExtViewOk && m_bUpOk)
|
||||
return true ;
|
||||
// calcolo direzione camera Up
|
||||
@@ -523,9 +517,14 @@ Scene::CalcClippingPlanesFromExtView( void)
|
||||
// ricavo la posizione dei piani di clipping sull'asse Z di vista
|
||||
const double EXP_COEFF = 1.1 ;
|
||||
double dExtent = max( ( EXP_COEFF * vtExtent.z), MIN_ZCLIP_EXT) ;
|
||||
m_dZNear = - ( ptCenter.z + dExtent) ;
|
||||
m_dZFar = - ( ptCenter.z - dExtent) ;
|
||||
|
||||
if ( m_bOrthographic) {
|
||||
m_dZNear = - ( ptCenter.z + dExtent) ;
|
||||
m_dZFar = - ( ptCenter.z - dExtent) ;
|
||||
}
|
||||
else {
|
||||
m_dZNear = PERSPECTIVE_NEAR_PLANE ;
|
||||
m_dZFar = abs( ptCenter.z - dExtent) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
@@ -682,6 +681,9 @@ Scene::Prepare( void)
|
||||
|
||||
// eventuale ricalcolo parametri di vista
|
||||
CalcDirUp() ;
|
||||
CalcDistCamera() ;
|
||||
if ( ! m_bOrthographic)
|
||||
m_bDistOk = false ; // resetto il flag per le prossime operazioni
|
||||
|
||||
// imposto matrice di proiezione
|
||||
glMatrixMode( GL_PROJECTION) ;
|
||||
@@ -693,7 +695,27 @@ Scene::Prepare( void)
|
||||
// imposto area di pick
|
||||
gluPickMatrix( m_ptSelCent.x, ( Viewport[3] - m_ptSelCent.y), m_nSelW, m_nSelH, Viewport) ;
|
||||
}
|
||||
glOrtho( - m_dHalfWidth, m_dHalfWidth, - m_dHalfHeight, m_dHalfHeight, m_dZNear, m_dZFar) ;
|
||||
|
||||
if ( m_bOrthographic)
|
||||
glOrtho( - m_dHalfWidth, m_dHalfWidth, - m_dHalfHeight, m_dHalfHeight, m_dZNear, m_dZFar) ;
|
||||
else {
|
||||
// calcolo del fov : se dolly è costante, se zoom standard deve adattarsi alla vista
|
||||
double dFov = PERSPECTIVE_STD_FOV ;
|
||||
double dRatio = m_dHalfWidth / m_dHalfHeight ;
|
||||
if ( m_nPerspZoomType == ZT_STD) {
|
||||
// verifico che il fov non superi il valore massimo consentito
|
||||
if ( m_dHalfHeight / m_dDistCamera > PERSPECTIVE_TAN_MAX_FOV) {
|
||||
dFov = PERSPECTIVE_MAX_FOV ;
|
||||
// aggiusto i valori di HalfHeight e HalfWidth
|
||||
m_dHalfHeight = m_dDistCamera * PERSPECTIVE_TAN_MAX_FOV ;
|
||||
m_dHalfWidth = dRatio * m_dHalfHeight ;
|
||||
}
|
||||
else
|
||||
dFov = 2 * atan2( m_dHalfHeight, m_dDistCamera) * RADTODEG ;
|
||||
}
|
||||
|
||||
gluPerspective( abs( dFov), dRatio, m_dZNear, m_dZFar) ;
|
||||
}
|
||||
|
||||
// imposto matrice modello/vista
|
||||
glMatrixMode( GL_MODELVIEW) ;
|
||||
@@ -740,12 +762,12 @@ Scene::MyDraw( bool bSwapBF)
|
||||
if ( m_pGeomDB != nullptr)
|
||||
m_pGeomDB->GetDefaultMaterial( m_colDef) ;
|
||||
|
||||
// impostazioni dipendenti dalla modalit� di visualizzazione
|
||||
// impostazioni dipendenti dalla modalità di visualizzazione
|
||||
switch ( m_nShowMode) {
|
||||
case SM_WIREFRAME :
|
||||
// disabilito illuminazione
|
||||
glDisable( GL_LIGHTING) ;
|
||||
// disegno griglia senza illuminazione (gi� impostato)
|
||||
// disegno griglia senza illuminazione (già impostato)
|
||||
DrawGrid() ;
|
||||
// imposto dati standard per punti e linee
|
||||
glPointSize( (float) GetPointSize()) ;
|
||||
@@ -758,7 +780,7 @@ Scene::MyDraw( bool bSwapBF)
|
||||
case SM_HIDDENLINE :
|
||||
// disabilito illuminazione
|
||||
glDisable( GL_LIGHTING) ;
|
||||
// disegno griglia senza illuminazione (gi� impostato)
|
||||
// disegno griglia senza illuminazione (già impostato)
|
||||
DrawGrid() ;
|
||||
// imposto dati standard per punti e linee
|
||||
glPointSize( (float) GetPointSize()) ;
|
||||
@@ -844,10 +866,6 @@ Scene::MyDraw( bool bSwapBF)
|
||||
glDisable( GL_DEPTH_TEST) ;
|
||||
glDisable( GL_LIGHTING) ;
|
||||
|
||||
// da togliere e richiamare esternamente...
|
||||
SetGlobCubeParameters( 1, 60, 60, 75) ;
|
||||
SetGlobFrameParameters( 3, 40, 40, 25, 2) ;
|
||||
|
||||
// disegno riferimento globale
|
||||
DrawGlobFrame() ;
|
||||
|
||||
@@ -855,24 +873,6 @@ Scene::MyDraw( bool bSwapBF)
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL) ;
|
||||
DrawDirect() ;
|
||||
|
||||
|
||||
// disegno il cubetto
|
||||
glDisable( GL_LIGHTING) ;
|
||||
glEnable( GL_DEPTH_TEST) ;
|
||||
glEnable( GL_POLYGON_OFFSET_FILL) ;
|
||||
glFrontFace( GL_CCW) ;
|
||||
glCullFace( GL_BACK) ;
|
||||
glEnable( GL_CULL_FACE) ;
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL) ;
|
||||
glPolygonOffset( 0.5, 0.5) ;
|
||||
DrawGlobCube( true) ; // superifici
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE) ;
|
||||
glLineWidth( 1) ;
|
||||
DrawGlobCube( false) ; // linee
|
||||
glLineWidth( GetLineWidth()) ;
|
||||
glDisable( GL_CULL_FACE) ;
|
||||
glDisable( GL_DEPTH_TEST) ;
|
||||
|
||||
// aggiorno
|
||||
glFlush() ;
|
||||
|
||||
@@ -941,6 +941,61 @@ Scene::UnProject( const Point3d& ptView, Point3d& ptWorld) const
|
||||
return ( nRes == GL_TRUE) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::GetPixelZ( const Point3d& ptWin, double& dWinZ)
|
||||
{
|
||||
glGetError() ;
|
||||
|
||||
// recupero la ViewPort corrente
|
||||
GLint Viewport[ 4] ;
|
||||
glGetIntegerv( GL_VIEWPORT, Viewport) ;
|
||||
|
||||
// inizializzo i parametri come per la selezione, senza però effettuarla !
|
||||
m_bSelect = true ;
|
||||
m_ptSelCent = ptWin ;
|
||||
m_nSelW = 13 ; // riducibile ...
|
||||
m_nSelH = 13 ; // riducibile ...
|
||||
|
||||
// imposto la pick-matrix e la proiezione ridotta
|
||||
if ( ! Prepare()) {
|
||||
m_bSelect = false ;
|
||||
dWinZ = GetProjectedCenter().z ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// forzo rendering opaco per il picking: niente blending, depth write ON
|
||||
glDisable( GL_LIGHTING) ;
|
||||
glDisable( GL_BLEND) ;
|
||||
glEnable( GL_DEPTH_TEST) ;
|
||||
glDepthMask( GL_TRUE) ;
|
||||
glClear( GL_DEPTH_BUFFER_BIT) ; // pulizia buffer depth per futura scrittura
|
||||
|
||||
// disegno la scena nella viewport ridotta : questo scrive il depth buffer ( se fossi nella vera
|
||||
// modalità di selezione GL_SELECT non scriverei le depth nel buffer, in quanto non c'è una
|
||||
// modalità di rendering)
|
||||
DrawGroup( GDB_ID_ROOT, 1, MdStMkCol( GDB_MD_STD, GDB_ST_ON, GDB_MK_OFF, m_colDef)) ;
|
||||
glFlush() ; // per sicurezza attendo
|
||||
|
||||
// leggo la Z del pixel corrente, le coordinate x e y non cambiano rispetto alla viewport originale
|
||||
glReadBuffer( GL_FRONT) ;
|
||||
float dZ ;
|
||||
bool bOk = true ;
|
||||
glReadPixels( int( ptWin.x), int( Viewport[3] - ptWin.y), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &dZ) ;
|
||||
if ( glGetError() == GL_NO_ERROR && dZ > 0.1f && dZ < 0.9f)
|
||||
dWinZ = dZ ;
|
||||
else {
|
||||
bOk = false ;
|
||||
dWinZ = GetProjectedCenter().z ;
|
||||
}
|
||||
|
||||
// reset dei parametri
|
||||
m_bSelect = false ;
|
||||
Prepare() ;
|
||||
|
||||
return bOk ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void
|
||||
Scene::Destroy( void)
|
||||
|
||||
+227
-51
@@ -14,9 +14,11 @@
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "Scene.h"
|
||||
#include "/EgtDev/Include/EgtILogger.h"
|
||||
#include "/EgtDev/Include/EGnStringUtils.h"
|
||||
#include "/EgtDev/Include/EGkFrame3d.h"
|
||||
#include "/EgtDev/Include/EGnStringUtils.h"
|
||||
#include "/EgtDev/Include/EgtNumUtils.h"
|
||||
#include "/EgtDev/Include/EgtILogger.h"
|
||||
|
||||
|
||||
using namespace std ;
|
||||
|
||||
@@ -24,10 +26,74 @@ using namespace std ;
|
||||
static const double MIN_DIST_CAMERA = 10 ;
|
||||
static const double STD_DIST_CAMERA = 1000 ;
|
||||
|
||||
static const double MIN_HALF_WIDTH_STD = 0.7 ;
|
||||
static const double MAX_HALF_WIDTH_STD = 180000 ;
|
||||
static const double MIN_HALF_HEIGHT_STD = 0.5 ;
|
||||
static const double MAX_HALF_HEIGHT_STD = 140000 ;
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::SetCameraType( bool bOrthoOrPersp)
|
||||
{
|
||||
m_bOrthographic = bOrthoOrPersp ;
|
||||
// ricalcolo i parametri di vista
|
||||
m_bDistOk = false ;
|
||||
CalcDistCamera() ;
|
||||
CalcClippingPlanesFromExtView() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::SetZoomType( int nZoomMode)
|
||||
{
|
||||
if ( nZoomMode != ZT_STD && nZoomMode != ZT_DOLLY)
|
||||
return false ;
|
||||
m_nPerspZoomType = nZoomMode ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
double
|
||||
Scene::CalcMinCameraDistance()
|
||||
{
|
||||
double dMinDist = MIN_DIST_CAMERA ;
|
||||
|
||||
// nel caso di vista prospettica la distanza della camera deve garantire di non finire dentro gli oggetti
|
||||
if ( ! m_bOrthographic) {
|
||||
|
||||
// calcolo il box di tutti gli oggetti visibili nel frame della camera
|
||||
Frame3d frCamera ;
|
||||
CalcCameraFrame( frCamera) ;
|
||||
BBox3d b3Tot ;
|
||||
if ( m_pGeomDB != nullptr)
|
||||
m_pGeomDB->GetGlobalBBox( GDB_ID_ROOT, b3Tot, BBF_ONLY_VISIBLE) ;
|
||||
b3Tot.ToLoc( frCamera) ;
|
||||
|
||||
// la distanza minima della camera è quella che garantisce di trovarsi ad una distanza pari almeno a PERSPECTIVE_NEAR_PLANE
|
||||
// dalla faccia del box davanti alla camera
|
||||
Point3d ptMax = b3Tot.GetMax() ;
|
||||
ptMax.ToGlob( frCamera) ;
|
||||
dMinDist = ( ptMax - m_ptCenter) * m_vtDirCamera + PERSPECTIVE_NEAR_PLANE + 10 * EPS_SMALL ;
|
||||
}
|
||||
|
||||
return dMinDist ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::CalcDistCamera()
|
||||
{
|
||||
// verifico se il calcolo è necessario
|
||||
if ( m_bDistOk)
|
||||
return true ;
|
||||
|
||||
if ( m_dDistCamera < EPS_SMALL)
|
||||
m_dDistCamera = STD_DIST_CAMERA ;
|
||||
else {
|
||||
double dMinDist = CalcMinCameraDistance() ;
|
||||
if ( m_dDistCamera < dMinDist)
|
||||
m_dDistCamera = dMinDist ;
|
||||
}
|
||||
m_bDistOk = true ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
@@ -46,9 +112,10 @@ Scene::SetCenter( const Point3d& ptCenter)
|
||||
bool
|
||||
Scene::SetCamera( double dAngVertDeg, double dAngOrizzDeg, double dDist)
|
||||
{
|
||||
// assegno la direzione e la distanza
|
||||
// assegno la direzione ed eventuale distanza
|
||||
m_vtDirCamera = FromSpherical( 1, dAngVertDeg, dAngOrizzDeg) ;
|
||||
m_dDistCamera = dDist ;
|
||||
if ( dDist > EPS_SMALL)
|
||||
m_dDistCamera = dDist ;
|
||||
if ( ! VerifyCamera())
|
||||
return false ;
|
||||
// se vista da sopra, impongo vtUp da angolo orizzontale
|
||||
@@ -108,7 +175,11 @@ Scene::SetCamera( int nDir, double dDist)
|
||||
}
|
||||
if ( nDir != CT_CPLANE)
|
||||
m_vtDirCamera.Rotate( Z_AX, m_nOrizzOffsCamera * ANG_RIGHT) ;
|
||||
m_dDistCamera = dDist ;
|
||||
|
||||
// assegno eventuale distanza
|
||||
if ( dDist > EPS_SMALL)
|
||||
m_dDistCamera = dDist ;
|
||||
|
||||
return VerifyCamera( nDir != CT_CPLANE) ;
|
||||
}
|
||||
|
||||
@@ -119,15 +190,16 @@ Scene::VerifyCamera( bool bUseOrizzOffsCamera)
|
||||
// verifico il versore
|
||||
if ( ! m_vtDirCamera.Normalize())
|
||||
m_vtDirCamera.Set( 0, 0, 1) ;
|
||||
// verifico la distanza
|
||||
if ( m_dDistCamera < EPS_SMALL)
|
||||
m_dDistCamera = STD_DIST_CAMERA ;
|
||||
else
|
||||
m_dDistCamera = max( m_dDistCamera, MIN_DIST_CAMERA) ;
|
||||
|
||||
// ricalcolo direzione Up
|
||||
m_bUpOk = false ;
|
||||
if ( ! CalcDirUp( bUseOrizzOffsCamera))
|
||||
return false ;
|
||||
|
||||
// verifico la distanza
|
||||
m_bDistOk = false ;
|
||||
CalcDistCamera() ;
|
||||
|
||||
// ricalcolo ExtView
|
||||
m_bExtViewOk = false ;
|
||||
if ( ! CalcExtView())
|
||||
@@ -208,11 +280,11 @@ Scene::GetProjectedCenter( void) const
|
||||
bool
|
||||
Scene::CalcDirUp( bool bUseOrizzOffsCamera)
|
||||
{
|
||||
// verifico se il calcolo è necessario
|
||||
// verifico se il calcolo è necessario
|
||||
if ( m_bUpOk)
|
||||
return true ;
|
||||
// direzione perpendicolare giacente nel piano XY
|
||||
// ( m_vtDirCamera è opposta alla direzione in cui si guarda)
|
||||
// ( m_vtDirCamera è opposta alla direzione in cui si guarda)
|
||||
Vector3d vtPerpXY = m_vtDirCamera ^ Z_AX ;
|
||||
if ( ! vtPerpXY.Normalize()) {
|
||||
vtPerpXY = -X_AX ;
|
||||
@@ -249,19 +321,29 @@ bool
|
||||
Scene::PanCamera( const Point3d& ptWinOld, const Point3d& ptWinNew)
|
||||
{
|
||||
// porto i due punti in coordinate mondo
|
||||
double dZCenter = GetProjectedCenter().z ;
|
||||
Point3d ptViewOld( ptWinOld.x, ptWinOld.y, dZCenter) ;
|
||||
double dOldZCenter ;
|
||||
GetPixelZ( ptWinOld, dOldZCenter) ;
|
||||
Point3d ptViewOld( ptWinOld.x, ptWinOld.y, dOldZCenter) ;
|
||||
Point3d ptWorldOld ;
|
||||
if ( ! UnProject( ptViewOld, ptWorldOld))
|
||||
return false ;
|
||||
Point3d ptViewNew( ptWinNew.x, ptWinNew.y, dZCenter) ;
|
||||
double dNewZCenter ;
|
||||
GetPixelZ( ptWinNew, dNewZCenter) ;
|
||||
Point3d ptViewNew( ptWinNew.x, ptWinNew.y, dNewZCenter) ;
|
||||
Point3d ptWorldNew ;
|
||||
if ( ! UnProject( ptViewNew, ptWorldNew))
|
||||
return false ;
|
||||
// calcolo lo spostamento tra i due punti
|
||||
Vector3d vtMove = ptWorldNew - ptWorldOld ;
|
||||
// applico questo spostamento al centro di vista
|
||||
return SetCenter( GetCenter() - vtMove) ;
|
||||
SetCenter( GetCenter() - vtMove) ;
|
||||
// se dolly aggiusto la distanza per non entrare negli oggetti
|
||||
if ( ! m_bOrthographic && m_nPerspZoomType == ZT_DOLLY)
|
||||
CalcDistCamera() ;
|
||||
else
|
||||
m_bDistOk = true ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -307,6 +389,31 @@ Scene::ZoomAll( void)
|
||||
|
||||
// calcolo nuovi dati di ingombro
|
||||
CalcDimViewFromExtView() ;
|
||||
|
||||
if ( ! m_bOrthographic) {
|
||||
if ( m_nPerspZoomType == ZT_DOLLY) {
|
||||
// adatto la distanza della camera in modo che il fov resti al valore standard
|
||||
m_dDistCamera = m_dHalfHeight / tan( PERSPECTIVE_STD_FOV * 0.5 * DEGTORAD) + ( m_b3ExtView.GetMax().z - m_b3ExtView.GetMin().z) * 0.5 ;
|
||||
}
|
||||
else {
|
||||
// aggiusto la distanza della camera
|
||||
m_b3ExtView.GetDiameter( m_dDistCamera) ;
|
||||
|
||||
// il valore di m_dHalfHeight calcolato dal box non garantisce che l'oggetto sia interamente contenuto nel frustum
|
||||
// perchè è il valore in corrispondenza della faccia del box davanti alla camera. Per il calcolo del fov m_dHalfHeight
|
||||
// deve essere calcolato in corrispondenza di m_ptCenter
|
||||
// distanza della camera dalla faccia davanti del box
|
||||
double dDist = m_dDistCamera - ( m_b3ExtView.GetMax().z - m_b3ExtView.GetMin().z) * 0.5 ;
|
||||
// aggiorno le dimensioni
|
||||
double dAspect = m_dHalfWidth / m_dHalfHeight ;
|
||||
m_dHalfHeight = m_dHalfHeight / dDist * m_dDistCamera ;
|
||||
m_dHalfWidth = m_dHalfHeight * dAspect ;
|
||||
|
||||
}
|
||||
}
|
||||
// la distanza della camera è calcolata correttamente
|
||||
m_bDistOk = true ;
|
||||
|
||||
CalcClippingPlanesFromExtView() ;
|
||||
|
||||
return true ;
|
||||
@@ -349,8 +456,32 @@ Scene::ZoomObject( int nId)
|
||||
double dHalfHeight = COEFF * ( b3Obj.GetMax().y - b3Obj.GetMin().y) / 2 ;
|
||||
|
||||
// imposto il centro e le dimensioni di vista
|
||||
m_ptCenter = ptCent ;
|
||||
return AdjustDimView( dHalfWidth, dHalfHeight) ;
|
||||
m_ptCenter = ptCent ;
|
||||
if ( ! AdjustDimView( dHalfWidth, dHalfHeight))
|
||||
return false ;
|
||||
|
||||
if ( ! m_bOrthographic) {
|
||||
// cfr conti analoghi in ZoomAll
|
||||
if ( m_nPerspZoomType == ZT_DOLLY) {
|
||||
m_dDistCamera = m_dHalfHeight / tan( PERSPECTIVE_STD_FOV * 0.5 * DEGTORAD) + ( b3Obj.GetMax().z - b3Obj.GetMin().z) * 0.5 ;
|
||||
}
|
||||
else {
|
||||
// verifico di non finire dentro l'oggetto
|
||||
double dDiam ; b3Obj.GetDiameter( dDiam) ;
|
||||
if ( m_dDistCamera < dDiam * 0.5)
|
||||
m_dDistCamera = dDiam * 0.5 ;
|
||||
// distanza della camera dalla faccia davanti del box
|
||||
double dDist = m_dDistCamera - ( b3Obj.GetMax().z - b3Obj.GetMin().z) * 0.5 ;
|
||||
// ricalcolo le dimensioni
|
||||
double dAspect = m_dHalfWidth / m_dHalfHeight ;
|
||||
m_dHalfHeight = m_dHalfHeight / dDist * m_dDistCamera ;
|
||||
m_dHalfWidth = m_dHalfHeight * dAspect ;
|
||||
}
|
||||
}
|
||||
// la distanza della camera è calcolata per non finire dentro gli oggetti
|
||||
m_bDistOk = true ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -358,7 +489,19 @@ bool
|
||||
Scene::ZoomRadius( double dRadius)
|
||||
{
|
||||
// adatto le dimensioni a quelle della vista
|
||||
return AdjustDimView( dRadius, dRadius) ;
|
||||
if ( ! AdjustDimView( dRadius, dRadius))
|
||||
return false ;
|
||||
|
||||
// per il dolly va modificata la distanza dalla camera
|
||||
if ( ! m_bOrthographic && m_nPerspZoomType == ZT_DOLLY) {
|
||||
m_dDistCamera = m_dHalfHeight / tan( PERSPECTIVE_STD_FOV * 0.5 * DEGTORAD) ;
|
||||
// verifico la distanza della camera
|
||||
CalcDistCamera() ;
|
||||
}
|
||||
else
|
||||
m_bDistOk = true ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -368,13 +511,17 @@ Scene::ZoomChange( double dCoeff)
|
||||
const double MIN_COEFF = 0.5 ;
|
||||
const double MAX_COEFF = 2 ;
|
||||
|
||||
// controllo i limiti
|
||||
if ( dCoeff < MIN_COEFF)
|
||||
dCoeff = MIN_COEFF ;
|
||||
else if ( dCoeff > MAX_COEFF)
|
||||
dCoeff = MAX_COEFF ;
|
||||
m_dHalfWidth *= dCoeff ;
|
||||
m_dHalfHeight *= dCoeff ;
|
||||
// cambio le dimensioni di zoom
|
||||
if ( ! m_bOrthographic && m_nPerspZoomType == ZT_DOLLY) {
|
||||
// per il dolly va modificata la distanza della camera
|
||||
m_dDistCamera *= dCoeff ;
|
||||
}
|
||||
else {
|
||||
// controllo i limiti
|
||||
dCoeff = clamp( dCoeff, MIN_COEFF, MAX_COEFF) ;
|
||||
m_dHalfWidth *= dCoeff ;
|
||||
m_dHalfHeight *= dCoeff ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
@@ -383,31 +530,45 @@ Scene::ZoomChange( double dCoeff)
|
||||
bool
|
||||
Scene::ZoomOnPoint( const Point3d& ptWin, double dCoeff)
|
||||
{
|
||||
// recupero la matrice viewport
|
||||
GLint Viewport[4] ;
|
||||
glGetIntegerv( GL_VIEWPORT, Viewport) ;
|
||||
|
||||
// range valori delle Viewport
|
||||
double dLimInfHW = MIN_HALF_WIDTH_STD * Viewport[2] / 1152.0 ;
|
||||
double dLimInfHH = MIN_HALF_HEIGHT_STD * Viewport[3] / 928.0 ;
|
||||
double dLimSupHW = MAX_HALF_WIDTH_STD * Viewport[2] / 1152.0 ;
|
||||
double dLimSupHH = MAX_HALF_WIDTH_STD * Viewport[3] / 928.0 ;
|
||||
|
||||
// controllo se i parametri di Zoom minimo e massimo sono rispettati, altrimenti esco
|
||||
if ( m_dHalfWidth * dCoeff > dLimSupHW || m_dHalfHeight * dCoeff > dLimSupHH)
|
||||
return true ;
|
||||
if ( m_dHalfWidth * dCoeff < dLimInfHW || m_dHalfHeight * dCoeff < dLimInfHH)
|
||||
return true ;
|
||||
// leggo Z del pixel
|
||||
double dWinZ ;
|
||||
GetPixelZ( ptWin, dWinZ) ;
|
||||
|
||||
// porto il punto in coordinate mondo
|
||||
Point3d ptView( ptWin.x, ptWin.y, GetProjectedCenter().z) ;
|
||||
Point3d ptView( ptWin.x, ptWin.y, dWinZ) ;
|
||||
Point3d ptWorld ;
|
||||
if ( ! UnProject( ptView, ptWorld))
|
||||
return false ;
|
||||
|
||||
// modifico opportunamente il centro di vista
|
||||
Point3d ptNewCen = ptWorld + ( GetCenter() - ptWorld) * dCoeff ;
|
||||
Point3d ptOldCen = m_ptCenter ;
|
||||
Point3d ptNewCen = ptWorld + ( m_ptCenter - ptWorld) * dCoeff ;
|
||||
ptNewCen += ( ptWorld - ptNewCen) * m_vtDirCamera * m_vtDirCamera ;
|
||||
SetCenter( ptNewCen) ;
|
||||
// eseguo lo zoom
|
||||
m_bDistOk = true ;
|
||||
|
||||
if ( ! m_bOrthographic) {
|
||||
if ( m_nPerspZoomType == ZT_DOLLY) {
|
||||
// nel caso di dolly verifico se il nuovo zoom fa entrare negli oggetti
|
||||
double dMinDist = CalcMinCameraDistance() ;
|
||||
if ( m_dDistCamera * dCoeff < dMinDist) {
|
||||
// adatto il coefficiente di zoom e ricalcolo il centro
|
||||
dCoeff = dMinDist / m_dDistCamera ;
|
||||
Point3d ptNewCenter = ptWorld + ( ptOldCen - ptWorld) * dCoeff ;
|
||||
SetCenter( ptNewCenter) ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// nel caso standard verifico se il nuovo fov supera il valore massimo
|
||||
if ( m_dHalfHeight * dCoeff / m_dDistCamera > PERSPECTIVE_TAN_MAX_FOV) {
|
||||
// adatto il coefficiente di zoom e ricalcolo il centro
|
||||
dCoeff = PERSPECTIVE_TAN_MAX_FOV * m_dDistCamera / m_dHalfHeight ;
|
||||
Point3d ptNewCenter = ptWorld + ( ptOldCen - ptWorld) * dCoeff ;
|
||||
SetCenter( ptNewCenter) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ZoomChange( dCoeff) ;
|
||||
}
|
||||
|
||||
@@ -415,12 +576,16 @@ Scene::ZoomOnPoint( const Point3d& ptWin, double dCoeff)
|
||||
bool
|
||||
Scene::ZoomWin( const Point3d& ptWin1, const Point3d& ptWin2)
|
||||
{
|
||||
// leggo Z del pixel
|
||||
double dWinZ ;
|
||||
GetPixelZ( Media( ptWin1, ptWin2), dWinZ) ;
|
||||
|
||||
// porto i punti in coordinate mondo
|
||||
Point3d ptWorld1 ;
|
||||
if ( ! UnProject( Point3d( ptWin1.x, ptWin1.y, GetProjectedCenter().z), ptWorld1))
|
||||
if ( ! UnProject( Point3d( ptWin1.x, ptWin1.y, dWinZ), ptWorld1))
|
||||
return false ;
|
||||
Point3d ptWorld2 ;
|
||||
if ( ! UnProject( Point3d( ptWin2.x, ptWin2.y, GetProjectedCenter().z), ptWorld2))
|
||||
if ( ! UnProject( Point3d( ptWin2.x, ptWin2.y, dWinZ), ptWorld2))
|
||||
return false ;
|
||||
|
||||
// recupero il riferimento della camera (vista)
|
||||
@@ -441,7 +606,18 @@ Scene::ZoomWin( const Point3d& ptWin1, const Point3d& ptWin2)
|
||||
double dHalfHeight = 0.5 * abs( ptView1.y - ptView2.y) ;
|
||||
|
||||
// adatto le dimensioni a quelle della vista
|
||||
return AdjustDimView( dHalfWidth, dHalfHeight) ;
|
||||
if ( ! AdjustDimView( dHalfWidth, dHalfHeight))
|
||||
return false ;
|
||||
|
||||
// per il dolly va modificata la distanza della camera
|
||||
if ( ! m_bOrthographic && m_nPerspZoomType == ZT_DOLLY) {
|
||||
m_dDistCamera = m_dHalfHeight / tan( PERSPECTIVE_STD_FOV * 0.5 * DEGTORAD) ;
|
||||
CalcDistCamera() ;
|
||||
}
|
||||
else
|
||||
m_bDistOk = true ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
+134
-68
@@ -64,6 +64,14 @@ Scene::SetMark( Color colMark)
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::SetMark2( Color colMark)
|
||||
{
|
||||
m_colMark2 = colMark ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::SetSelSurf( Color colSelSurf)
|
||||
@@ -135,7 +143,7 @@ Scene::DrawGroup( const IGdbIterator& iIter, int nPass, const MdStMkCol& cParent
|
||||
Frame3d frFrame ;
|
||||
if ( ! iIter.GetGroupFrame( frFrame))
|
||||
return false ;
|
||||
// se non è identità, lo aggiungo sullo stack delle matrici MODELVIEW di OpenGL
|
||||
// se non è identità, lo aggiungo sullo stack delle matrici MODELVIEW di OpenGL
|
||||
bool bMatrix = ( frFrame.GetType() != Frame3d::TOP || ! frFrame.Orig().IsSmall()) ;
|
||||
if ( bMatrix) {
|
||||
glPushMatrix() ;
|
||||
@@ -166,7 +174,7 @@ Scene::DrawGroup( const IGdbIterator& iIter, int nPass, const MdStMkCol& cParent
|
||||
// recupero e aggiorno il colore dell'oggetto
|
||||
Color colObj = cParent.colObj ;
|
||||
pIter->GetMaterial( colObj) ;
|
||||
// se in modalità selezione, verifico sia selezionabile
|
||||
// se in modalità selezione, verifico sia selezionabile
|
||||
bool bSel = true ;
|
||||
if ( m_bSelect && UnselectableFind( pIter->GetId()))
|
||||
bSel = false ;
|
||||
@@ -220,6 +228,10 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
// recupero eventuale parte custom
|
||||
const IUserObj* pUserObj = iIter.GetUserObj() ;
|
||||
|
||||
// numero di colori per TriMesh e Zmap
|
||||
const int STM_COL = 2 ;
|
||||
const int ZMAP_COL = 2 ;
|
||||
|
||||
// se non esiste grafica associata, la creo
|
||||
if ( pGeoObj->GetObjGraphics() == nullptr) {
|
||||
// oggetto grafico molteplice solo per Zmap o superfici che lo richiedono
|
||||
@@ -228,17 +240,25 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
const IVolZmap* pZmap = GetVolZmap( pGeoObj) ;
|
||||
if ( pZmap != nullptr) {
|
||||
if ( ( m_nShowZmap & ZSM_SURF) != 0)
|
||||
nCount += 2 * pZmap->GetBlockCount() ;
|
||||
nCount += ZMAP_COL * pZmap->GetBlockCount() ;
|
||||
if ( ( m_nShowZmap & ZSM_LINES) != 0 || ( m_nShowZmap & ZSM_NORMALS) != 0)
|
||||
nCount += 1 ;
|
||||
if ( pZmap->GetShowEdges())
|
||||
nCount += 1 ;
|
||||
}
|
||||
}
|
||||
else if (( nGeoType & GEO_SURF) != 0) {
|
||||
const ISurfTriMesh* pSTM = GetSurfTriMeshAux( pGeoObj) ;
|
||||
if ( pSTM != nullptr && pSTM->GetMaxTFlag() > 0)
|
||||
nCount = 2 ;
|
||||
if ( pSTM != nullptr) {
|
||||
if ( pSTM->GetMaxTFlag() > 0)
|
||||
nCount = STM_COL ;
|
||||
else
|
||||
nCount = 1 ;
|
||||
if ( pSTM->GetShowEdges())
|
||||
nCount += 1 ;
|
||||
}
|
||||
}
|
||||
// nuova modalità grafica solo per superfici e testi con molti triangoli o solidi Zmap
|
||||
// nuova modalità grafica solo per superfici e testi con molti triangoli o solidi Zmap
|
||||
const int N_MIN_TRIA_NEWWAY = 100 ;
|
||||
bool bNewWay = false ;
|
||||
if ( m_bNewWay) {
|
||||
@@ -263,7 +283,7 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
pGeoObj->SetObjGraphics( pGraphics) ;
|
||||
}
|
||||
|
||||
// se la grafica associata non è valida la ricalcolo
|
||||
// se la grafica associata non è valida la ricalcolo
|
||||
ObjEGrGraphics* pGraphics = GetObjEGrGraphics( pGeoObj) ;
|
||||
if ( ! pGraphics->IsValid()) {
|
||||
const double ANG_TOL_GRAPH_DEG = 15 ;
|
||||
@@ -366,11 +386,14 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
if ( pSTM == nullptr)
|
||||
return false ;
|
||||
// superficie con visualizzazione standard
|
||||
if ( pSTM->GetMaxTFlag() == 0) {
|
||||
bool bTwoColors = ( pSTM->GetMaxTFlag() > 0) ;
|
||||
if ( ! bTwoColors) {
|
||||
// recupero il materiale
|
||||
Material mMat ;
|
||||
if ( ! iIter.GetCalcMaterial( mMat))
|
||||
mMat.Set( m_colDef) ;
|
||||
// Imposto indice blocco corrente
|
||||
pGraphics->SetCurrent( 0) ;
|
||||
// pulisco
|
||||
pGraphics->Clear() ;
|
||||
// se ci sono triangoli
|
||||
@@ -396,11 +419,11 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
}
|
||||
pGraphics->EndTriangles() ;
|
||||
}
|
||||
else
|
||||
pGraphics->Validate() ;
|
||||
}
|
||||
// altrimenti superficie con due colori
|
||||
else {
|
||||
// numero di colori
|
||||
const int STM_COL = 2 ;
|
||||
// definizione materiali
|
||||
Material mMat[STM_COL] ;
|
||||
Color cCol[STM_COL] ;
|
||||
@@ -408,7 +431,7 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
cCol[0] = siObj.colObj ;
|
||||
if ( ! iIter.GetCalcMaterial( mMat[0]))
|
||||
mMat[0].Set( m_colDef) ;
|
||||
// secondo materiale per parti modificate (tonalità spostata di +22.5 deg)
|
||||
// secondo materiale per parti modificate (tonalità spostata di +22.5 deg)
|
||||
cCol[1] = cCol[0] ;
|
||||
mMat[1] = mMat[0] ;
|
||||
HSV hsv = GetHSVFromColor( siObj.colObj) ;
|
||||
@@ -425,12 +448,13 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
// Ciclo sui colori
|
||||
for ( int j = 0 ; j < STM_COL ; ++ j) {
|
||||
// Imposto indice blocco corrente
|
||||
pGraphics->SetCurrent( j) ;
|
||||
// lo pulisco
|
||||
pGraphics->Clear() ;
|
||||
if ( pGraphics->SetCurrent( j))
|
||||
pGraphics->Clear() ;
|
||||
// se non ci sono triangoli, passo oltre
|
||||
if ( nTri[j] == 0)
|
||||
if ( nTri[j] == 0) {
|
||||
pGraphics->Validate() ;
|
||||
continue ;
|
||||
}
|
||||
// assegno materiali
|
||||
pGraphics->AddColor( cCol[j]) ; // per wireframe
|
||||
pGraphics->AddMaterial( mMat[j].GetAmbient(), mMat[j].GetDiffuse(),
|
||||
@@ -454,6 +478,28 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
pGraphics->EndTriangles() ;
|
||||
}
|
||||
}
|
||||
// eventuali spigoli vivi
|
||||
if ( pSTM->GetShowEdges()) {
|
||||
if ( pGraphics->SetCurrent( bTwoColors ? 2 : 1))
|
||||
pGraphics->Clear() ;
|
||||
int nEdgCnt = pSTM->GetEdgeCount() ;
|
||||
if ( nEdgCnt > 0) {
|
||||
pGraphics->AddColor( DGRAY) ;
|
||||
pGraphics->AddMaterial( DGRAY, DGRAY, DGRAY, 10) ;
|
||||
pGraphics->AddBackMaterial( DGRAY) ;
|
||||
PNTVECTOR vPnt ; vPnt.reserve( 2 * nEdgCnt) ;
|
||||
for ( int i = 0 ; i < nEdgCnt ; ++i) {
|
||||
Point3d ptP1, ptP2 ;
|
||||
double dAng ;
|
||||
if ( pSTM->GetEdge( i, ptP1, ptP2, dAng) &&
|
||||
abs( dAng) > pSTM->GetSmoothAngle()) {
|
||||
vPnt.emplace_back( ptP1) ;
|
||||
vPnt.emplace_back( ptP2) ;
|
||||
}
|
||||
}
|
||||
pGraphics->AddLines( vPnt, false, true) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
// se Zmap
|
||||
else if ( nGeoType == VOL_ZMAP) {
|
||||
@@ -463,8 +509,6 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
return false ;
|
||||
// numero di blocchi
|
||||
int nCount = 0 ;
|
||||
// numero di colori
|
||||
const int ZMAP_COL = 2 ;
|
||||
// indicazione se tridexel
|
||||
bool bIsTriDexel = pZmap->IsTriDexel() ;
|
||||
// se triangoli da disegnare
|
||||
@@ -476,9 +520,9 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
cCol[0] = siObj.colObj ;
|
||||
if ( ! iIter.GetCalcMaterial( mMat[0]))
|
||||
mMat[0].Set( m_colDef) ;
|
||||
// secondo materiale per parti lavorate (tonalità spostata di +22.5 deg)
|
||||
// secondo materiale per parti lavorate (tonalità spostata di +22.5 deg)
|
||||
cCol[1] = cCol[0] ;
|
||||
mMat[1] = mMat[0] ;
|
||||
mMat[1] = mMat[0] ;
|
||||
// se richiesto diverso
|
||||
if ( ( m_nShowZmap & ZSM_COLORS) != 0) {
|
||||
HSV hsv = GetHSVFromColor( siObj.colObj) ;
|
||||
@@ -492,9 +536,9 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
// Ciclo sui blocchi
|
||||
nCount = pZmap->GetBlockCount() ;
|
||||
for ( int i = 0 ; i < nCount ; ++ i) {
|
||||
// Se blocco già aggiornato, vado oltre
|
||||
pGraphics->SetCurrent( ZMAP_COL * i) ;
|
||||
if ( pZmap->GetBlockUpdatingCounter( i) <= pGraphics->GetCounter())
|
||||
// Se blocco non esistente o già aggiornato, vado oltre
|
||||
if ( ! pGraphics->SetCurrent( ZMAP_COL * i) ||
|
||||
pZmap->GetBlockUpdatingCounter( i) <= pGraphics->GetCounter())
|
||||
continue ;
|
||||
// Recupero i triangoli del blocco
|
||||
TRIA3DEXVECTOR vTria ;
|
||||
@@ -509,8 +553,9 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
}
|
||||
// Ciclo sui colori
|
||||
for ( int j = 0 ; j < ZMAP_COL ; ++ j) {
|
||||
// Imposto indice blocco corrente
|
||||
pGraphics->SetCurrent( ZMAP_COL * i + j) ;
|
||||
// Imposto indice blocco corrente, se non esiste passo oltre
|
||||
if ( ! pGraphics->SetCurrent( ZMAP_COL * i + j))
|
||||
continue ;
|
||||
// lo pulisco
|
||||
pGraphics->Clear() ;
|
||||
// se non ci sono triangoli, passo oltre
|
||||
@@ -538,46 +583,68 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
}
|
||||
}
|
||||
// visualizzazione spilloni e normali (sempre nell'ultimo blocco)
|
||||
if ( ( m_nShowZmap & ZSM_LINES) != 0 || ( m_nShowZmap & ZSM_NORMALS) != 0) {
|
||||
bool bLinNrmShow = ( ( m_nShowZmap & ZSM_LINES) != 0 || ( m_nShowZmap & ZSM_NORMALS) != 0) ;
|
||||
if ( bLinNrmShow) {
|
||||
// imposto indice blocco corrente
|
||||
pGraphics->SetCurrent( ZMAP_COL * nCount) ;
|
||||
// lo pulisco
|
||||
pGraphics->Clear() ;
|
||||
// ciclo sui tre gruppi di spilloni
|
||||
int nKmin = ( m_nShowZmap & ZSM_LINES) != 0 ? 0 : 3 ;
|
||||
int nKmax = ( m_nShowZmap & ZSM_NORMALS) != 0 ? 6 : 3 ;
|
||||
Color vCol[6] = {BLUE, RED, GREEN, BLUE, RED, GREEN} ;
|
||||
for ( int k = nKmin ; k < nKmax ; ++ k) {
|
||||
pGraphics->AddColor( vCol[k]) ;
|
||||
pGraphics->AddMaterial( vCol[k], vCol[k], vCol[k], 10) ;
|
||||
pGraphics->AddBackMaterial( vCol[k]) ;
|
||||
PNTVECTOR vPnt ;
|
||||
for ( int i = 0 ; ; ++ i) {
|
||||
bool bOutBreak = false ;
|
||||
for ( int j = 0 ; ; ++ j) {
|
||||
POLYLINELIST lstPL ;
|
||||
if ( pZmap->GetDexelLines( k, j, i, lstPL)) {
|
||||
for ( const auto& PL : lstPL) {
|
||||
Point3d ptS, ptE ;
|
||||
bool Found = PL.GetFirstLine( ptS, ptE) ;
|
||||
while ( Found) {
|
||||
vPnt.emplace_back( ptS) ;
|
||||
vPnt.emplace_back( ptE) ;
|
||||
Found = PL.GetNextLine( ptS, ptE) ;
|
||||
if ( pGraphics->SetCurrent( ZMAP_COL * nCount)) {
|
||||
// lo pulisco
|
||||
pGraphics->Clear() ;
|
||||
// ciclo sui tre gruppi di spilloni
|
||||
int nKmin = ( m_nShowZmap & ZSM_LINES) != 0 ? 0 : 3 ;
|
||||
int nKmax = ( m_nShowZmap & ZSM_NORMALS) != 0 ? 6 : 3 ;
|
||||
Color vCol[6] = {BLUE, RED, GREEN, BLUE, RED, GREEN} ;
|
||||
for ( int k = nKmin ; k < nKmax ; ++ k) {
|
||||
pGraphics->AddColor( vCol[k]) ;
|
||||
pGraphics->AddMaterial( vCol[k], vCol[k], vCol[k], 10) ;
|
||||
pGraphics->AddBackMaterial( vCol[k]) ;
|
||||
PNTVECTOR vPnt ;
|
||||
for ( int i = 0 ; ; ++ i) {
|
||||
bool bOutBreak = false ;
|
||||
for ( int j = 0 ; ; ++ j) {
|
||||
POLYLINELIST lstPL ;
|
||||
if ( pZmap->GetDexelLines( k, j, i, lstPL)) {
|
||||
for ( const auto& PL : lstPL) {
|
||||
Point3d ptS, ptE ;
|
||||
bool Found = PL.GetFirstLine( ptS, ptE) ;
|
||||
while ( Found) {
|
||||
vPnt.emplace_back( ptS) ;
|
||||
vPnt.emplace_back( ptE) ;
|
||||
Found = PL.GetNextLine( ptS, ptE) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( j == 0)
|
||||
bOutBreak = true ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
if ( bOutBreak)
|
||||
break ;
|
||||
else {
|
||||
if ( j == 0)
|
||||
bOutBreak = true ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
if ( bOutBreak)
|
||||
break ;
|
||||
}
|
||||
if ( vPnt.size() > 0)
|
||||
pGraphics->AddLines( vPnt) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
// eventuali spigoli vivi
|
||||
if ( pZmap->GetShowEdges()) {
|
||||
// imposto indice blocco corrente
|
||||
if ( pGraphics->SetCurrent( ZMAP_COL * nCount + ( bLinNrmShow ? 1 : 0))) {
|
||||
// lo pulisco
|
||||
pGraphics->Clear() ;
|
||||
// inserisco le curve
|
||||
ICURVEPOVECTOR vpCurve ;
|
||||
if ( pZmap->GetEdges( vpCurve) && ! vpCurve.empty()) {
|
||||
pGraphics->AddColor( DGRAY) ;
|
||||
pGraphics->AddMaterial( DGRAY, DGRAY, DGRAY, 10) ;
|
||||
pGraphics->AddBackMaterial( DGRAY) ;
|
||||
for ( const auto& pCrv : vpCurve) {
|
||||
PolyLine PL ;
|
||||
if ( pCrv->ApproxWithLines( 10 * EPS_SMALL, ANG_TOL_GRAPH_DEG, ICurve::APL_SPECIAL, PL))
|
||||
pGraphics->AddPolyLine( PL, false, true) ;
|
||||
}
|
||||
}
|
||||
if ( vPnt.size() > 0)
|
||||
pGraphics->AddLines( vPnt) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -662,7 +729,7 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
bool bSurf = (( nGeoType & ( GEO_SURF | GEO_VOLUME)) != 0) ;
|
||||
bool bGenSurf = ( bSurf || ( nGeoType == EXT_TEXT && m_nShowText == TXT_FILL && GetExtText( pGeoObj)->GetAuxSurf() != nullptr)) ;
|
||||
|
||||
// recupero il valore di opacità (solo per le superfici e i solidi può esserci trasparenza)
|
||||
// recupero il valore di opacità (solo per le superfici e i solidi può esserci trasparenza)
|
||||
int nAlpha = siObj.colObj.GetIntAlpha() ;
|
||||
|
||||
// salto in ogni caso le superfici e i solidi completamente trasparenti
|
||||
@@ -676,7 +743,7 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
|
||||
return true ;
|
||||
}
|
||||
|
||||
// se shading e non modalità selezione
|
||||
// se shading e non modalità selezione
|
||||
bool bSurfSha = false ;
|
||||
if ( m_nShowMode == SM_SHADING && ! m_bSelect) {
|
||||
// in prima passata disegno solo le superfici opache e metto in un vettore quelle semitrasparenti
|
||||
@@ -774,6 +841,7 @@ Scene::DrawAlphaSurfVector( void)
|
||||
[]( const AlphaSurf& a, const AlphaSurf&b) { return a.dZmax < b.dZmax ; }) ;
|
||||
|
||||
// eseguo visualizzazione
|
||||
bool bOk = true ;
|
||||
for ( const auto& AlphaSurf : m_vAlphaSurf) {
|
||||
// imposto matrice MODELVIEW
|
||||
double Matrix[OGLMAT_DIM] ;
|
||||
@@ -781,15 +849,13 @@ Scene::DrawAlphaSurfVector( void)
|
||||
glPushMatrix() ;
|
||||
glLoadMatrixd( Matrix) ;
|
||||
// eseguo visualizzazione
|
||||
bool bOk = AlphaSurf.pGraph->Draw( AlphaSurf.nStat, AlphaSurf.nMark, true,
|
||||
AlphaSurf.bSurf, AlphaSurf.nAlpha, AlphaSurf.bShowAux) ;
|
||||
if ( ! AlphaSurf.pGraph->Draw( AlphaSurf.nStat, AlphaSurf.nMark, true,
|
||||
AlphaSurf.bSurf, AlphaSurf.nAlpha, AlphaSurf.bShowAux))
|
||||
bOk = false ;
|
||||
// ripristino matrice
|
||||
glPopMatrix() ;
|
||||
// in caso di errore, esco
|
||||
if ( ! bOk)
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
return bOk ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,770 +0,0 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2022
|
||||
//----------------------------------------------------------------------------
|
||||
// File : SceneGlobCube.cpp Data : 10.10.22 Versione : 1
|
||||
// Contenuto : Implementazione gestione e disegno Cubetto per viste.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 11.10.22 DS Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "Scene.h"
|
||||
#include "EGrUtils.h"
|
||||
#include "ObjOldGraphics.h"
|
||||
#include "ObjNewGraphics.h"
|
||||
#include "ObjMultiGraphics.h"
|
||||
#include "/EgtDev/Include/EGkSurfTriMesh.h"
|
||||
#include "/EgtDev/Include/EGkSfrCreate.h"
|
||||
#include "/EgtDev/Include/EGkGeomDB.h"
|
||||
#include "/EgtDev/Include/EGkObjGraphics.h"
|
||||
|
||||
|
||||
using namespace std ;
|
||||
|
||||
// posizione X e Y dello schermo
|
||||
const double MIN_EDGE_SIZE = 20 ;
|
||||
const double MAX_EDGE_SIZE = 200.0 ;
|
||||
|
||||
// colore render dei bordi delle superifici del cubo
|
||||
const Color CUBE_LINES( 0, 0, 0, 1) ;
|
||||
|
||||
// angolo di tolleranza per rotazioni con vettori quasi paralleli
|
||||
const double ANG_ROT_TOLL = 5 ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::CreateFlatPart( ISurfTriMesh* pSrf)
|
||||
{
|
||||
|
||||
// vertici
|
||||
pSrf->AddVertex( Point3d( 0.33 * m_dCubeEdge, 0.33 * m_dCubeEdge, 0)),
|
||||
pSrf->AddVertex( Point3d( - 0.33 * m_dCubeEdge, 0.33 * m_dCubeEdge, 0)) ;
|
||||
pSrf->AddVertex( Point3d( - 0.33 * m_dCubeEdge, - 0.33 * m_dCubeEdge, 0)) ;
|
||||
pSrf->AddVertex( Point3d( 0.33 * m_dCubeEdge, - 0.33 * m_dCubeEdge, 0)) ;
|
||||
|
||||
// triangoli
|
||||
int nNewInd_0[3] = { 0, 1, 2} ;
|
||||
pSrf->AddTriangle( nNewInd_0) ;
|
||||
int nNewInd_1[3] = { 0, 2, 3} ;
|
||||
pSrf->AddTriangle( nNewInd_1) ;
|
||||
|
||||
// verifico
|
||||
pSrf->DoCompacting() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::CreateEdgePart( ISurfTriMesh* pSrf)
|
||||
{
|
||||
// vertici
|
||||
pSrf->AddVertex( Point3d( 0.33 * m_dCubeEdge, - 0.085 * m_dCubeEdge, 0)) ;
|
||||
pSrf->AddVertex( Point3d( - 0.33 * m_dCubeEdge, - 0.085 * m_dCubeEdge, 0)) ;
|
||||
pSrf->AddVertex( Point3d( - 0.33 * m_dCubeEdge, 0, - 0.085 * m_dCubeEdge)) ;
|
||||
pSrf->AddVertex( Point3d( 0.33 * m_dCubeEdge, 0, - 0.085 * m_dCubeEdge)) ;
|
||||
pSrf->AddVertex( Point3d( - 0.33 * m_dCubeEdge, 0.085 * m_dCubeEdge, - 0.17 * m_dCubeEdge)) ;
|
||||
pSrf->AddVertex( Point3d( 0.33 * m_dCubeEdge, 0.085 * m_dCubeEdge, - 0.17 * m_dCubeEdge)) ;
|
||||
|
||||
// triangoli
|
||||
int nNewInd_0[3] = { 2, 1 ,0} ;
|
||||
pSrf->AddTriangle( nNewInd_0) ;
|
||||
int nNewInd_1[3] = { 3, 2, 0} ;
|
||||
pSrf->AddTriangle( nNewInd_1) ;
|
||||
int nNewInd_2[3] = { 2, 5, 4} ;
|
||||
pSrf->AddTriangle( nNewInd_2) ;
|
||||
int nNewInd_3[3] = { 2, 3, 5} ;
|
||||
pSrf->AddTriangle( nNewInd_3) ;
|
||||
|
||||
// verifico
|
||||
pSrf->DoCompacting() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::CreateCornerPart( ISurfTriMesh* pSrf)
|
||||
{
|
||||
// vertici
|
||||
pSrf->AddVertex( Point3d( - 0.085 * m_dCubeEdge, 0.085 * m_dCubeEdge, -0.17 * m_dCubeEdge)) ;
|
||||
pSrf->AddVertex( Point3d( - 0.085 * m_dCubeEdge, - 0.085 * m_dCubeEdge, 0)) ;
|
||||
pSrf->AddVertex( Point3d( 0.085 * m_dCubeEdge, - 0.085 * m_dCubeEdge, - 0.17 * m_dCubeEdge)) ;
|
||||
|
||||
// triangoli
|
||||
int nNewInd_0[3] = { 0, 1, 2} ;
|
||||
pSrf->AddTriangle( nNewInd_0) ;
|
||||
|
||||
// verifico
|
||||
pSrf->DoCompacting() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static ObjEGrGraphics*
|
||||
CreateObjEGrGraphics( int nCount, bool bNewWay)
|
||||
{
|
||||
if ( nCount > 1)
|
||||
return ( new( nothrow) ObjMultiGraphics( nCount, bNewWay)) ;
|
||||
else if ( bNewWay)
|
||||
return ( new( nothrow) ObjNewGraphics) ;
|
||||
else
|
||||
return ( new( nothrow) ObjOldGraphics) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::DrawCube( bool bSurf)
|
||||
{
|
||||
|
||||
// recupero la matrice viewport
|
||||
GLint Viewport[4] ;
|
||||
glGetIntegerv( GL_VIEWPORT, Viewport) ;
|
||||
|
||||
// se il vettore delle superifici č vuoto, allora lo creo
|
||||
if ( m_vStm_Cube.empty()) {
|
||||
// Z+ -> 1 -> TOP
|
||||
PtrOwner<ISurfTriMesh> pStm_Zp( CreateSurfTriMesh()) ;
|
||||
CreateFlatPart( pStm_Zp) ;
|
||||
pStm_Zp->Translate( Vector3d( 0, 0, 0.5 * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_Zp)) ;
|
||||
|
||||
// Z- -> 2 -> BOTTOM
|
||||
PtrOwner<ISurfTriMesh> pStm_Zm( CreateSurfTriMesh()) ;
|
||||
CreateFlatPart( pStm_Zm) ;
|
||||
pStm_Zm->Rotate( ORIG, Y_AX, 180) ;
|
||||
pStm_Zm->Translate( Vector3d( 0, 0, - 0.5 * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_Zm)) ;
|
||||
|
||||
// X+ -> 3 -> RIGHT
|
||||
PtrOwner<ISurfTriMesh> pStm_Xp( CreateSurfTriMesh()) ;
|
||||
CreateFlatPart( pStm_Xp) ;
|
||||
pStm_Xp->Rotate( ORIG, Y_AX, 180) ;
|
||||
pStm_Xp->Rotate( ORIG, -Y_AX, 90) ;
|
||||
pStm_Xp->Translate( Vector3d( 0.5 * m_dCubeEdge, 0, 0)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_Xp)) ;
|
||||
|
||||
// X- -> 4 -> LEFT
|
||||
PtrOwner<ISurfTriMesh> pStm_Xm( CreateSurfTriMesh()) ;
|
||||
CreateFlatPart( pStm_Xm) ;
|
||||
pStm_Xm->Rotate( ORIG, -Y_AX, 90) ;
|
||||
pStm_Xm->Translate( Vector3d( -0.5 * m_dCubeEdge, 0, 0)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_Xm)) ;
|
||||
|
||||
// Y+ -> 5 -> FRONT
|
||||
PtrOwner<ISurfTriMesh> pStm_Yp( CreateSurfTriMesh()) ;
|
||||
CreateFlatPart( pStm_Yp) ;
|
||||
pStm_Yp->Rotate( ORIG, -X_AX, 90) ;
|
||||
pStm_Yp->Translate( Vector3d( 0, 0.5 * m_dCubeEdge, 0)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_Yp)) ;
|
||||
|
||||
// Y- -> 6 -> BACK
|
||||
PtrOwner<ISurfTriMesh> pStm_Ym( CreateSurfTriMesh()) ;
|
||||
CreateFlatPart( pStm_Ym) ;
|
||||
pStm_Ym->Rotate( ORIG, Y_AX, 180) ;
|
||||
pStm_Ym->Rotate( ORIG, -X_AX, 90) ;
|
||||
pStm_Ym->Translate( Vector3d( 0, -0.5 * m_dCubeEdge, 0)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_Ym)) ;
|
||||
|
||||
// Z+X+ -> 7 -> TOP-RIGHT
|
||||
PtrOwner<ISurfTriMesh> pStm_ZpXp( CreateSurfTriMesh()) ;
|
||||
CreateEdgePart( pStm_ZpXp) ;
|
||||
pStm_ZpXp->Rotate( ORIG, -Z_AX, 90) ;
|
||||
pStm_ZpXp->Translate( Vector3d(( 0.5 - 0.085) * m_dCubeEdge , 0, 0.5 * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_ZpXp)) ;
|
||||
|
||||
// Z+X- -> 8 -> TOP-LEFT
|
||||
PtrOwner<ISurfTriMesh> pStm_ZpXm( CreateSurfTriMesh()) ;
|
||||
CreateEdgePart( pStm_ZpXm) ;
|
||||
pStm_ZpXm->Rotate( ORIG, Z_AX, 90) ;
|
||||
pStm_ZpXm->Translate( Vector3d(( - 0.5 + 0.085) * m_dCubeEdge, 0, 0.5 * m_dCubeEdge));
|
||||
m_vStm_Cube.emplace_back( Release( pStm_ZpXm)) ;
|
||||
|
||||
// Z-X+ -> 9 -> BOTTOM-RIGHT
|
||||
PtrOwner<ISurfTriMesh> pStm_ZmXp( CreateSurfTriMesh()) ;
|
||||
CreateEdgePart( pStm_ZmXp) ;
|
||||
pStm_ZmXp->Rotate( ORIG, -Z_AX, 90) ;
|
||||
pStm_ZmXp->Rotate( ORIG, Y_AX, 90) ;
|
||||
pStm_ZmXp->Translate( Vector3d( 0.5 * m_dCubeEdge, 0,( - 0.5 + 0.085) * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_ZmXp)) ;
|
||||
|
||||
// Z-X- -> 10 -> BOTTOM-LEFT
|
||||
PtrOwner<ISurfTriMesh> pStm_ZmXm( CreateSurfTriMesh()) ;
|
||||
CreateEdgePart( pStm_ZmXm) ;
|
||||
pStm_ZmXm->Rotate( ORIG, Z_AX, 90) ;
|
||||
pStm_ZmXm->Rotate( ORIG, -Y_AX, 90) ;
|
||||
pStm_ZmXm->Translate( Vector3d( - 0.5 * m_dCubeEdge, 0, ( - 0.5 + 0.085) * m_dCubeEdge)) ;;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_ZmXm)) ;
|
||||
|
||||
// Z+Y+ -> 11 -> TOP-FRONT
|
||||
PtrOwner<ISurfTriMesh> pStm_ZpYp( CreateSurfTriMesh()) ;
|
||||
CreateEdgePart( pStm_ZpYp) ;
|
||||
pStm_ZpYp->Translate( Vector3d( 0, ( 0.5 - 0.085) * m_dCubeEdge, 0.5 * m_dCubeEdge)) ;
|
||||
pStm_ZpYp->SetTempProp( 5, 0) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_ZpYp)) ;
|
||||
|
||||
// Z+Y- -> 12 -> TOP-BACK
|
||||
PtrOwner<ISurfTriMesh> pStm_ZpYm( CreateSurfTriMesh()) ;
|
||||
CreateEdgePart( pStm_ZpYm) ;
|
||||
pStm_ZpYm->Rotate( ORIG, -Z_AX, 180) ;
|
||||
pStm_ZpYm->Translate( Vector3d( 0, ( - 0.5 + 0.085) * m_dCubeEdge, 0.5 * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_ZpYm)) ;
|
||||
|
||||
// Z-Y+ -> 13 -> BOTTOM-FRONT
|
||||
PtrOwner<ISurfTriMesh> pStm_ZmYp( CreateSurfTriMesh()) ;
|
||||
CreateEdgePart( pStm_ZmYp) ;
|
||||
pStm_ZmYp->Rotate( ORIG, -X_AX, 90) ;
|
||||
pStm_ZmYp->Translate( Vector3d( 0, ( 0.5) * m_dCubeEdge ,
|
||||
( - 0.5 + 0.085) * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_ZmYp)) ;
|
||||
|
||||
// Z-Y- -> 14 -> BOTTOM-BACK
|
||||
PtrOwner<ISurfTriMesh> pStm_ZmYm( CreateSurfTriMesh()) ;
|
||||
CreateEdgePart( pStm_ZmYm) ;
|
||||
pStm_ZmYm->Rotate( ORIG, -Z_AX, 180) ;
|
||||
pStm_ZmYm->Rotate( ORIG, X_AX, 90) ;
|
||||
pStm_ZmYm->Translate( Vector3d( 0, - 0.5 * m_dCubeEdge, ( - 0.5 + 0.085) * m_dCubeEdge )) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_ZmYm)) ;
|
||||
|
||||
// X+Y+ -> 15 -> RIGHT-FRONT
|
||||
PtrOwner<ISurfTriMesh> pStm_XpYp( CreateSurfTriMesh()) ;
|
||||
CreateEdgePart( pStm_XpYp) ;
|
||||
pStm_XpYp->Rotate( ORIG, Y_AX, 90) ;
|
||||
pStm_XpYp->Translate( Vector3d( 0.5 * m_dCubeEdge,( 0.5 - 0.085) * m_dCubeEdge, 0)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_XpYp)) ;
|
||||
|
||||
// X-Y+ -> 16 -> LEFT-FRONT
|
||||
PtrOwner<ISurfTriMesh> pStm_XmYp( CreateSurfTriMesh()) ;
|
||||
CreateEdgePart( pStm_XmYp) ;
|
||||
pStm_XmYp->Rotate( ORIG, -Y_AX, 90) ;
|
||||
pStm_XmYp->Translate( Vector3d( - 0.5 * m_dCubeEdge, ( 0.5 - 0.085) * m_dCubeEdge, 0)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_XmYp)) ;
|
||||
|
||||
// X+Y- -> 17 -> RIGHT-BACK
|
||||
PtrOwner<ISurfTriMesh> pStm_XpYm( CreateSurfTriMesh()) ;
|
||||
CreateEdgePart( pStm_XpYm) ;
|
||||
pStm_XpYm->Rotate( ORIG, -Y_AX, 90) ;
|
||||
pStm_XpYm->Rotate( ORIG, Z_AX, 180) ;
|
||||
pStm_XpYm->Translate( Vector3d( 0.5 * m_dCubeEdge, ( - 0.5 + 0.085) * m_dCubeEdge , 0)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_XpYm)) ;
|
||||
|
||||
// X-Y- -> 18 -> LEFT-BACK
|
||||
PtrOwner<ISurfTriMesh> pStm_XmYm( CreateSurfTriMesh()) ;
|
||||
CreateEdgePart( pStm_XmYm) ;
|
||||
pStm_XmYm->Rotate( ORIG, Y_AX, 90) ;
|
||||
pStm_XmYm->Rotate( ORIG, Z_AX, 180) ;
|
||||
pStm_XmYm->Translate( Vector3d( - 0.5 * m_dCubeEdge,- ( 0.5 - 0.085) * m_dCubeEdge, 0)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_XmYm)) ;
|
||||
|
||||
// Z+X+Y+ -> 19 -> TOP-RIGHT-FRONT
|
||||
PtrOwner<ISurfTriMesh> pStm_XpYpZp( CreateSurfTriMesh()) ;
|
||||
CreateCornerPart( pStm_XpYpZp ) ;
|
||||
pStm_XpYpZp->Translate( Vector3d(( 0.5 - 0.085) * m_dCubeEdge, ( 0.5 - 0.085) * m_dCubeEdge, 0.5 * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_XpYpZp)) ;
|
||||
|
||||
// Z+X-Y+ -> 20 -> TOP-LEFT-FRONT
|
||||
PtrOwner<ISurfTriMesh> pStm_XmYpZp( CreateSurfTriMesh()) ;
|
||||
CreateCornerPart( pStm_XmYpZp) ;
|
||||
pStm_XmYpZp->Rotate( ORIG, Z_AX, 90) ;
|
||||
pStm_XmYpZp->Translate( Vector3d(( - 0.5 + 0.085) * m_dCubeEdge,( 0.5 - 0.085) * m_dCubeEdge,0.5 * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_XmYpZp)) ;
|
||||
|
||||
// Z+X+Y- -> 21 -> TOP-RIGHT-BACK
|
||||
PtrOwner<ISurfTriMesh> pStm_XpYmZp( CreateSurfTriMesh()) ;
|
||||
CreateCornerPart( pStm_XpYmZp) ;
|
||||
pStm_XpYmZp->Rotate( ORIG, -Z_AX, 90) ;
|
||||
pStm_XpYmZp->Translate( Vector3d(( + 0.5 - 0.085) * m_dCubeEdge, ( - 0.5 + 0.085) * m_dCubeEdge,0.5 * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_XpYmZp)) ;
|
||||
|
||||
// Z+X-Y- -> 22 -> TOP-LEFT-BACK
|
||||
PtrOwner<ISurfTriMesh> pStm_XmYmZp( CreateSurfTriMesh()) ;
|
||||
CreateCornerPart( pStm_XmYmZp) ;
|
||||
pStm_XmYmZp->Rotate( ORIG, Z_AX, 180) ;
|
||||
pStm_XmYmZp->Translate( Vector3d(( - 0.5 + 0.085) * m_dCubeEdge, ( - 0.5 + 0.085) * m_dCubeEdge, 0.5 * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_XmYmZp)) ;
|
||||
|
||||
// Z-X+Y+ -> 23 -> BOTTOM-RIGHT-FRONT
|
||||
PtrOwner<ISurfTriMesh> pStm_XpYpZm( CreateSurfTriMesh()) ;
|
||||
CreateCornerPart( pStm_XpYpZm) ;
|
||||
pStm_XpYpZm->Rotate( ORIG, X_AX, 180) ;
|
||||
pStm_XpYpZm->Rotate( ORIG, Z_AX, 90) ;
|
||||
pStm_XpYpZm->Translate( Vector3d(( 0.5 - 0.085) * m_dCubeEdge, ( 0.5 - 0.085) * m_dCubeEdge, - 0.5 * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_XpYpZm)) ;
|
||||
|
||||
// Z-X-Y+ -> 24 -> BOTTOM-LEFT-FRONT
|
||||
PtrOwner<ISurfTriMesh> pStm_XmYpZm( CreateSurfTriMesh()) ;
|
||||
CreateCornerPart( pStm_XmYpZm) ;
|
||||
pStm_XmYpZm->Rotate(ORIG, -X_AX, 90) ;
|
||||
pStm_XmYpZm->Rotate( ORIG, Z_AX, 90) ;
|
||||
pStm_XmYpZm->Translate( Vector3d( - 0.5 * m_dCubeEdge, ( 0.5 - 0.085) * m_dCubeEdge,( - 0.5 + 0.085) * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_XmYpZm)) ;
|
||||
|
||||
// Z-X+Y- -> 25 -> BOTTOM-RIGHT-BACK
|
||||
PtrOwner<ISurfTriMesh> pStm_XpYmZm( CreateSurfTriMesh()) ;
|
||||
CreateCornerPart( pStm_XpYmZm) ;
|
||||
pStm_XpYmZm->Rotate( ORIG, X_AX, 180) ;
|
||||
pStm_XpYmZm->Translate( Vector3d(( + 0.5 - 0.085) * m_dCubeEdge, ( - 0.5 + 0.085) * m_dCubeEdge, - 0.5 * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_XpYmZm)) ;
|
||||
|
||||
// Z-X-Y- -> 26 -> BOTTOM-LEFT-BACK
|
||||
PtrOwner<ISurfTriMesh> pStm_XmYmZm( CreateSurfTriMesh()) ;
|
||||
CreateCornerPart( pStm_XmYmZm) ;
|
||||
pStm_XmYmZm->Rotate( ORIG, X_AX, 180) ;
|
||||
pStm_XmYmZm->Rotate( ORIG, -Z_AX, 90) ;
|
||||
pStm_XmYmZm->Translate( Vector3d(( - 0.5 + 0.085) * m_dCubeEdge, ( - 0.5 + 0.085) * m_dCubeEdge, - 0.5 * m_dCubeEdge)) ;
|
||||
m_vStm_Cube.emplace_back( Release( pStm_XmYmZm)) ;
|
||||
}
|
||||
|
||||
// creo un vettore di Graphics, uno per ogni superificie del cubetto
|
||||
vector<PtrOwner<ObjEGrGraphics>> vGraphics ;
|
||||
for ( int i = 0 ; i < 26 ; ++ i) {
|
||||
PtrOwner<ObjEGrGraphics> pNewGraphics( CreateObjEGrGraphics( 0, false)) ;
|
||||
vGraphics.emplace_back( Release( pNewGraphics)) ;
|
||||
vGraphics[i]->SetScene( this) ;
|
||||
}
|
||||
|
||||
// render delle superifici del cubo ( superfici o Linee a seconda del Flag)
|
||||
for ( int s = 0 ; s < 26 ; ++ s) {
|
||||
|
||||
// recupero la superificie corrente del cubo da visualizzare
|
||||
PtrOwner<ISurfTriMesh> pStmCurr( CloneSurfTriMesh( m_vStm_Cube[s])) ;
|
||||
if ( IsNull( pStmCurr))
|
||||
return false ;
|
||||
|
||||
// scalo la superificie a seconda della viewport corrente ( per Zoom)
|
||||
pStmCurr->Scale( GLOB_FRM, ( 2 * m_dHalfWidth) / Viewport[2], ( 2 * m_dHalfWidth) / Viewport[2],
|
||||
( 2 * m_dHalfWidth) / Viewport[2]) ;
|
||||
// sposto la superificie nel sistema di riferimento relativo alla telecamera ( per Pan)
|
||||
pStmCurr->Translate(( m_ptOrigCube - ORIG)) ;
|
||||
|
||||
// definisco colori per i vertici e colore per le linee
|
||||
Color cCol_Vertex ;
|
||||
Color cCol_Line = CUBE_LINES ;
|
||||
|
||||
switch ( s) {
|
||||
case 0 :
|
||||
cCol_Vertex = m_cColZ ; break ;
|
||||
case 1 :
|
||||
cCol_Vertex = m_cColZm ; break ;
|
||||
case 2 :
|
||||
cCol_Vertex = m_cColX ; break ;
|
||||
case 3 :
|
||||
cCol_Vertex = m_cColXm ; break ;
|
||||
case 4 :
|
||||
cCol_Vertex = m_cColY ; break ;
|
||||
case 5 :
|
||||
cCol_Vertex = m_cColYm ; break ;
|
||||
break ;
|
||||
case 6 : case 7 : case 8 : case 9 : case 10 : case 11 :
|
||||
case 12 : case 13 : case 14 : case 15 : case 16 : case 17 :
|
||||
cCol_Vertex = m_cColEdge ; break ;
|
||||
case 18 : case 19 : case 20 : case 21: case 22: case 23 : case 24 : case 25 :
|
||||
cCol_Vertex = m_cColCorner ; break ;
|
||||
default :
|
||||
break ;
|
||||
}
|
||||
vGraphics[s]->AddColor( bSurf ? cCol_Vertex : CUBE_LINES) ;
|
||||
int nTria = pStmCurr->GetTriangleCount() ;
|
||||
vGraphics[s]->StartTriangles( nTria) ;
|
||||
Triangle3dEx Tria ;
|
||||
int nId = pStmCurr->GetFirstTriangle( Tria) ;
|
||||
while ( nId != SVT_NULL) {
|
||||
// edge solo se boundary e normali ai vertici smussate
|
||||
vGraphics[s]->AddTriangle( Tria, Tria.GetTriFlags(), Tria.GetTriNormals()) ;
|
||||
nId = pStmCurr->GetNextTriangle( nId, Tria) ;
|
||||
}
|
||||
vGraphics[s]->EndTriangles() ;
|
||||
// assegno un id temporaneo alla superificie caricata ( modalita wireFrame, come nella Select)
|
||||
if ( ! bSurf)
|
||||
glLoadName( m_nStartFaceId + s + 1) ;
|
||||
vGraphics[s]->Draw( GDB_ST_ON, GDB_MK_OFF, true, true, 80, false) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::DrawGlobCube( bool bSurf)
|
||||
{
|
||||
// se non devo disegnare il cubetto, esco
|
||||
if ( ! m_bShowGlobCube)
|
||||
return true ;
|
||||
|
||||
// recupero il primo Id libero ( e aggiungo 1000)
|
||||
m_nStartFaceId = m_pGeomDB->GetNewId() + 1000 ;
|
||||
|
||||
// recupero la matrice viewport
|
||||
GLint Viewport[4] ;
|
||||
glGetIntegerv( GL_VIEWPORT, Viewport) ;
|
||||
|
||||
// imposto il riferimento
|
||||
glPushMatrix() ;
|
||||
|
||||
// se sono in selezione il cubo lo lascio nella posizione precedente ( cambio di viewport => cambio centro del cubo)
|
||||
Point3d ptOrig ;
|
||||
if ( m_bSelect)
|
||||
ptOrig = m_ptOrigCube ;
|
||||
else {
|
||||
UnProject( Point3d( m_dCubeX, m_dCubeY, 0.25), ptOrig) ; // posizione Z del cubo sempre 0.25 dallo schermo
|
||||
m_ptOrigCube = ptOrig ;
|
||||
}
|
||||
|
||||
// creo il cubo
|
||||
if ( ! DrawCube( bSurf))
|
||||
return true ;
|
||||
|
||||
// tolgo lo stack dei nomi in modalitŕ selezione
|
||||
if ( m_bSelect)
|
||||
glLoadName( 0) ;
|
||||
|
||||
// ripristino lo stack delle matrici
|
||||
glPopMatrix() ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::RotateCameraWithCube()
|
||||
{
|
||||
// controllo se il cubetto č abilitato e ho almeno un Id dalla selezione nel buffer
|
||||
if ( ! m_bShowGlobCube || m_nSelNbr == 0)
|
||||
return false ;
|
||||
|
||||
// controllo che la selezione non sia avvenuta mediante Drag
|
||||
if ( m_nSelW != 13 || m_nSelH != 13)
|
||||
return false ;
|
||||
|
||||
// se ho piů di un elemento trovato, do prioritŕ alla superificie con piů facce
|
||||
int nId = 0 ;
|
||||
int nFace = 1 ;
|
||||
bool bSelStm_Cube = false ;
|
||||
|
||||
for ( int i = 0 ; i < m_nSelNbr ; ++ i) {
|
||||
// recupero l'Id corrente
|
||||
int nCurrId = m_nSelBuff[i].nId ;
|
||||
// controllo che l'Id appartenga ad una superificie del cubetto
|
||||
if ( nCurrId <= m_nStartFaceId || nCurrId > m_nStartFaceId + 26)
|
||||
continue ;
|
||||
|
||||
bSelStm_Cube = true ;
|
||||
int nCurrFace = 1 ;
|
||||
if ( nCurrId - m_nStartFaceId > 6 && nCurrId - m_nStartFaceId <= 18) // se superificie Edge
|
||||
nCurrFace = 2 ;
|
||||
else if ( nCurrId - m_nStartFaceId > 18) // se superificie Corner
|
||||
nCurrFace = 3 ;
|
||||
|
||||
nFace = max( nFace, nCurrFace) ;
|
||||
if ( nFace == 1 || nFace == nCurrFace)
|
||||
nId = nCurrId ;
|
||||
}
|
||||
if ( ! bSelStm_Cube)
|
||||
return false ;
|
||||
|
||||
// ottengo la faccia del cubo selezionato ( valore tra 1 e 26)
|
||||
int nCubeface = nId - m_nStartFaceId ;
|
||||
|
||||
// prendo i parametri della telecamera
|
||||
double dTheta, dPhi, dDist ;
|
||||
GetCamera( &dPhi, &dTheta, &dDist) ;
|
||||
double dPhi_orig = dPhi ;
|
||||
double dTheta_orig = dTheta ;
|
||||
|
||||
// flag per numero di Step fatti e valore forzato di Theta per Z+ e Z-
|
||||
bool bHasTwoStep = false ;
|
||||
double dTheta_Forced = 0.0 ;
|
||||
|
||||
// imposto i nuovi angoli theta e phi mantenendo la distanza
|
||||
if ( GetAngleByCubeFace( nCubeface, dTheta, dPhi)) {
|
||||
// ricavo il vettore iniziale della telecamera
|
||||
Vector3d v_q1 = m_vtDirCamera ;
|
||||
// ricavo il vettore finale della telecamera
|
||||
Vector3d v_q2 = FromSpherical( 1 , dPhi, dTheta) ;
|
||||
// flag per rotazione necessaria o superflua
|
||||
bool bDoRotation = true ;
|
||||
// nuovi angoli nel caso di doppie rotazioni
|
||||
double dTheta_new ; double dPhi_new ;
|
||||
|
||||
// controllo se voglio mettere la vista in Z+ o Z-
|
||||
if ( AreSameOrOppositeVectorApprox( v_q2, Z_AX)) {
|
||||
// controllo se sono giŕ in posizione questa posizione ( Z+ o Z-)
|
||||
if ( AreSameVectorApprox( v_q1, v_q2)) {
|
||||
// se sono giŕ orientato in maniera corretta non faccio nulla, altrimenti...
|
||||
if ( abs( dTheta_orig - ( ANG_RIGHT - ANG_STRAIGHT)) > EPS_ANG_SMALL) {
|
||||
Vector3d v_q1S = FromSpherical( 1, 90, dTheta_orig) ;
|
||||
// ... ruoto la telecamera solo lungo theta
|
||||
RotateCameraWithBlockedAngle( v_q1S, -Y_AX, dDist, true, 1, dTheta_orig, dPhi_orig, dTheta_new, dPhi_new) ;
|
||||
}
|
||||
bDoRotation = false ;
|
||||
}
|
||||
// se non sono in posizione Z+ o Z- e devo andare in una di queste due, allora...
|
||||
else if ( ! (( v_q2.IsZplus() || v_q2.IsZminus()) &&
|
||||
( abs( dTheta_orig - ( ANG_STRAIGHT + ANG_RIGHT)) < EPS_SMALL && v_q1.y < 0))) {
|
||||
// controllo se sono nel caso limite della faccia quasi opposta
|
||||
bool bForceCoeff = false ;
|
||||
if ( abs( dTheta_orig - ( ANG_RIGHT)) < EPS_ANG_SMALL)
|
||||
v_q1.Rotate( Z_AX, 5) ;
|
||||
bHasTwoStep = true ;
|
||||
// ... ruoto la telecamera solo lungo theta
|
||||
RotateCameraWithBlockedAngle( v_q1, - Y_AX, 1, true, 1, dTheta_orig, dPhi_orig, dTheta_new, dPhi_new) ;
|
||||
dTheta_Forced = ANG_RIGHT + ANG_STRAIGHT ;
|
||||
v_q1 = FromSpherical( 1, dPhi_orig, dTheta_Forced) ;
|
||||
}
|
||||
}
|
||||
// controllo se sono in posizione Z+ o Z- e devo sistemare la vista in un'altra posizione
|
||||
else if ( AreSameOrOppositeVectorApprox( v_q1, Z_AX)) {
|
||||
// ho giŕ controllato di non aver v_q1 e v_q2 paralleli...
|
||||
double dTheta_S, dPhi_S , dLenS_ ;
|
||||
v_q2.ToSpherical( &dLenS_, &dPhi_S, &dTheta_S) ;
|
||||
|
||||
if ( abs( dTheta_orig - dTheta_S) > EPS_SMALL) {
|
||||
Vector3d v_q1S = FromSpherical( 1, 90, dTheta_orig) ;
|
||||
|
||||
// controllo nel caso di angoli opposti ( o quasi)
|
||||
bool bForceCoeff = false ;
|
||||
if ( abs( dTheta_S - ANG_RIGHT ) < EPS_ANG_SMALL) {
|
||||
v_q1S.Rotate( Z_AX, dTheta_S - ANG_RIGHT >= 0 ? ANG_ROT_TOLL : -ANG_ROT_TOLL) ;
|
||||
bForceCoeff = true ;
|
||||
}
|
||||
|
||||
// ... ruoto la telecamera solo lungo theta
|
||||
RotateCameraWithBlockedAngle( v_q1S, v_q2, dDist, bForceCoeff ? 2 : 1, 1, dTheta_orig, dPhi_orig,
|
||||
dTheta_new, dPhi_new) ;
|
||||
|
||||
dTheta_Forced = dTheta_new ;
|
||||
v_q1 = FromSpherical( 1, dPhi_orig, dTheta_Forced) ;
|
||||
bHasTwoStep = true ;
|
||||
}
|
||||
else {
|
||||
bHasTwoStep = true ;
|
||||
dTheta_Forced = ANG_RIGHT + ANG_STRAIGHT ;
|
||||
}
|
||||
}
|
||||
// se devo ruotare ... animazione mediante Slerp con parametro u tra 0 e 1
|
||||
if ( bDoRotation)
|
||||
RotateCameraWithBlockedAngle( v_q1, v_q2, dDist, true, bHasTwoStep ? 2 : 0, dTheta_Forced, dPhi_orig,
|
||||
dTheta_new, dPhi_new) ;
|
||||
}
|
||||
|
||||
// refresh finale per sicurezza
|
||||
RedrawWindow() ;
|
||||
// annullo il numero di elementi selezionati
|
||||
m_nSelNbr = 0 ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::RotateCameraWithBlockedAngle( Vector3d vDirS, Vector3d vDirE, double dDist, int nAdaptSpeed,
|
||||
int nBlockedAngle, double dTheta_orig, double dPhi_orig,
|
||||
double& dTheta_new, double& dPhi_new)
|
||||
{
|
||||
// controllo dei parametri
|
||||
if ( vDirS.IsSmall() || vDirE.IsSmall() || dDist < EPS_SMALL)
|
||||
return false ;
|
||||
if ( nBlockedAngle < 0 || nBlockedAngle > 2)
|
||||
nBlockedAngle = 0 ;
|
||||
vDirS.Normalize() ;
|
||||
vDirE.Normalize() ;
|
||||
|
||||
// angolo per interpolazione sferica
|
||||
double dAng = acos( vDirS * vDirE) ;
|
||||
|
||||
// imposto la velocitŕ di rotazione a seconda dell'angolo da percorrere... ( se richisto, altrimenti 1)
|
||||
int nCoeff = 1 ;
|
||||
if (( nAdaptSpeed == 1 && dAng * RADTODEG > ANG_RIGHT * ( 2.0 / 3.0) - 50 * EPS_ANG_SMALL) || nAdaptSpeed == 2)
|
||||
nCoeff = 2 ;
|
||||
double dThetaSs, dPhiSs, dLenSs, dThetaEs, dPhiEs, dLenEs ;
|
||||
vDirS.ToSpherical( &dLenSs, &dPhiSs, &dThetaSs) ;
|
||||
vDirE.ToSpherical( &dLenEs, &dPhiEs, &dThetaEs) ;
|
||||
if (( abs ( abs( dThetaEs - dThetaSs) - ANG_STRAIGHT)) < 3 * ANG_ROT_TOLL + 5 * EPS_ANG_SMALL)
|
||||
nCoeff = 4 ;
|
||||
|
||||
// ricavo i parametri per l'interpolazione sferica
|
||||
for ( int u = 0 ; u <= 10 * nCoeff && abs( dAng) > EPS_SMALL ; ++ u) {
|
||||
double du = u ;
|
||||
if ( nCoeff == 2) du = 0.5 * u ;
|
||||
if ( nCoeff == 4) du = 0.25 * u ;
|
||||
Vector3d vSlerp = (( sin( 1 - 0.1 * du) * dAng) / sin( dAng)) * vDirS +
|
||||
( sin( 0.1 * du * dAng) / sin( dAng)) * vDirE ;
|
||||
double dTheta_u ,dPhi_u ,dLen ;
|
||||
vSlerp.ToSpherical( &dLen, &dPhi_u, &dTheta_u) ;
|
||||
if ( abs( u - 10 * nCoeff) < EPS_SMALL &&
|
||||
( abs( dPhi_u) < EPS_ANG_SMALL || abs( dPhi_u - ANG_STRAIGHT) < EPS_ANG_SMALL))
|
||||
dTheta_u = ANG_STRAIGHT + ANG_RIGHT ;
|
||||
SetCamera( nBlockedAngle == 1 ? dPhi_orig : dPhi_u,
|
||||
nBlockedAngle == 2 ? dTheta_orig : dTheta_u, dDist) ;
|
||||
RedrawWindow() ;
|
||||
dTheta_new = dTheta_u ;
|
||||
dPhi_new = dPhi_u ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::GetAngleByCubeFace( int nFaceId, double &dTheta, double &dPhi)
|
||||
{
|
||||
switch ( nFaceId)
|
||||
{
|
||||
case 1 : // TOP
|
||||
dPhi = 0 ; dTheta = 270 ;
|
||||
break ;
|
||||
case 2 : // BOTTOM
|
||||
dPhi = 180 ; dTheta = 270 ;
|
||||
break ;
|
||||
case 3 : // RIGHT
|
||||
dPhi = 90 ; dTheta = 0 ;
|
||||
break ;
|
||||
case 4 : // LEFT
|
||||
dPhi = 90 ; dTheta = 180 ;
|
||||
break ;
|
||||
case 5 : // FRONT
|
||||
dPhi = 90 ; dTheta = 90 ;
|
||||
break ;
|
||||
case 6 : // BACK
|
||||
dPhi = 90 ; dTheta = 270 ;
|
||||
break ;
|
||||
case 7 : // TOP-RIGHT
|
||||
dPhi = 45 ; dTheta = 0 ;
|
||||
break ;
|
||||
case 8 : // TOP-LEFT
|
||||
dPhi = 45 ; dTheta = 180 ;
|
||||
break ;
|
||||
case 9 : // BOTTOM-RIGHT
|
||||
dPhi = 225 ; dTheta = 180 ;
|
||||
break ;
|
||||
case 10 : // BOTTOM-LEFT
|
||||
dPhi = 225 ; dTheta = 0 ;
|
||||
break ;
|
||||
case 11 : // TOP-FRONT
|
||||
dPhi = 45 ; dTheta = 90 ;
|
||||
break ;
|
||||
case 12 : // TOP-BACK
|
||||
dPhi = 45 ; dTheta = 270 ;
|
||||
break ;
|
||||
case 13 : // BOTTOM-FRONT
|
||||
dPhi = 225 ; dTheta = 270 ;
|
||||
break ;
|
||||
case 14 : // BOTTOM-BACK
|
||||
dPhi = 225 ; dTheta = 90 ;
|
||||
break ;
|
||||
case 15 : // RIGHT-FRONT
|
||||
dPhi = 90 ; dTheta = 45 ;
|
||||
break ;
|
||||
case 16 : // LEFT-FRONT
|
||||
dPhi = 90 ; dTheta = 135 ;
|
||||
break ;
|
||||
case 17 : // RIGHT-BACK
|
||||
dPhi = 90 ; dTheta = 315 ;
|
||||
break ;
|
||||
case 18 : // LEFT-BACK
|
||||
dPhi = 90 ; dTheta = 225 ;
|
||||
break ;
|
||||
case 19 : // TOP-RIGHT-FRONT
|
||||
dPhi = 45 ; dTheta = 45 ;
|
||||
break ;
|
||||
case 20 : // TOP-LEFT-FRONT
|
||||
dPhi = 45 ; dTheta = 135 ;
|
||||
break ;
|
||||
case 21 : // TOP-RIGHT-BACK
|
||||
dPhi = 45 ; dTheta = 315 ;
|
||||
break ;
|
||||
case 22 : // TOP-LEFT-BACK
|
||||
dPhi = 45 ; dTheta = 225 ;
|
||||
break ;
|
||||
case 23 : // BOTTOM-RIGHT-FRONT
|
||||
dPhi = 135 ; dTheta = 45 ;
|
||||
break ;
|
||||
case 24 : // BOTTOM-LEFT-FRONT
|
||||
dPhi = 135 ; dTheta = 135 ;
|
||||
break ;
|
||||
case 25 : // BOTTOM-RIGHT-BACK
|
||||
dPhi = 135 ; dTheta = 315 ;
|
||||
break ;
|
||||
case 26: // BOTTOM-LEFT-BACK
|
||||
dPhi = 135 ; dTheta = 215 ;
|
||||
break ;
|
||||
default :
|
||||
break ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::SetGlobCubeParameters( int nPosFlag, double dDistX, double dDistY, double dLenEdge)
|
||||
{
|
||||
// controllo ammissibilitŕ dei parametri
|
||||
if ( nPosFlag < 0 || nPosFlag > 4 ||
|
||||
dDistX < 0 || dDistY < 0 ||
|
||||
dLenEdge < MIN_EDGE_SIZE || dLenEdge > MAX_EDGE_SIZE )
|
||||
return false ;
|
||||
|
||||
// se visualizzazione del cubo non ammessa, esco
|
||||
if ( nPosFlag == 0) {
|
||||
m_bShowGlobCube = false ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
// imposto il flag di scelta dell'angolo del cubetto
|
||||
m_nCube_Flag = nPosFlag ;
|
||||
|
||||
// recupero la matrice viewport
|
||||
GLint Viewport[4] ;
|
||||
glGetIntegerv( GL_VIEWPORT, Viewport) ;
|
||||
|
||||
// imposto le coordinate del centro del cubo ( X e Y coordinate in ViewPort)
|
||||
double dCoordX = 0 ;
|
||||
double dCoordY = 0 ;
|
||||
switch ( m_nCube_Flag)
|
||||
{
|
||||
case 1 : // cubo in alto a destra
|
||||
dCoordX = Viewport[2] - dDistX ;
|
||||
dCoordY = dDistY ;
|
||||
break ;
|
||||
case 2 : // cubo in alto a sinistra
|
||||
dCoordX = dDistX ;
|
||||
dCoordY = dDistY ;
|
||||
break ;
|
||||
case 3 : // cubo in basso a sinistra
|
||||
dCoordX = dDistX ;
|
||||
dCoordY = Viewport[3] - dDistY ;
|
||||
break ;
|
||||
case 4 : // cubo in basso a destra
|
||||
dCoordX = Viewport[2] - dDistX ;
|
||||
dCoordY = Viewport[3] - dDistY ;
|
||||
break ;
|
||||
default :
|
||||
return false ;
|
||||
break ;
|
||||
}
|
||||
|
||||
// controllo che il cubo stia nella Viewport verticale con l'ingombro del suo lato
|
||||
if ( dCoordX <= sqrt( 3) * dLenEdge * 0.5 * sqrt( 2) * 0.5 + 3 ||
|
||||
dCoordX >= Viewport[2] - sqrt( 3) * dLenEdge * 0.5 * sqrt( 2) / 2 - 3)
|
||||
return false ;
|
||||
|
||||
// controllo che il cubo stia nella Viewport orizzontale con l'ingombro del suo lato
|
||||
if ( dCoordY <= Viewport[1] + sqrt( 3) * dLenEdge * 0.5 * sqrt( 2) * 0.5 + 3 ||
|
||||
dCoordY >= Viewport[3] - sqrt( 3) * dLenEdge * 0.5 * sqrt( 2) * 0.5 - 3)
|
||||
return false ;
|
||||
|
||||
// imposto le variabili membro
|
||||
m_dCubeX = dCoordX ;
|
||||
m_dCubeY = dCoordY ;
|
||||
m_dCubeEdge = dLenEdge ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
+26
-249
@@ -15,69 +15,10 @@
|
||||
#include "stdafx.h"
|
||||
#include "Scene.h"
|
||||
#include "EGrUtils.h"
|
||||
#include "/EgtDev/Include/EGkStmStandard.h"
|
||||
#include "ObjOldGraphics.h"
|
||||
#include "ObjNewGraphics.h"
|
||||
#include "ObjMultiGraphics.h"
|
||||
|
||||
|
||||
using namespace std ;
|
||||
|
||||
// posizione X e Y dello schermo
|
||||
const int POSITION_FLAG = 3 ;
|
||||
const double DIST_X = 40 ;
|
||||
const double DIST_Y = 40 ;
|
||||
|
||||
// dimensione lunghezza delle linee
|
||||
const double LINE_LEN = 25 ;
|
||||
const double MIN_LINE_LEN = 20.0 ;
|
||||
const double MAX_LINE_LEN = 100.0 ;
|
||||
|
||||
// dimensione spessore delle linee
|
||||
const double LINE_WIDTH = 2 ;
|
||||
|
||||
// colore origine del Frame
|
||||
const Color FRAME_ORIG( 0, 0, 0, 1) ;
|
||||
|
||||
// flag creazione coni per assi e vettore delle tre rispettive superifici
|
||||
static bool bConeCreated = false ;
|
||||
ISURFTMPOVECTOR vStmCones ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool CreateCone( double dConeRad, double dConeLen, double dLen) {
|
||||
|
||||
vStmCones.clear() ;
|
||||
|
||||
PtrOwner<ISurfTriMesh> pStmConeX( GetSurfTriMeshCone( dConeRad, dConeLen, 10)) ;
|
||||
pStmConeX->Rotate( ORIG, Y_AX, ANG_RIGHT) ;
|
||||
pStmConeX->Translate( Vector3d( 1, 0, 0) * dLen) ;
|
||||
vStmCones.emplace_back( Release( pStmConeX)) ;
|
||||
|
||||
PtrOwner<ISurfTriMesh> pStmConeY( GetSurfTriMeshCone( dConeRad, dConeLen, 10)) ;
|
||||
pStmConeY->Rotate( ORIG, -X_AX, ANG_RIGHT) ;
|
||||
pStmConeY->Translate( Vector3d( 0, 1, 0) * dLen) ;
|
||||
vStmCones.emplace_back( Release( pStmConeY)) ;
|
||||
|
||||
PtrOwner<ISurfTriMesh> pStmConeZ( GetSurfTriMeshCone( dConeRad, dConeLen, 10)) ;
|
||||
pStmConeZ->Translate( Vector3d( 0, 0, 1) * dLen) ;
|
||||
vStmCones.emplace_back( Release( pStmConeZ)) ;
|
||||
|
||||
bConeCreated = true ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static ObjEGrGraphics*
|
||||
CreateObjEGrGraphics( int nCount, bool bNewWay)
|
||||
{
|
||||
if ( nCount > 1)
|
||||
return ( new( nothrow) ObjMultiGraphics( nCount, bNewWay)) ;
|
||||
else if ( bNewWay)
|
||||
return ( new( nothrow) ObjNewGraphics) ;
|
||||
else
|
||||
return ( new( nothrow) ObjOldGraphics) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::SetGlobFrameShow( bool bShow)
|
||||
@@ -86,76 +27,6 @@ Scene::SetGlobFrameShow( bool bShow)
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::SetGlobFrameParameters( int nPosFlag, double dDistX, double dDistY,
|
||||
double dLenLine, double dWidthLine)
|
||||
{
|
||||
// controllo ammissibilità dei parametri
|
||||
if ( nPosFlag < 0 || nPosFlag > 4 ||
|
||||
dDistX < 0 || dDistY < 0 ||
|
||||
dLenLine < MIN_LINE_LEN || dLenLine > MAX_LINE_LEN ||
|
||||
dWidthLine < 1.0)
|
||||
return false ;
|
||||
|
||||
// se visualizzazione del frame non ammessa, esco
|
||||
if ( nPosFlag == 0) {
|
||||
m_bShowGlobFrame = false ;
|
||||
bConeCreated = false ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
// setto il flag di scelta per l'angolo di visualizzazione del Frame
|
||||
m_nAxisFrame_Flag = nPosFlag ;
|
||||
|
||||
// recupero la matrice viewport
|
||||
GLint Viewport[4] ;
|
||||
glGetIntegerv( GL_VIEWPORT, Viewport) ;
|
||||
|
||||
// imposto le coordinate del centro del Frame ( X e Y coordinate in ViewPort)
|
||||
double dCoordX = 0 ;
|
||||
double dCoordY = 0 ;
|
||||
switch ( m_nAxisFrame_Flag)
|
||||
{
|
||||
case 1 : // frame in alto a destra
|
||||
dCoordX = Viewport[2] - dDistX ;
|
||||
dCoordY = dDistY ;
|
||||
break ;
|
||||
case 2 : // frame in alto a sinistra
|
||||
dCoordX = dDistX ;
|
||||
dCoordY = dDistY ;
|
||||
break ;
|
||||
case 3 : // frame in basso a sinistra
|
||||
dCoordX = dDistX ;
|
||||
dCoordY = Viewport[3] - dDistY ;
|
||||
break ;
|
||||
case 4 : // frame in basso a destra
|
||||
dCoordX = Viewport[2] - dDistX ;
|
||||
dCoordY = Viewport[3] - dDistY ;
|
||||
break ;
|
||||
default :
|
||||
break ;
|
||||
}
|
||||
|
||||
// controllo che il frame stia nella Viewport verticale con l'ingombro dei suoi versori
|
||||
if ( dCoordX <= dLenLine * 0.5 * sqrt( 2) + 3 ||
|
||||
dCoordX >= Viewport[2] - sqrt( 2) * dLenLine * 0.5 - 3)
|
||||
return false ;
|
||||
|
||||
// controllo che il frame stia nella Viewport orizzontale con l'ingombro dei suoi versori
|
||||
if ( dCoordY <= Viewport[1] + sqrt( 2) * dLenLine * 0.5 + 3 ||
|
||||
dCoordY >= Viewport[3] - sqrt( 2) * dLenLine * 0.5 - 3)
|
||||
return false ;
|
||||
|
||||
// imposto le variabili membro
|
||||
m_dFrame_DistX = dCoordX ;
|
||||
m_dFrame_DistY = dCoordY ;
|
||||
m_dFrameLineL = dLenLine ;
|
||||
m_dFrameLineW = dWidthLine ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::DrawGlobFrame( void)
|
||||
@@ -168,140 +39,46 @@ Scene::DrawGlobFrame( void)
|
||||
GLint Viewport[ 4] ;
|
||||
glGetIntegerv( GL_VIEWPORT, Viewport) ;
|
||||
|
||||
// imposto il riferimento
|
||||
// imposto il riferimento sempre in vista ortografica
|
||||
glMatrixMode( GL_PROJECTION) ;
|
||||
glPushMatrix() ;
|
||||
if ( ! m_bOrthographic) {
|
||||
glLoadIdentity() ;
|
||||
glOrtho( - m_dHalfWidth, m_dHalfWidth, - m_dHalfHeight, m_dHalfHeight, m_dZNear, m_dZFar) ;
|
||||
}
|
||||
|
||||
// imposto l'origine del sistema di riferimento nelle coordinate della ViewPort
|
||||
// origine del riferimento globale
|
||||
const double DIST_BORDER = 30 ;
|
||||
const double POS_Z = 0.5 ;
|
||||
Point3d ptOrig ;
|
||||
const double POS_Z = 0.25 ;
|
||||
UnProject( Point3d( m_dFrame_DistX, m_dFrame_DistY, POS_Z), ptOrig) ;
|
||||
UnProject( Point3d( DIST_BORDER, Viewport[3] - DIST_BORDER, POS_Z), ptOrig) ;
|
||||
|
||||
// abilito Ztest per rendering delle linee e dei punti
|
||||
glEnable( GL_DEPTH_TEST) ;
|
||||
// lunghezza degli assi
|
||||
const double LEN_AX = DIST_BORDER - 2 ;
|
||||
double dLen = LEN_AX * ( 2 * m_dHalfWidth) / Viewport[2] ;
|
||||
|
||||
// controllo gli angoli correnti della telecamera per decidere il rendering delle linee ( continue o stripped)
|
||||
double dTheta, dPhi, dDist ;
|
||||
GetCamera( &dPhi, &dTheta, &dDist) ;
|
||||
bool bStripped_X = false ;
|
||||
bool bStripped_Y = false ;
|
||||
bool bStripped_Z = false ;
|
||||
if ( abs( dPhi) > ANG_RIGHT)
|
||||
bStripped_Z = true ;
|
||||
if ( abs( dTheta) > ANG_RIGHT && abs( dTheta) < ANG_RIGHT + ANG_STRAIGHT)
|
||||
bStripped_X = true ;
|
||||
if ( abs( dTheta) > ANG_STRAIGHT)
|
||||
bStripped_Y = true ;
|
||||
|
||||
// scalo la lunghezza degli assi
|
||||
double dLen = m_dFrameLineL * ( 2 * m_dHalfWidth) / Viewport[2] ;
|
||||
double dOrigOff = 0.875 * m_dFrameLineW * ( 2 * m_dHalfWidth) / Viewport[2] ;
|
||||
double dConeRad = m_dFrameLineW * 1.0 ;
|
||||
double dConeLen = 0.4 * m_dFrameLineL ;
|
||||
|
||||
// imposto la dimensione degli assi
|
||||
glLineWidth(( float) m_dFrameLineW) ;
|
||||
|
||||
// asse X
|
||||
if ( bStripped_X)
|
||||
glEnable( GL_LINE_STIPPLE) ;
|
||||
else
|
||||
glEnable( GL_LINES) ;
|
||||
// disegno degli assi
|
||||
glLineWidth( (float) GetFrameLineWidth()) ;
|
||||
glBegin( GL_LINES) ;
|
||||
glColor3f( m_cColX.GetRed(), m_cColX.GetGreen(), m_cColX.GetBlue()) ;
|
||||
glVertex3f( float( ptOrig.x + dOrigOff), float( ptOrig.y), float( ptOrig.z)) ;
|
||||
// asse X+
|
||||
glColor3f( 1, 0, 0) ;
|
||||
glVertex3f( float( ptOrig.x), float( ptOrig.y), float( ptOrig.z)) ;
|
||||
glVertex3f( float( ptOrig.x + dLen), float( ptOrig.y), float( ptOrig.z)) ;
|
||||
glEnd() ;
|
||||
if ( bStripped_X)
|
||||
glDisable( GL_LINE_STIPPLE) ;
|
||||
|
||||
// asse Y
|
||||
if ( bStripped_Y)
|
||||
glEnable( GL_LINE_STIPPLE) ;
|
||||
else
|
||||
glEnable( GL_LINES) ;
|
||||
glBegin( GL_LINES) ;
|
||||
glColor3f( m_cColY.GetRed(), m_cColY.GetGreen(), m_cColY.GetBlue()) ;
|
||||
glVertex3f( float( ptOrig.x), float( ptOrig.y + dOrigOff), float( ptOrig.z)) ;
|
||||
// asse Y+
|
||||
glColor3f( 0, 1, 0) ;
|
||||
glVertex3f( float( ptOrig.x), float( ptOrig.y), float( ptOrig.z)) ;
|
||||
glVertex3f( float( ptOrig.x), float( ptOrig.y + dLen), float( ptOrig.z)) ;
|
||||
glEnd() ;
|
||||
if ( bStripped_Y)
|
||||
glDisable( GL_LINE_STIPPLE) ;
|
||||
|
||||
// asse Z
|
||||
if ( bStripped_Z)
|
||||
glEnable( GL_LINE_STIPPLE) ;
|
||||
else
|
||||
glEnable( GL_LINES) ;
|
||||
glBegin( GL_LINES) ;
|
||||
glColor3f( m_cColZ.GetRed(), m_cColZ.GetGreen(), m_cColZ.GetBlue()) ;
|
||||
glVertex3f( float( ptOrig.x), float( ptOrig.y), float( ptOrig.z + dOrigOff)) ;
|
||||
// asse Z+
|
||||
glColor3f( 0, 0, 1) ;
|
||||
glVertex3f( float( ptOrig.x), float( ptOrig.y), float( ptOrig.z)) ;
|
||||
glVertex3f( float( ptOrig.x), float( ptOrig.y), float( ptOrig.z + dLen)) ;
|
||||
glEnd() ;
|
||||
if ( bStripped_Z)
|
||||
glDisable( GL_LINE_STIPPLE) ;
|
||||
|
||||
// TEST PUNTI !
|
||||
glEnable( GL_POINT_SMOOTH ) ;
|
||||
glPointSize(( float) 2.5 * m_dFrameLineW) ;
|
||||
glBegin( GL_POINTS) ;
|
||||
glColor3f( FRAME_ORIG.GetRed(), FRAME_ORIG.GetGreen(), FRAME_ORIG.GetBlue()) ;
|
||||
glVertex3f( float( ptOrig.x), float( ptOrig.y), float( ptOrig.z)) ;
|
||||
glEnd() ;
|
||||
glPointSize(( float) GetPointSize()) ;
|
||||
glDisable( GL_POINT_SMOOTH) ;
|
||||
|
||||
// disegno i tre coni ( se precedentemente non già creati)
|
||||
if ( ! bConeCreated)
|
||||
CreateCone( dConeRad, dConeLen, m_dFrameLineL) ;
|
||||
|
||||
// creo un vettore di Graphics, uno per ogni cono del frame
|
||||
vector<PtrOwner<ObjEGrGraphics>> vGraphics ;
|
||||
for ( int i = 0 ; i < 3 ; ++ i) {
|
||||
PtrOwner<ObjEGrGraphics> pNewGraphics( CreateObjEGrGraphics( 0, false)) ;
|
||||
vGraphics.emplace_back( Release( pNewGraphics)) ;
|
||||
vGraphics[i]->SetScene( this) ;
|
||||
}
|
||||
|
||||
for ( int s = 0 ; s < 3 ; ++ s) {
|
||||
// recupero la superificie corrente del cubo da visualizzare
|
||||
PtrOwner<ISurfTriMesh> pStmCurr_Cone( CloneSurfTriMesh( vStmCones[s])) ;
|
||||
if ( IsNull( pStmCurr_Cone))
|
||||
return false ;
|
||||
|
||||
// scalo la superificie a seconda della viewport corrente ( per Zoom)
|
||||
pStmCurr_Cone->Scale( GLOB_FRM, ( 2 * m_dHalfWidth) / Viewport[2], ( 2 * m_dHalfWidth) / Viewport[2],
|
||||
( 2 * m_dHalfWidth) / Viewport[2]) ;
|
||||
// sposto la superificie nel sistema di riferimento relativo alla telecamera ( per Pan)
|
||||
pStmCurr_Cone->Translate(( ptOrig - ORIG)) ;
|
||||
|
||||
Color cCurrColor ;
|
||||
if ( s == 0) cCurrColor = m_cColX ;
|
||||
if ( s == 1) cCurrColor = m_cColY ;
|
||||
if ( s == 2) cCurrColor = m_cColZ ;
|
||||
vGraphics[s]->AddColor( cCurrColor) ;
|
||||
int nTria = pStmCurr_Cone->GetTriangleCount() ;
|
||||
vGraphics[s]->StartTriangles( nTria) ;
|
||||
Triangle3dEx Tria ;
|
||||
int nId = pStmCurr_Cone->GetFirstTriangle( Tria) ;
|
||||
while ( nId != SVT_NULL) {
|
||||
// edge solo se boundary e normali ai vertici smussate
|
||||
vGraphics[s]->AddTriangle( Tria, Tria.GetTriFlags(), Tria.GetTriNormals()) ;
|
||||
nId = pStmCurr_Cone->GetNextTriangle( nId, Tria) ;
|
||||
}
|
||||
vGraphics[s]->EndTriangles() ;
|
||||
// assegno un id temporaneo alla superificie caricata ( modalita wireFrame, come nella Select)
|
||||
vGraphics[s]->Draw( GDB_ST_ON, GDB_MK_OFF, true, true, 80, false) ;
|
||||
}
|
||||
|
||||
// torno a spessore della linee impostato in precedenza
|
||||
glLineWidth((float) GetLineWidth()) ;
|
||||
|
||||
glDisable( GL_DEPTH_TEST) ;
|
||||
// ripristino spessore linee
|
||||
glLineWidth( (float) GetLineWidth()) ;
|
||||
|
||||
// ripristino lo stack delle matrici
|
||||
glPopMatrix() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+21
-19
@@ -128,26 +128,28 @@ Scene::GetImage( int nShowMode, Color colBackTop, Color colBackBottom,
|
||||
pDib = FreeImage_ConvertTo24Bits( pTmpDib) ;
|
||||
FreeImage_Unload( pTmpDib) ;
|
||||
|
||||
// Eseguo scalatura della bitmap
|
||||
int nLeft ; int nTop ;
|
||||
int nRight ; int nBottom ;
|
||||
if ( dCoeffW / nN >= dCoeffH / nM) {
|
||||
nLeft = 0 ;
|
||||
nRight = nN * nWidth - 1 ;
|
||||
int nDeltaH = nM * nHeight - nN * int( nDestHeight / dCoeffW) ;
|
||||
nTop = nDeltaH / 2 ;
|
||||
nBottom = nM * nHeight - nTop - 1 ;
|
||||
// Se necessario, eseguo scalatura della bitmap
|
||||
if ( nDestWidth != nN * nWidth || nDestHeight != nM * nHeight) {
|
||||
int nLeft ; int nTop ;
|
||||
int nRight ; int nBottom ;
|
||||
if ( dCoeffW / nN >= dCoeffH / nM) {
|
||||
nLeft = 0 ;
|
||||
nRight = nN * nWidth - 1 ;
|
||||
int nDeltaH = nM * nHeight - nN * int( nDestHeight / dCoeffW) ;
|
||||
nTop = nDeltaH / 2 ;
|
||||
nBottom = nM * nHeight - nTop - 1 ;
|
||||
}
|
||||
else {
|
||||
nTop = 0 ;
|
||||
nBottom = nM * nHeight - 1 ;
|
||||
int nDeltaW = nN * nWidth - nM * int( nDestWidth / dCoeffH) ;
|
||||
nLeft = nDeltaW / 2 ;
|
||||
nRight = nN * nWidth - nLeft - 1 ;
|
||||
}
|
||||
FIBITMAP* pTmp2Dib = pDib ;
|
||||
pDib = FreeImage_RescaleRect( pTmp2Dib, nDestWidth, nDestHeight, nLeft, nTop, nRight, nBottom, FILTER_CATMULLROM) ;
|
||||
FreeImage_Unload( pTmp2Dib) ;
|
||||
}
|
||||
else {
|
||||
nTop = 0 ;
|
||||
nBottom = nM * nHeight - 1 ;
|
||||
int nDeltaW = nN * nWidth - nM * int( nDestWidth / dCoeffH) ;
|
||||
nLeft = nDeltaW / 2 ;
|
||||
nRight = nN * nWidth - nLeft - 1 ;
|
||||
}
|
||||
FIBITMAP* pTmp2Dib = pDib ;
|
||||
pDib = FreeImage_RescaleRect( pTmp2Dib, nDestWidth, nDestHeight, nLeft, nTop, nRight, nBottom, FILTER_BSPLINE) ;
|
||||
FreeImage_Unload( pTmp2Dib) ;
|
||||
|
||||
// Salvataggio
|
||||
int nFlag = 0 ;
|
||||
|
||||
+21
-11
@@ -95,12 +95,6 @@ Scene::Select( const Point3d& ptSelCenter, int nW, int nH, int& nSel)
|
||||
// non imposto glPolygonMode secondo il tipo di rendering perchè ignorato in selezione
|
||||
// disegno le geometrie del DB in una sola passata
|
||||
DrawGroup( GDB_ID_ROOT, 1, MdStMkCol( GDB_MD_STD, GDB_ST_ON, GDB_MK_OFF, m_colDef)) ;
|
||||
// disegno il cubetto
|
||||
glEnable( GL_CULL_FACE) ;
|
||||
glCullFace( GL_BACK) ;
|
||||
glFrontFace( GL_CCW) ;
|
||||
DrawGlobCube( false) ;
|
||||
glDisable( GL_CULL_FACE) ;
|
||||
|
||||
// pulisco stack nomi
|
||||
glPopName() ;
|
||||
@@ -115,10 +109,6 @@ Scene::Select( const Point3d& ptSelCenter, int nW, int nH, int& nSel)
|
||||
// riordino il buffer di selezione secondo la Zdepth minima crescente
|
||||
qsort( m_nSelBuff, m_nSelNbr, sizeof( SelRec), CompareSelRec) ;
|
||||
|
||||
// controllo se ho selezionato una superficie sul cubetto
|
||||
if ( RotateCameraWithCube())
|
||||
m_nSelNbr = 0 ;
|
||||
|
||||
nSel = m_nSelNbr ;
|
||||
return true ;
|
||||
}
|
||||
@@ -371,7 +361,27 @@ Scene::GetPointFromSelect( int nSelId, const Point3d& ptView, Point3d& ptSel, in
|
||||
double dLenMir = 4 * dBlRad ;
|
||||
// cerco i triangoli intersecati dalla linea di mira
|
||||
ILSIVECTOR vInfo ;
|
||||
if ( ! IntersLineSurfTm( ptMir, vtDir, dLenMir, *pStm, vInfo) || vInfo.size() == 0)
|
||||
if ( ! IntersLineSurfTm( ptMir, vtDir, dLenMir, *pStm, vInfo))
|
||||
return false ;
|
||||
// se non trovato alcunchè, cerco le linee che partono dagli angoli e dai punti medi dei lati del rettangolo di mira
|
||||
VCT3DVECTOR vVtWind = { {0.51, 0.51, 0}, {0, 0.51, 0}, {-0.51, 0.51, 0}, {-0.51, 0, 0},
|
||||
{-0.51, -0.51, 0}, {0, -0.51, 0}, {0.51, -0.51, 0}, {0.51, 0, 0},
|
||||
{0.25, 0.51, 0}, {-0.25, 0.51, 0}, {-0.51, 0.25, 0}, {-0.51, -0.25, 0},
|
||||
{-0.25, -0.51, 0}, {0.25, -0.51, 0}, {0.51, -0.25, 0}, {0.51, 0.25, 0}} ;
|
||||
for ( int i = 0 ; i < int( vVtWind.size()) && vInfo.empty() ; ++ i) {
|
||||
// determino punto su vertice del rettangolo di selezione
|
||||
Point3d ptWinZ2 = ptWinZ + vVtWind[i].x * m_nSelH * X_AX + vVtWind[i].y * m_nSelW * Y_AX ;
|
||||
// ne ricavo punto di mira
|
||||
Point3d ptMir2 ;
|
||||
if ( ! UnProject( ptWinZ2, ptMir2))
|
||||
return false ;
|
||||
ptMir2.ToLoc( frEnt) ;
|
||||
ptMir2 -= vtDir * 2 * dBlRad ;
|
||||
// interseco con la superficie
|
||||
if ( ! IntersLineSurfTm( ptMir2, vtDir, dLenMir, *pStm, vInfo))
|
||||
return false ;
|
||||
}
|
||||
if ( vInfo.empty())
|
||||
return false ;
|
||||
// recupero il primo punto
|
||||
ptSel = GetToGlob( vInfo[0].ptI, frEnt) ;
|
||||
|
||||
+98
-64
@@ -48,7 +48,7 @@ Scene::GetGraphicSnapPoint( int nSnap, const Point3d& ptWin, int nW, int nH, Poi
|
||||
// reset dati associati a ultimo punto snap
|
||||
m_nLastSnapId = GDB_ID_NULL ;
|
||||
m_bLastSnapDirOk = false ;
|
||||
// verifico validità GDB
|
||||
// verifico validità GDB
|
||||
if ( m_pGeomDB == nullptr)
|
||||
return false ;
|
||||
// se Snap Sketch o Grid, devo trovare il punto sulla griglia
|
||||
@@ -58,14 +58,14 @@ Scene::GetGraphicSnapPoint( int nSnap, const Point3d& ptWin, int nW, int nH, Poi
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
// se Snap Intersection, devo trovare l'intersezione tra due entità inquadrate
|
||||
// se Snap Intersection, devo trovare l'intersezione tra due entità inquadrate
|
||||
else if ( nSnap == SP_INTERS) {
|
||||
if ( FindSelectedIntersectionPoint( ptWin, nW, nH)) {
|
||||
ptSel = m_ptLastSnapPnt ;
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
// altrimenti devo trovare il punto dall'entità inquadrata
|
||||
// altrimenti devo trovare il punto dall'entità inquadrata
|
||||
else {
|
||||
if ( FindSelectedSnapPoint( nSnap, ptWin, nW, nH)) {
|
||||
ptSel = m_ptLastSnapPnt ;
|
||||
@@ -88,9 +88,17 @@ Scene::GetGridSnapPointZ( bool bSketch, const Point3d& ptWin, const Point3d& ptG
|
||||
if ( ! UnProject( ptWin, ptLine))
|
||||
return false ;
|
||||
Vector3d vtLine = - m_vtDirCamera ;
|
||||
if ( ! m_bOrthographic) {
|
||||
// nella vista prospettica la direzione di mira è data dalla linea che coingiunge le proiezioni di ptWin sui piani near e far
|
||||
Point3d ptLine2 ;
|
||||
if ( ! UnProject( Point3d( ptWin.x, ptWin.y, 1), ptLine2))
|
||||
return false ;
|
||||
vtLine = ptLine - ptLine2 ;
|
||||
vtLine.Normalize() ;
|
||||
}
|
||||
|
||||
// piano di elevazione :
|
||||
// per il punto di griglia, contenente la perp. alla griglia e più perp. possibile alla direzione di mira
|
||||
// per il punto di griglia, contenente la perp. alla griglia e più perp. possibile alla direzione di mira
|
||||
Vector3d vtNorm = vtLine - ( vtLine * frGrid.VersZ()) * frGrid.VersZ() ;
|
||||
if ( ! vtNorm.Normalize())
|
||||
return false ;
|
||||
@@ -123,6 +131,14 @@ Scene::FindGridSnapPoint( bool bSketch, const Point3d& ptWin)
|
||||
if ( ! UnProject( ptWin, ptLine))
|
||||
return false ;
|
||||
Vector3d vtLine = - m_vtDirCamera ;
|
||||
if ( ! m_bOrthographic) {
|
||||
// nella vista prospettica la direzione di mira è data dalla linea che coingiunge le proiezioni di ptWin sui piani near e far
|
||||
Point3d ptLine2 ;
|
||||
if ( ! UnProject( Point3d( ptWin.x, ptWin.y, 1), ptLine2))
|
||||
return false ;
|
||||
vtLine = ptLine - ptLine2 ;
|
||||
vtLine.Normalize() ;
|
||||
}
|
||||
|
||||
// determino l'intersezione di questa linea con il piano della griglia
|
||||
double dDenom = vtLine * frGrid.VersZ() ;
|
||||
@@ -133,7 +149,7 @@ Scene::FindGridSnapPoint( bool bSketch, const Point3d& ptWin)
|
||||
|
||||
// porto il punto sul piano di griglia
|
||||
m_ptLastSnapPnt.ToLoc( frGrid) ;
|
||||
// se punto grid, devo arrotondare al nodo di griglia più vicino
|
||||
// se punto grid, devo arrotondare al nodo di griglia più vicino
|
||||
if ( ! bSketch) {
|
||||
m_ptLastSnapPnt.x = floor( m_ptLastSnapPnt.x / m_dSnapStep + 0.5) * m_dSnapStep ;
|
||||
m_ptLastSnapPnt.y = floor( m_ptLastSnapPnt.y / m_dSnapStep + 0.5) * m_dSnapStep ;
|
||||
@@ -150,7 +166,9 @@ bool
|
||||
Scene::FindSelectedIntersectionPoint( const Point3d& ptWin, int nW, int nH)
|
||||
{
|
||||
// --- l'intersezione viene calcolata nel piano della griglia ---
|
||||
// verifico siano state selezionate delle entità
|
||||
// salvo eventuale ultima entità precedentemente selezionata
|
||||
int nPrevSel = GetFirstSelectedObj() ;
|
||||
// verifico siano state selezionate delle entità
|
||||
int nSel ;
|
||||
Select( ptWin, nW, nH, nSel) ;
|
||||
if ( nSel <= 0)
|
||||
@@ -158,17 +176,19 @@ Scene::FindSelectedIntersectionPoint( const Point3d& ptWin, int nW, int nH)
|
||||
// cerco le prime due curve inquadrate con i loro riferimenti
|
||||
const ICurve* pCrv[2] ;
|
||||
Frame3d frEnt[2] ;
|
||||
int nIds[2] ;
|
||||
double dWinZ = 0 ;
|
||||
int nCrvNum = 0 ;
|
||||
for ( int i = GetFirstSelectedObj() ; i != GDB_ID_NULL && nCrvNum < 2 ; i = GetNextSelectedObj()) {
|
||||
// se non è entità geometrica
|
||||
for ( int nObjId = GetFirstSelectedObj() ; nObjId != GDB_ID_NULL && nCrvNum < 2 ; nObjId = GetNextSelectedObj()) {
|
||||
// se non è entità geometrica
|
||||
const IGeoObj* pGObj ;
|
||||
if ( ( pGObj = m_pGeomDB->GetGeoObj( i)) == nullptr)
|
||||
if ( ( pGObj = m_pGeomDB->GetGeoObj( nObjId)) == nullptr)
|
||||
continue ;
|
||||
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
||||
pCrv[nCrvNum] = GetCurve( pGObj) ;
|
||||
if ( ! m_pGeomDB->GetGlobFrame( i, frEnt[nCrvNum]))
|
||||
if ( ! m_pGeomDB->GetGlobFrame( nObjId, frEnt[nCrvNum]))
|
||||
return false ;
|
||||
nIds[nCrvNum] = nObjId ;
|
||||
dWinZ += 0.5 * GetSelectedObjWinZ() ;
|
||||
++ nCrvNum ;
|
||||
}
|
||||
@@ -176,11 +196,11 @@ Scene::FindSelectedIntersectionPoint( const Point3d& ptWin, int nW, int nH)
|
||||
// se nessuna curva, esco
|
||||
if ( nCrvNum == 0)
|
||||
return false ;
|
||||
// se una sola curva, può essere auto intersezione
|
||||
// se una sola curva, può essere auto intersezione
|
||||
if ( nCrvNum == 1) {
|
||||
// recupero il riferimento di griglia
|
||||
Frame3d frGrid = GetGridFrame() ;
|
||||
// se il riferimento della curva è diverso da quello della griglia, devo trasformarla
|
||||
// se il riferimento della curva è diverso da quello della griglia, devo trasformarla
|
||||
PtrOwner<ICurve> pcrvTrans0 ;
|
||||
if ( ! AreSameFrame( frEnt[0], frGrid)) {
|
||||
pcrvTrans0.Set( pCrv[0]->Clone()) ;
|
||||
@@ -195,17 +215,19 @@ Scene::FindSelectedIntersectionPoint( const Point3d& ptWin, int nW, int nH)
|
||||
if ( ! UnProject( ptWinZ, ptNear))
|
||||
ptNear = ORIG ;
|
||||
ptNear.ToLoc( frGrid) ;
|
||||
// calcolo il punto di intersezione sulla prima curva più vicino al punto di riferimento
|
||||
// calcolo il punto di intersezione sulla prima curva più vicino al punto di riferimento
|
||||
SelfIntersCurve sintC( *pCrv[0]) ;
|
||||
if ( ! sintC.GetIntersPointNearTo( ptNear, m_ptLastSnapPnt))
|
||||
return false ;
|
||||
m_nLastSnapId = nIds[0] ;
|
||||
m_ptLastSnapPnt.ToGlob( frGrid) ;
|
||||
m_bLastSnapDirOk = false ;
|
||||
return true ;
|
||||
}
|
||||
// altrimenti due curve, procedo normalmente
|
||||
// recupero il riferimento di griglia
|
||||
Frame3d frGrid = GetGridFrame() ;
|
||||
// se il riferimento della prima curva è diverso da quello della griglia, devo trasformarla
|
||||
// se il riferimento della prima curva è diverso da quello della griglia, devo trasformarla
|
||||
PtrOwner<ICurve> pcrvTrans0 ;
|
||||
if ( ! AreSameFrame( frEnt[0], frGrid)) {
|
||||
pcrvTrans0.Set( pCrv[0]->Clone()) ;
|
||||
@@ -214,7 +236,7 @@ Scene::FindSelectedIntersectionPoint( const Point3d& ptWin, int nW, int nH)
|
||||
pcrvTrans0->LocToLoc( frEnt[0], frGrid) ;
|
||||
pCrv[0] = pcrvTrans0 ;
|
||||
}
|
||||
// se il riferimento della seconda curva è diverso da quello della griglia, devo trasformarla
|
||||
// se il riferimento della seconda curva è diverso da quello della griglia, devo trasformarla
|
||||
PtrOwner<ICurve> pcrvTrans1 ;
|
||||
if ( ! AreSameFrame( frEnt[1], frGrid)) {
|
||||
pcrvTrans1.Set( pCrv[1]->Clone()) ;
|
||||
@@ -229,11 +251,13 @@ Scene::FindSelectedIntersectionPoint( const Point3d& ptWin, int nW, int nH)
|
||||
if ( ! UnProject( ptWinZ, ptNear))
|
||||
ptNear = ORIG ;
|
||||
ptNear.ToLoc( frGrid) ;
|
||||
// calcolo il punto di intersezione sulla prima curva più vicino al punto di riferimento
|
||||
// calcolo il punto di intersezione sulla prima curva più vicino al punto di riferimento
|
||||
IntersCurveCurve intCC( *pCrv[0], *pCrv[1], true) ;
|
||||
if ( ! intCC.GetIntersPointNearTo( 0, ptNear, m_ptLastSnapPnt))
|
||||
if ( ! intCC.GetIntersPointNearTo( ( nPrevSel == nIds[1] ? 1 : 0), ptNear, m_ptLastSnapPnt))
|
||||
return false ;
|
||||
m_nLastSnapId = nIds[0] ;
|
||||
m_ptLastSnapPnt.ToGlob( frGrid) ;
|
||||
m_bLastSnapDirOk = false ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
@@ -241,20 +265,20 @@ Scene::FindSelectedIntersectionPoint( const Point3d& ptWin, int nW, int nH)
|
||||
bool
|
||||
Scene::FindSelectedSnapPoint( int nSnap, const Point3d& ptWin, int nW, int nH)
|
||||
{
|
||||
// seleziono e verifico siano state selezionate delle entità
|
||||
// seleziono e verifico siano state selezionate delle entità
|
||||
int nSel ;
|
||||
Select( ptWin, nW, nH, nSel) ;
|
||||
if ( nSel <= 0)
|
||||
return false ;
|
||||
// cerco il punto notevole più vicino alla selezione tra le entità selezionate
|
||||
// cerco il punto notevole più vicino alla selezione tra le entità selezionate
|
||||
bool bFound = false ;
|
||||
double dMinSqDist = INFINITO * INFINITO ;
|
||||
for ( int nId = GetFirstSelectedObj() ; nId != GDB_ID_NULL ; nId = GetNextSelectedObj()) {
|
||||
// se non è entità geometrica
|
||||
// se non è entità geometrica
|
||||
const IGeoObj* pGObj ;
|
||||
if ( ( pGObj = m_pGeomDB->GetGeoObj( nId)) == nullptr)
|
||||
continue ;
|
||||
// recupero riferimento dell'entità
|
||||
// recupero riferimento dell'entità
|
||||
Frame3d frEnt ;
|
||||
if ( ! m_pGeomDB->GetGlobFrame( nId, frEnt))
|
||||
continue ;
|
||||
@@ -470,7 +494,7 @@ Scene::FindCurveSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame
|
||||
UnProject( ptWinZ, ptRef) ;
|
||||
// lo porto nel frame della curva
|
||||
ptRef.ToLoc( frEnt) ;
|
||||
// determino il punto più vicino della curva a questo
|
||||
// determino il punto più vicino della curva a questo
|
||||
MinDistPCInfo mdInfo ;
|
||||
DistPointCurve dstPtCurve( ptRef, *pCrv) ;
|
||||
if ( dstPtCurve.GetMinDistInfo( 0, mdInfo)) {
|
||||
@@ -497,7 +521,7 @@ Scene::FindCurveSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame
|
||||
bool
|
||||
Scene::VerifySnapPoint( const Point3d& ptP, const Point3d& ptWin, double& dMinSqDist) const
|
||||
{
|
||||
// il punto di riferimento deriva da XY su viewport e Z minima (più vicina a osservatore) da selezione
|
||||
// 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 ;
|
||||
@@ -505,7 +529,7 @@ Scene::VerifySnapPoint( const Point3d& ptP, const Point3d& ptWin, double& dMinSq
|
||||
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
|
||||
// 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) ;
|
||||
@@ -545,10 +569,10 @@ Scene::AdjustForCurveExtr( const Point3d& ptWin, const Frame3d& frEnt, const ICu
|
||||
double dExtrSqDist = INFINITO ;
|
||||
DistPointCurve dstPtECurve( ptRef - vtExtr, *pCrv) ;
|
||||
dstPtECurve.GetSqDist( dExtrSqDist) ;
|
||||
// se più vicino a base non devo modificare il punto
|
||||
// se più vicino a base non devo modificare il punto
|
||||
if ( dBaseSqDist <= dExtrSqDist)
|
||||
return false ;
|
||||
// più vicino ad estrusione, quindi la aggiungo
|
||||
// più vicino ad estrusione, quindi la aggiungo
|
||||
ptP += vtExtr ;
|
||||
return true ;
|
||||
}
|
||||
@@ -566,7 +590,7 @@ Scene::FindCurveCompoSnapPoint( int nSnap, const Point3d& ptWin, int nId, const
|
||||
return false ;
|
||||
// porto il punto nel riferimento della curva
|
||||
ptRef.ToLoc( frEnt) ;
|
||||
// se richiesto il centro di gravità (baricentro, centroide)
|
||||
// se richiesto il centro di gravità (baricentro, centroide)
|
||||
if ( nSnap == SP_CENTROID) {
|
||||
Point3d ptP ;
|
||||
bool bFound = false ;
|
||||
@@ -583,11 +607,11 @@ Scene::FindCurveCompoSnapPoint( int nSnap, const Point3d& ptWin, int nId, const
|
||||
return bFound ;
|
||||
}
|
||||
// altrimenti opero sulle curve componenti elementari
|
||||
// determino la curva elementare più vicina al punto di riferimento
|
||||
// determino la curva elementare più vicina al punto di riferimento
|
||||
int nCrv = - 1 ;
|
||||
double dPar ;
|
||||
int nFlag ;
|
||||
// cerco il punto della curva più vicino, dal suo parametro deduco la curva elementare
|
||||
// cerco il punto della curva più vicino, dal suo parametro deduco la curva elementare
|
||||
if ( DistPointCurve( ptRef, *pCrvCompo).GetParamAtMinDistPoint( 0, dPar, nFlag))
|
||||
nCrv = static_cast<int>( dPar) ;
|
||||
// lavoro sulla curva elementare
|
||||
@@ -617,7 +641,7 @@ bool
|
||||
Scene::FindSurfTMSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame3d& frEnt,
|
||||
const ISurfTriMesh* pStm, double& dMinSqDist)
|
||||
{
|
||||
// il punto di riferimento deriva da XY su viewport e Z minima (più vicina a osservatore) da selezione
|
||||
// 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 ;
|
||||
@@ -643,12 +667,12 @@ Scene::FindSurfTMSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
|
||||
Color cCol ;
|
||||
bool bAlpha = ( m_pGeomDB->GetCalcMaterial( nId, cCol) && cCol.GetIntAlpha() <= ALPHA_LIM) ;
|
||||
|
||||
// se richiesto il centro di gravità (baricentro, centroide)
|
||||
// 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
|
||||
// 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) ;
|
||||
@@ -660,7 +684,7 @@ Scene::FindSurfTMSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
|
||||
m_bLastSnapDirOk = false ;
|
||||
}
|
||||
}
|
||||
// se trovato e modalità shading o hiddenline, la favorisco perchè davanti alle possibili successive
|
||||
// se trovato e modalità shading o hiddenline, la favorisco perchè davanti alle possibili successive
|
||||
if ( bFound && ! ( bAlpha || m_nShowMode == SM_WIREFRAME))
|
||||
dMinSqDist = 0 ;
|
||||
return bFound ;
|
||||
@@ -670,12 +694,14 @@ Scene::FindSurfTMSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
|
||||
ILSIVECTOR vInfo ;
|
||||
if ( ! IntersLineSurfTm( ptMir, vtDir, dLenMir, *pStm, vInfo))
|
||||
return false ;
|
||||
// se non trovato alcunchè, cerco le linee che partono dagli angoli del rettangolo di mira
|
||||
Vector3d vtWinD( -1, -1, 0) ;
|
||||
for ( int i = 0 ; i < 4 && vInfo.size() == 0 ; ++ i) {
|
||||
// se non trovato alcunchè, cerco le linee che partono dagli angoli e dai punti medi dei lati del rettangolo di mira
|
||||
VCT3DVECTOR vVtWind = { {0.51, 0.51, 0}, {0, 0.51, 0}, {-0.51, 0.51, 0}, {-0.51, 0, 0},
|
||||
{-0.51, -0.51, 0}, {0, -0.51, 0}, {0.51, -0.51, 0}, {0.51, 0, 0},
|
||||
{0.25, 0.51, 0}, {-0.25, 0.51, 0}, {-0.51, 0.25, 0}, {-0.51, -0.25, 0},
|
||||
{-0.25, -0.51, 0}, {0.25, -0.51, 0}, {0.51, -0.25, 0}, {0.51, 0.25, 0}} ;
|
||||
for ( int i = 0 ; i < int( vVtWind.size()) && vInfo.empty() ; ++ i) {
|
||||
// determino punto su vertice del rettangolo di selezione
|
||||
Point3d ptWinZ2 = ptWinZ + vtWinD.x * m_nSelH * X_AX + vtWinD.y * m_nSelW * Y_AX ;
|
||||
vtWinD.Rotate( Z_AX, 0, 1) ;
|
||||
Point3d ptWinZ2 = ptWinZ + vVtWind[i].x * m_nSelH * X_AX + vVtWind[i].y * m_nSelW * Y_AX ;
|
||||
// ne ricavo punto di mira
|
||||
Point3d ptMir2 ;
|
||||
if ( ! UnProject( ptWinZ2, ptMir2))
|
||||
@@ -686,7 +712,7 @@ Scene::FindSurfTMSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
|
||||
if ( ! IntersLineSurfTm( ptMir2, vtDir, dLenMir, *pStm, vInfo))
|
||||
return false ;
|
||||
}
|
||||
if ( vInfo.size() == 0)
|
||||
if ( vInfo.empty())
|
||||
return false ;
|
||||
|
||||
// elaborazione a seconda del tipo di snap
|
||||
@@ -699,12 +725,12 @@ Scene::FindSurfTMSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
|
||||
for ( int i = 0 ; i < nTtot ; ++ i) {
|
||||
// punto di intersezione
|
||||
Point3d ptInt = vInfo[i].ptI ;
|
||||
// punto finale più vicino
|
||||
// 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
|
||||
// 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) ;
|
||||
@@ -727,12 +753,12 @@ Scene::FindSurfTMSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
|
||||
for ( int i = 0 ; i < nTtot ; ++ i) {
|
||||
// punto di intersezione
|
||||
Point3d ptInt = vInfo[i].ptI ;
|
||||
// punto medio più vicino
|
||||
// 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
|
||||
// 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) ;
|
||||
@@ -753,12 +779,12 @@ Scene::FindSurfTMSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
|
||||
// con wireframe devo provare tutti i triangoli intersecati, con shading e hiddenline solo il primo
|
||||
int nTtot = (( bAlpha || m_nShowMode == SM_WIREFRAME) ? int( vInfo.size()) : 1) ;
|
||||
for ( int i = 0 ; i < nTtot ; ++ i) {
|
||||
// centro più vicino
|
||||
// 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
|
||||
// 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) ;
|
||||
@@ -779,7 +805,7 @@ Scene::FindSurfTMSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
|
||||
case SP_PERP :
|
||||
case SP_MINDIST :
|
||||
// considero solo il primo triangolo intersecato
|
||||
// la distanza è nulla e la confronto con il minimo
|
||||
// la distanza è nulla e la confronto con il minimo
|
||||
if ( 0 < dMinSqDist) {
|
||||
bFound = true ;
|
||||
dMinSqDist = 0 ;
|
||||
@@ -805,7 +831,7 @@ Scene::FindSurfTMSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
|
||||
break ;
|
||||
}
|
||||
|
||||
// se trovato e modalità shading o hiddenline, la favorisco perchè davanti alle possibili successive
|
||||
// se trovato e modalità shading o hiddenline, la favorisco perchè davanti alle possibili successive
|
||||
if ( bFound && ! ( bAlpha || m_nShowMode == SM_WIREFRAME) && dMinSqDist < SRF_SMALL_SQDIST)
|
||||
dMinSqDist = 0 ;
|
||||
|
||||
@@ -817,7 +843,7 @@ bool
|
||||
Scene::FindSurfFRSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame3d& frEnt,
|
||||
const ISurfFlatRegion* pSfr, double& dMinSqDist)
|
||||
{
|
||||
// il punto di riferimento deriva da XY su viewport e Z minima (più vicina a osservatore) da selezione
|
||||
// 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 ;
|
||||
@@ -834,11 +860,11 @@ Scene::FindSurfFRSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
|
||||
|
||||
// elaborazione a seconda del tipo di snap
|
||||
bool bFound = false ;
|
||||
// se richiesto il centro di gravità (baricentro, centroide)
|
||||
// se richiesto il centro di gravità (baricentro, centroide)
|
||||
if ( nSnap == SP_CENTROID) {
|
||||
Point3d ptP ;
|
||||
if ( pSfr->GetCentroid( ptP)) {
|
||||
// il punto di confronto è quello sulla linea di mira a minima distanza dal centro
|
||||
// il punto di confronto è quello sulla linea di mira a minima distanza dal centro
|
||||
Point3d ptCfr = ptRef + (( ptP - ptRef) * vtDir) * vtDir ;
|
||||
// determino la distanza e la confronto con il minimo
|
||||
double dSqDist = SqDist( ptP, ptCfr) ;
|
||||
@@ -851,12 +877,12 @@ Scene::FindSurfFRSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
|
||||
}
|
||||
}
|
||||
}
|
||||
// se richiesto il centro (è il centroide del chunk più vicino)
|
||||
// se richiesto il centro (è il centroide del chunk più vicino)
|
||||
else if ( nSnap == SP_CENTER) {
|
||||
Point3d ptP ;
|
||||
for ( int i = 0 ; i < pSfr->GetChunkCount() ; ++ i) {
|
||||
if ( pSfr->GetChunkCentroid( i, ptP)) {
|
||||
// il punto di confronto è quello sulla linea di mira a minima distanza dal centro
|
||||
// il punto di confronto è quello sulla linea di mira a minima distanza dal centro
|
||||
Point3d ptCfr = ptRef + (( ptP - ptRef) * vtDir) * vtDir ;
|
||||
// determino la distanza e la confronto con il minimo
|
||||
double dSqDist = SqDist( ptP, ptCfr) ;
|
||||
@@ -907,7 +933,7 @@ Scene::FindSurfFRSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fram
|
||||
}
|
||||
}
|
||||
|
||||
// se trovato e modalità shading o hiddenline, la favorisco perchè davanti alle possibili successive
|
||||
// se trovato e modalità shading o hiddenline, la favorisco perchè davanti alle possibili successive
|
||||
if ( bFound && ! ( bAlpha || m_nShowMode == SM_WIREFRAME) && dMinSqDist < SRF_SMALL_SQDIST)
|
||||
dMinSqDist = 0 ;
|
||||
|
||||
@@ -919,7 +945,7 @@ bool
|
||||
Scene::FindVolZmapSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Frame3d& frEnt,
|
||||
const IVolZmap* pVzm, double& dMinSqDist)
|
||||
{
|
||||
// il punto di riferimento deriva da XY su viewport e Z minima (più vicina a osservatore) da selezione
|
||||
// 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 ;
|
||||
@@ -944,13 +970,13 @@ Scene::FindVolZmapSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fra
|
||||
Color cCol ;
|
||||
bool bAlpha = ( m_pGeomDB->GetCalcMaterial( nId, cCol) && cCol.GetIntAlpha() <= ALPHA_LIM) ;
|
||||
|
||||
// se richiesto il centro di gravità (baricentro, centroide)
|
||||
// se richiesto il centro di gravità (baricentro, centroide)
|
||||
if ( nSnap == SP_CENTROID) {
|
||||
Point3d ptP ;
|
||||
bool bFound = false ;
|
||||
BBox3d b3Loc ;
|
||||
if ( pVzm->GetLocalBBox( b3Loc) && b3Loc.GetCenter( ptP)) {
|
||||
// il punto di confronto è quello sulla linea di mira a minima distanza dal vertice
|
||||
// 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) ;
|
||||
@@ -962,7 +988,7 @@ Scene::FindVolZmapSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fra
|
||||
m_bLastSnapDirOk = false ;
|
||||
}
|
||||
}
|
||||
// se trovato e modalità shading o hiddenline, la favorisco perchè davanti alle possibili successive
|
||||
// se trovato e modalità shading o hiddenline, la favorisco perchè davanti alle possibili successive
|
||||
if ( bFound && ! ( bAlpha || m_nShowMode == SM_WIREFRAME))
|
||||
dMinSqDist = 0 ;
|
||||
return bFound ;
|
||||
@@ -972,7 +998,7 @@ Scene::FindVolZmapSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fra
|
||||
ILZIVECTOR vInfo ;
|
||||
if ( ! IntersLineVolZmap( ptMir, vtDir, *pVzm, vInfo))
|
||||
return false ;
|
||||
// se non trovato alcunchè, cerco le linee che partono dagli angoli del rettangolo di mira
|
||||
// se non trovato alcunchè, cerco le linee che partono dagli angoli del rettangolo di mira
|
||||
Vector3d vtWinD( -1, -1, 0) ;
|
||||
for ( int i = 0 ; i < 4 && vInfo.size() == 0 ; ++ i) {
|
||||
// determino punto su vertice del rettangolo di selezione
|
||||
@@ -1001,7 +1027,7 @@ Scene::FindVolZmapSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fra
|
||||
for ( int i = 0 ; i < nTtot ; ++ i) {
|
||||
// triangolo
|
||||
Triangle3d& trTria = vInfo[i].trTria ;
|
||||
// recupero il vertice del triangolo più vicino alla linea di mira
|
||||
// recupero il vertice del triangolo più vicino alla linea di mira
|
||||
int nVert ; double dSqDist ;
|
||||
if ( GetTriaVertexNearestToLine( trTria, ptRef, vtDir, nVert, dSqDist) && dSqDist < dMinSqDist) {
|
||||
bFound = true ;
|
||||
@@ -1021,7 +1047,7 @@ Scene::FindVolZmapSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fra
|
||||
for ( int i = 0 ; i < nTtot ; ++ i) {
|
||||
// triangolo
|
||||
Triangle3d& trTria = vInfo[i].trTria ;
|
||||
// recupero il punto medio del lato del triangolo più vicino alla linea di mira
|
||||
// recupero il punto medio del lato del triangolo più vicino alla linea di mira
|
||||
Point3d ptMid ; double dSqDist ;
|
||||
if ( GetTriaMidEdgeNearestToLine( trTria, ptRef, vtDir, ptMid, dSqDist) && dSqDist < dMinSqDist) {
|
||||
bFound = true ;
|
||||
@@ -1041,9 +1067,9 @@ Scene::FindVolZmapSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fra
|
||||
for ( int i = 0 ; i < nTtot ; ++ i) {
|
||||
// triangolo
|
||||
Triangle3d& trTria = vInfo[i].trTria ;
|
||||
// centro più vicino
|
||||
// centro più vicino
|
||||
Point3d ptCen = trTria.GetCentroid() ;
|
||||
// il punto di confronto è quello sulla linea di mira a minima distanza dal centro
|
||||
// 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) ;
|
||||
@@ -1063,7 +1089,7 @@ Scene::FindVolZmapSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fra
|
||||
case SP_PERP :
|
||||
case SP_MINDIST :
|
||||
// considero solo il primo triangolo intersecato
|
||||
// la distanza è nulla e la confronto con il minimo
|
||||
// la distanza è nulla e la confronto con il minimo
|
||||
if ( 0 < dMinSqDist) {
|
||||
bFound = true ;
|
||||
dMinSqDist = 0 ;
|
||||
@@ -1077,7 +1103,7 @@ Scene::FindVolZmapSnapPoint( int nSnap, const Point3d& ptWin, int nId, const Fra
|
||||
break ;
|
||||
}
|
||||
|
||||
// se trovato e modalità shading o hiddenline, la favorisco perchè davanti alle possibili successive
|
||||
// se trovato e modalità shading o hiddenline, la favorisco perchè davanti alle possibili successive
|
||||
if ( bFound && ! ( bAlpha || m_nShowMode == SM_WIREFRAME) && dMinSqDist < SRF_SMALL_SQDIST)
|
||||
dMinSqDist = 0 ;
|
||||
|
||||
@@ -1265,6 +1291,14 @@ Scene::GetPlaneSnapPoint( const Point3d& ptWin, const Plane3d& plPlane, Point3d&
|
||||
if ( ! UnProject( ptWin, ptLine))
|
||||
return false ;
|
||||
Vector3d vtLine = - m_vtDirCamera ;
|
||||
if ( ! m_bOrthographic) {
|
||||
// nella vista prospettica la direzione di mira è data dalla linea che coingiunge le proiezioni di ptWin sui piani near e far
|
||||
Point3d ptLine2 ;
|
||||
if ( ! UnProject( Point3d( ptWin.x, ptWin.y, 1), ptLine2))
|
||||
return false ;
|
||||
vtLine = ptLine - ptLine2 ;
|
||||
vtLine.Normalize() ;
|
||||
}
|
||||
|
||||
// determino l'intersezione di questa linea con il piano
|
||||
double dDenom = vtLine * plPlane.GetVersN() ;
|
||||
|
||||
Reference in New Issue
Block a user