MCPcopy Create free account
hub / github.com/ImageEngine/cortex / SpherePrimitive

Method SpherePrimitive

src/IECoreGL/SpherePrimitive.cpp:52–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50IE_CORE_DEFINERUNTIMETYPED( SpherePrimitive );
51
52SpherePrimitive::SpherePrimitive( float radius, float zMin, float zMax, float thetaMax )
53 : m_radius( radius ), m_zMin( zMin ), m_zMax( zMax ), m_thetaMax( thetaMax ), m_vertIdsBuffer( nullptr )
54{
55 // figure out bounding box
56
57 thetaMax = m_thetaMax/180.0f * M_PI;
58 float minX = m_radius * ( thetaMax < M_PI ? cosf( thetaMax ) : -1.0f );
59 float maxY = m_radius * ( thetaMax < M_PI/2 ? sinf( thetaMax ) : 1.0f );
60 float minY = m_radius * ( thetaMax > 3 * M_PI/2 ? -1.0f : min( 0.0f, sinf( thetaMax ) ) );
61 m_bound = Imath::Box3f( V3f( minX, minY, m_zMin * m_radius ), V3f( m_radius, maxY, m_zMax * m_radius ) );
62
63 // build vertex attributes for P, N and st, and indexes for triangles.
64
65 IECore::V3fVectorDataPtr pData = new IECore::V3fVectorData;
66 IECore::V3fVectorDataPtr nData = new IECore::V3fVectorData;
67 IECore::V2fVectorDataPtr uvData = new IECore::V2fVectorData;
68 m_vertIds = new IECore::UIntVectorData;
69
70 vector<V3f> &pVector = pData->writable();
71 vector<V3f> &nVector = nData->writable();
72 vector<V2f> &uvVector = uvData->writable();
73 vector<unsigned int> &vertIdsVector = m_vertIds->writable();
74
75 float oMin = asinf( m_zMin );
76 float oMax = asinf( m_zMax );
77 const unsigned int nO = max( 4u, (unsigned int)( 20.0f * (oMax - oMin) / M_PI ) );
78
79 thetaMax = m_thetaMax/180.0f * M_PI;
80 const unsigned int nT = max( 7u, (unsigned int)( 40.0f * thetaMax / (M_PI*2) ) );
81
82 for( unsigned int i=0; i<nO; i++ )
83 {
84 float v = (float)i/(float)(nO-1);
85 float o = lerp( oMin, oMax, v );
86 float z = m_radius * sinf( o );
87 float r = m_radius * cosf( o );
88
89 for( unsigned int j=0; j<nT; j++ )
90 {
91 float u = (float)j/(float)(nT-1);
92 float theta = thetaMax * u;
93 V3f p( r * cosf( theta ), r * sinf( theta ), z );
94 uvVector.push_back( V2f( u, v ) );
95 pVector.push_back( p );
96 nVector.push_back( p );
97 if( i < nO - 1 && j < nT - 1 )
98 {
99 unsigned int i0 = i * nT + j;
100 unsigned int i1 = i0 + 1;
101 unsigned int i2 = i0 + nT;
102 unsigned int i3 = i2 + 1;
103 vertIdsVector.push_back( i0 );
104 vertIdsVector.push_back( i1 );
105 vertIdsVector.push_back( i2 );
106 vertIdsVector.push_back( i1 );
107 vertIdsVector.push_back( i3 );
108 vertIdsVector.push_back( i2 );
109 }

Callers 15

testNameSanitisationMethod · 0.45
testUntypedPrimsMethod · 0.45
testScopeMethod · 0.45
testCustomAttributesMethod · 0.45
writeSCCMethod · 0.45
writeWalkMethod · 0.45

Calls 1

writableMethod · 0.45

Tested by 15

testNameSanitisationMethod · 0.36
testUntypedPrimsMethod · 0.36
testScopeMethod · 0.36
testCustomAttributesMethod · 0.36
writeWalkMethod · 0.36