Files
EgtGraphics/SceneGeom.cpp
T
Dario Sassi 1636334642 EgtGraphics :
- versioni release con ottimizzazione /Ox ;
- varie migliorie.
2014-02-13 18:14:35 +00:00

109 lines
3.5 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : SceneGeom.cpp Data : 10.02.14 Versione : 1.5b1
// Contenuto : Implementazione della gestione geometria della classe scena.
//
//
//
// Modifiche : 10.02.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- 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/EgtPointerOwner.h"
#include "/EgtDev/Include/EGkGdbIterator.h"
#include "/EgtDev/Include/EGkCurve.h"
using namespace std ;
//------------------------------ Constants -----------------------------------
const int OGLMAT_DIM = 16 ;
//----------------------------------------------------------------------------
bool
FrameToOpenGlMatrix( const Frame3d& frFrame, double Matrix[OGLMAT_DIM])
{
if ( frFrame.GetType() == Frame3d::ERR)
return false ;
Matrix[0] = frFrame.VersX().x ;
Matrix[1] = frFrame.VersX().y ;
Matrix[2] = frFrame.VersX().z ;
Matrix[3] = 0 ;
Matrix[4] = frFrame.VersY().x ;
Matrix[5] = frFrame.VersY().y ;
Matrix[6] = frFrame.VersY().z ;
Matrix[7] = 0 ;
Matrix[8] = frFrame.VersZ().x ;
Matrix[9] = frFrame.VersZ().y ;
Matrix[10] = frFrame.VersZ().z ;
Matrix[11] = 0 ;
Matrix[12] = frFrame.Orig().x ;
Matrix[13] = frFrame.Orig().y ;
Matrix[14] = frFrame.Orig().z ;
Matrix[15] = 1 ;
return true ;
}
//----------------------------------------------------------------------------
bool
Scene::DrawGroup( int nId)
{
// recupero il riferimento del gruppo
Frame3d frFrame ;
if ( ! m_pGeomDB->GetGroupFrame( nId, frFrame))
return false ;
// se non è identità, lo imposto nello stack delle matrici MODELVIEW di OpenGL
bool bMatrix = ( frFrame.GetType() != Frame3d::TOP || ! frFrame.Orig().IsSmall()) ;
if ( bMatrix) {
glPushMatrix() ;
double Matrix[OGLMAT_DIM] ;
if ( FrameToOpenGlMatrix( frFrame, Matrix))
glMultMatrixd( Matrix) ;
}
// creo un iteratore
PtrOwner<IGdbIterator> pIter( CreateGdbIterator()) ;
if ( ! ::IsValid( pIter))
return false ;
// scandisco il gruppo
pIter->SetGDB( m_pGeomDB) ;
bool bNext = pIter->GoToFirstInGroup( nId) ;
while ( bNext) {
int nGdbType = pIter->GetGdbType() ;
if ( nGdbType == GDB_GEO) {
const ICurve* pCurve ;
// se curva, la emetto
if ( ( pCurve = GetCurve( pIter->GetGeoObj())) != nullptr) {
bool bFound ;
PolyLine PL ;
Point3d ptP ;
pCurve->ApproxWithLines( 0.1, 5, PL) ;
glBegin( GL_LINE_STRIP) ;
for ( bFound = PL.GetFirstPoint( ptP) ; bFound ; bFound = PL.GetNextPoint( ptP)) {
glVertex3f( (GLfloat)ptP.x, (GLfloat)ptP.y, (GLfloat)ptP.z) ;
}
glEnd() ;
}
}
else if ( nGdbType == GDB_GROUP) {
if ( ! DrawGroup( pIter->GetId()))
return false ;
}
bNext = pIter->GoToNext() ;
}
// se necessario, ripristino lo stack delle matrici
if ( bMatrix)
glPopMatrix() ;
return true ;
}