Pro OpenGL ES for iOS

(singke) #1

CHAPTER 5: Textures (^161)
//The second one
float phi1 = M_PI ((float)(phiIdx+1) (1.0/(float)«
(m_Stacks)) - 0.5);
float cosPhi0 = cos(phi0);
float sinPhi0 = sin(phi0);
float cosPhi1 = cos(phi1);
float sinPhi1 = sin(phi1);
float cosTheta, sinTheta;
//Longitude
for(thetaIdx=0; thetaIdx < m_Slices; thetaIdx++)
{
//Increment along the longitude circle each "slice."
float theta = -2.0M_PI ((float)thetaIdx) «
(1.0/(float)(m_Slices-1));
cosTheta = cos(theta);
sinTheta = sin(theta);
//We're generating a vertical pair of points, such
//as the first point of stack 0 and the first point«
// of stack 1above it. This is how TRIANGLE_STRIPS work,
//taking a set of 4 vertices and essentially drawing«
// two triangles at a time. The first is v0-v1-v2 and«
the next is
// v2-v1-v3 etc. Get x-y-z for the first vertex of«
stack.
vPtr[0] = m_Scale
cosPhi0 cosTheta;
vPtr[1] = m_Scale
sinPhi0m_Squash;
vPtr[2] = m_Scale
(cosPhi0 sinTheta);
//The same but for the vertex immediately above the«
previous one.
vPtr[3] = m_Scale
cosPhi1 cosTheta;
vPtr[4] = m_Scale
sinPhi1m_Squash;
vPtr[5] = m_Scale
(cosPhi1 sinTheta);
//Normal pointers for lighting.
nPtr[0] = cosPhi0
cosTheta;
nPtr[2] = cosPhi0 sinTheta;
nPtr[1] = sinPhi0;
nPtr[3] = cosPhi1
cosTheta;
nPtr[5] = cosPhi1 sinTheta;
nPtr[4] = sinPhi1;
if(tPtr!=nil) //4
{
GLfloat texX = (float)thetaIdx
«

Free download pdf