//---------------------------------------------------------------------------- // EgalTech 2024 //---------------------------------------------------------------------------- // File : SbzSphere.cpp Data : 14.02.2024 Versione : 2.6b2 // Contenuto : Implementazione di funzioni per creazione di superfici Sbz // standard : Box, Pyramid, Cylinder, Sphere, Cone. // // // Modifiche : 14.02.2024 DB Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "CurveArc.h" #include "SurfTriMesh.h" #include "SurfBezier.h" #include "/EgtDev/Include/EGkSbzStandard.h" using namespace std ; //------------------------------------------------------------------------------- ISurfBezier* CreateBezierSphere( const Point3d& ptCenter, double dR) { // creo una superficie di Bezier di grado 2 con 45 punti di controllo PtrOwner pSrfBez( CreateSurfBezier()) ; int nDegU = 2 ; int nDegV = 2 ; int nSpanU = 4 ; // i poli della sfera sono a coordinate ( 0,0,-R) e ( 0,0,R) int nSpanV = 2 ; bool bRat = true ; double dW = SQRT2 ; pSrfBez->Init(nDegU, nDegV, nSpanU, nSpanV, bRat) ; // polo inferiore // dW = 1, dW = SQRT2 / 2 for ( int i = 0 ; i < 9; ++i) { if ( i % 2 == 0) dW = 1 ; else dW = SQRT2 / 2 ; pSrfBez->SetControlPoint( i, 0, ptCenter + Point3d( 0, 0, -dR), dW) ; } // definisco la gabbia esterna // dW = SQRT2 / 2, dW = 1 / 2 // parto dal punto ( 0,-dR, -dR) e completo riga per riga double dH = -dR ; for ( int j = 1 ; j < 4 ; ++j ) { Vector3d vtDir ( 0, -dR, 0) ; Point3d pt(-dR,-dR,dH) ; for ( int i = 0; i < 9 ; ++i ) { // ogni due punti ruoto di 90 gradi a sinistra if ( i%2 == 0) { vtDir.Rotate( Z_AX, 90) ; if ( j%2 == 1) dW = SQRT2 / 2 ; else dW = 1 ; } else { if ( j%2 == 1) dW = 1. / 2. ; else dW = SQRT2 / 2 ; } pt += vtDir ; pSrfBez->SetControlPoint( i, j, ptCenter + pt, dW) ; } dH += dR ; } // polo superiore // dW = 1, dW = SQRT2 / 2 for ( int i = 0 ; i < 9; ++i) { if ( i % 2 == 0) dW = 1 ; else dW = SQRT2 / 2 ; pSrfBez->SetControlPoint( i, 4, ptCenter + Point3d( 0, 0, dR), dW) ; } return Release( pSrfBez) ; }