1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
void Cylinder::draw()
{
int lats = 20;
int longs = 20;
float sliceLats;
float sliceLongs;
sliceLats = 2.0f * PI / lats;
sliceLongs = PI / longs;
glTranslatef(this->center->X(), this->center->Y(), this->center->Z()); // ligne problematique
glScalef(this->radius, this->radius, this->radius);
glBegin(GL_QUADS);
for (int i = 0; i <= longs; i++)
{
float y0 = cos(i * sliceLongs);
float y1 = cos((i + 1) * sliceLongs);
for (int j = 0; j <= lats; j++)
{
float x0 = sin(j * sliceLats);
float x1 = sin((j + 1) * sliceLats);
float z0 = cos(j * sliceLats);
float z1 = cos((j + 1) * sliceLats);
float x2 = sin(j * sliceLats);
float x3 = sin((j + 1) * sliceLats);
float z2 = cos(j * sliceLats);
float z3 = cos((j + 1) * sliceLats);
glColor3f((float)(i + j) / (float)(lats + longs), (float)(i + j) / (float)(lats + longs), (float)(i + j) / (float)(lats + longs));
glVertex3f(x0, y0, z0);
glVertex3f(x1, y0, z1);
glVertex3f(x3, y1, z3);
glVertex3f(x2, y1, z2);
}
}
glEnd();
} |
Partager