


HOW TO DRAW ROPE TEXTYRE CODE
The code snippet to generate all triangles of a sphere may look like If the first vertex index in the current stack is k1 and the next stack is k2, then the counterclockwise orders of vertex indices of 2 triangles are īut, the top and bottom stacks require only one triangle per sector. However, if the shared vertices have different normals or texture coordinates, then a single triangle strip cannot be used.Įach sector in a stack requires 2 triangles. It is possible to use a single triangle strip to render the whole sphere. In order to draw the surface of a sphere in OpenGL, you must triangulate adjacent vertices to form polygons. Vertex indices to draw triangles of a sphere vertex tex coord (s, t) range between Y = xy * sinf(sectorAngle) // r * cos(u) * sin(v) X = xy * cosf(sectorAngle) // r * cos(u) * cos(v) SectorAngle = j * sectorStep // starting from 0 to 2pi // vertex position (x, y, z) Z = radius * sinf(stackAngle) // r * sin(u) // add (sectorCount+1) vertices per stack // the first and last vertices have same position and normal, but different tex coords Xy = radius * cosf(stackAngle) // r * cos(u)

StackAngle = PI / 2 - i * stackStep // starting from pi/2 to -pi/2 For more details, please refer to buildVerticesSmooth() or buildVerticesFlat() functions in Sphere.cpp class.įloat nx, ny, nz, lengthInv = 1.0f / radius // vertex normal It also creates other vertex attributes surface normals and texture coordinates. The following C++ code generates all vertices of the sphere for the given radius, sectors and stacks. The sector and stack angle for each step can be calculated by the following The range of sector angles is from 0 to 360 degrees, and the stack angles are from 90 (top) to -90 degrees (bottom). A point on a sphere using sector and stack anglesĪn arbitrary point ( x, y, z) on a sphere can be computed by parametric equations with the corresponding sector angle θ and stack angle ϕ.
