glBegin(GL_QUADS); for(int v = 0; v < numV; v++, v1+=dv){ for(int u = 0; u < numU; u++, u1+=du){ float angle1 = u1 * PI2 + PI * 1.5f; float x1 = cos(angle1) * v1; float y1 = sin(angle1) * v1; float angle2 = (u1 + du) * PI2 + PI * 1.5f; float x2 = cos(angle2) * v1; float y2 = sin(angle2) * v1; float angle3 = u1 * PI2 + PI * 1.5f; float x3 = cos(angle1) * (v1 + dv); float y3 = sin(angle1) * (v1 + dv); float angle4 = (u1 + du) * PI2 + PI * 1.5f; float x4 = cos(angle2) * (v1 + dv); float y4 = sin(angle2) * (v1 + dv); glVertex3f(x1, y1, center[2]); glVertex3f(x2, y2, center[2]); glVertex3f(x3, y3, center[2]); glVertex3f(x4, y4, center[2]); } } glEnd();
...CalcDiskVertex(u, v, center, minRad, maxRad);CalcDiskVertex(u + du, v, center, minRad, maxRad);CalcDiskVertex(u + du, v + dv, center, minRad, maxRad);CalcDiskVertex(u, v + dv, center, minRad, maxRad);...
void CalcDiskVertex( float u, float v, const float center[3], float minRad, float maxRad ){ float angle = u * PI2 - PI / 2; // используем параметр "u" для угла поворота float radius = minRad + (v + 0.5f) * (maxRad - minRad); // используем параметр "v" для радиуса glVertex3f(center[0] + cos(angle) * radius, center[1] + sin(angle) * radius, center[2]); // готовченко!}
void VMMutomo::drwShpere (const float center[3], float radius, int numU, int numV){ if (numU < 1) numU = 1; if (numV < 1) numV = 1; float u1 = -0.5f, v1 = -0.5f; float du = 1.0f / numU; float dv = 1.0f / numV; float shift = radius/2; float startPoint[3] = { center[0] - shift, center[1] - shift, center[2] - shift}; glBegin(GL_QUADS); for(int v = 0; v < numV; v++, v1+=dv){ for(int u = 0; u < numU; u++, u1+=du){ CalcShereVertex(u1, v1, u1, center, radius); CalcShereVertex(u1 + du, v1, u1 + du, center, radius); CalcShereVertex(u1 + du, v1 + dv, u1 + du, center, radius); CalcShereVertex(u1, v1 + dv, u1, center, radius); } } glEnd();}void VMMutomo::CalcShereVertex(float x, float y, float z, const float center[3], float radius){ float ang1 = x * PI2 ; float ang2 = ........; float x1 = center[0] + sin(ang1) * cos(ang2) * radius; float y1 = center[1] + sin(ang1) * sin(ang2) * radius; float z1 = center[2] + cos(ang2) * radius; glVertex3f(x1, y1, z1);}
void CalcShereVertex(float x, float y, float z, const float center[3], float radius){ float ang1 = x * PI2; float ang2 = y * PI; float x1 = center[0] + cos(ang1) * (radius * (-y)); float y1 = center[1] + sin(ang2) * radius; float z1 = center[2] + sin(ang1) * (radius * (-y)); glVertex3f(x1, y1, z1);}
void drwShpere (const float center[3], float radius, int numU, int numV){ if (numU < 1) numU = 1; if (numV < 1) numV = 1; float u1 = -0.5f, v1 = -0.5f; float du = 1.0f / numU; float dv = 1.0f / numV; float shift = radius/2; float startPoint[3] = { center[0] - shift, center[1] - shift, center[2] - shift}; glBegin(GL_QUADS); for(int v = 0; v < numV; v++, v1+=dv){ for(int u = 0; u < numU; u++, u1+=du){ CalcShereVertex(u1, v1, u1, center, radius); CalcShereVertex(u1 + du, v1, u1 + du, center, radius); CalcShereVertex(u1 + du, v1 + dv, u1 + du, center, radius); CalcShereVertex(u1, v1 + dv, u1, center, radius); } } glEnd();}void CalcShereVertex(float x, float y, float z, const float center[3], float radius){ float ang1 = x * PI2; float ang2 = y * PI; float x1 = center[0] + sin(ang2) * cos(ang1) * radius; float y1 = center[1] + sin(ang2) * sin(ang1) * radius; float z1 = center[2] + cos(ang2) * radius; glVertex3f(x1, y1, z1);}
void CalcSphereVertex(float u, float v, const float center[3], float radius){ float ang1 = u * PI2 - PI / 2; float ang2 = v * PI; float x1 = center[0] + cos(ang1) * cos(ang2) * radius; float y1 = center[1] + sin(ang2) * radius; float z1 = center[2] + sin(ang1) * cos(ang2) * radius; glVertex3f(x1, y1, z1);}