147964cf6a
- Cubetto - Assi - Griglia - Zoom.
308 lines
10 KiB
C++
308 lines
10 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : SceneGlobFrame.cpp Data : 02.12.14 Versione : 1.5l1
|
|
// Contenuto : Implementazione gestione e disegno terna di riferimento globale.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 02.12.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#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)
|
|
{
|
|
m_bShowGlobFrame = 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)
|
|
{
|
|
// se non devo disegnare, esco subito
|
|
if ( ! m_bShowGlobFrame)
|
|
return true ;
|
|
|
|
// recupero la matrice viewport
|
|
GLint Viewport[ 4] ;
|
|
glGetIntegerv( GL_VIEWPORT, Viewport) ;
|
|
|
|
// imposto il riferimento
|
|
glPushMatrix() ;
|
|
|
|
// imposto l'origine del sistema di riferimento nelle coordinate della ViewPort
|
|
Point3d ptOrig ;
|
|
const double POS_Z = 0.25 ;
|
|
UnProject( Point3d( m_dFrame_DistX, m_dFrame_DistY, POS_Z), ptOrig) ;
|
|
|
|
// abilito Ztest per rendering delle linee e dei punti
|
|
glEnable( GL_DEPTH_TEST) ;
|
|
|
|
// 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) ;
|
|
glBegin( GL_LINES) ;
|
|
glColor3f( m_cColX.GetRed(), m_cColX.GetGreen(), m_cColX.GetBlue()) ;
|
|
glVertex3f( float( ptOrig.x + dOrigOff), 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)) ;
|
|
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)) ;
|
|
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 lo stack delle matrici
|
|
glPopMatrix() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
|