Created
April 8, 2014 15:26
-
-
Save dpasca/10142521 to your computer and use it in GitHub Desktop.
indicized sphere from cylinder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------- | |
// setup geometry | |
const static u_int NDIV_PHI = 20; | |
const static u_int NDIV_THE = 20; | |
mPosBase.reserve( NDIV_PHI * NDIV_THE ); | |
auto &geom = *moBaseMesh->mpGeom; | |
geom.mNor.reserve( mPosBase.size() ); | |
for (u_int i=0; i != NDIV_PHI; ++i) | |
{ | |
float v = (float)i / (NDIV_PHI-1); | |
float phi = DLerp( 0.f, FM_PI, v ); | |
for (u_int j=0; j != NDIV_THE; ++j) | |
{ | |
float u = (float)j / NDIV_THE; | |
float the = DLerp( 0.f, 2*FM_PI, u ); | |
Float3 v1( sinf( phi ) * cosf( the ), | |
cosf( phi ), | |
sinf( phi ) * sinf( the ) ); | |
mPosBase.push_back( v1 ); | |
geom.mNor.push_back( DE3::MakeNormal(v1) ); | |
} | |
} | |
mPosTemp.resize( mPosBase.size() ); | |
auto &idxs = geom.mPrims.mIndices; | |
idxs.reserve( NDIV_PHI * NDIV_THE * 2*3 ); | |
for (u_int i=0; i != (NDIV_PHI-1); ++i) | |
{ | |
u_int iBase = i*NDIV_THE; | |
for (u_int j=0; j != NDIV_THE; ++j) | |
{ | |
u_int i00 = iBase + j; | |
u_int i01 = iBase + (j == NDIV_THE-1 ? 0 : j+1); | |
idxs.push_back( i00 + 0*NDIV_THE ); | |
idxs.push_back( i01 + 1*NDIV_THE ); | |
idxs.push_back( i00 + 1*NDIV_THE ); | |
idxs.push_back( i00 + 0*NDIV_THE ); | |
idxs.push_back( i01 + 0*NDIV_THE ); | |
idxs.push_back( i01 + 1*NDIV_THE ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment