Sphere.cpp class provides pre-defined functions draw(), drawWithLines() and drawLines(), to draw a sphere using OpenGL VertexArray.īy default, the north pole of the sphere is facing to +Z axis. This example constructs spheres with 36 sectors and 18 stacks, but with different shadings flat, smooth or textured. ![]() If(i != 0) // horizontal lines except 1st stack, k1 => k+1ĭownload: sphere.zip, sphereShader.zip (Updated: ) store indices for lines // vertical lines for all stacks, k1 => k2 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). Sectors and stacks of a sphere 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 ϕ.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |