スポンサーリンク
UV球は球を緯度、経度で表現したような球のことを言う。
参考文献に合わせてStep,Sectorで表現すると以下のような関係になる
glm::vec3 getPoint( const int sectorstep, const int sectorCount, const int stackstep, const int stackCount, const float r) { float theta = 2 * 3.14159 * (float(sectorstep) / sectorCount); float phi = 3.14159 / 2.f - 3.14159 * (float(stackstep) / stackCount); float x = (r * cos(phi)) * cos(theta); float y = (r * cos(phi)) * sin(theta); float z = r * sin(phi); return glm::vec3(x, y, z); }
// 球を描画 void draw_uv_sphere(const int stackCount, const int SectorCount,const float r) { for (int stackStep = 0; stackStep < stackCount; stackStep++) { for (int sectorStep = 0; sectorStep < SectorCount; sectorStep++) { glm::vec3 k1 = getPoint(sectorStep, SectorCount, stackStep, stackCount, r); glm::vec3 k2 = getPoint(sectorStep, SectorCount, stackStep + 1, stackCount, r); glm::vec3 k3 = getPoint(sectorStep + 1, SectorCount, stackStep + 1, stackCount, r); glm::vec3 k4 = getPoint(sectorStep + 1, SectorCount, stackStep, stackCount, r); // 四角形で描画 glBegin(GL_LINE_LOOP); glVertex3fv(glm::value_ptr(k1)); glVertex3fv(glm::value_ptr(k2)); glVertex3fv(glm::value_ptr(k3)); glVertex3fv(glm::value_ptr(k4)); glEnd(); /* k1 k1+1 (k4) +-------+ | /| | / | | / | | / | | / | | / | |/ | +-------+ k2 k2+1 (k3) */ } } }
http://www.songho.ca/opengl/gl_sphere.html