0

there's a func i wrote below that generate a cylinder starting from origin facing y pos with the height of one. How can i make it curve (toward x let's say, it doesn't really matter)?

void DrawCylinder(int sides, int radius)    
{
    double alpha, theta = 2 * PI / sides;
    for (alpha = 0; alpha <= 2 * PI; alpha += theta)
    {
        glColor3d(0.3 + 0.7*fabs(sin(alpha)), 0.3 + 0.7*fabs(sin(alpha)), 0.3 + 0.7*fabs(sin(alpha)));
        glBegin(GL_POLYGON);
        glVertex3d(radius*cos(alpha), 0, radius*sin(alpha)); // point 1
        glVertex3d(radius*cos(alpha), 1, radius*sin(alpha)); // point 2
        glVertex3d(radius*cos(alpha + theta), 1, radius*sin(alpha + theta)); // point 3
        glVertex3d(radius*cos(alpha + theta), 0, radius*sin(alpha + theta)); // point 4     
        glEnd();
    }
}

here's the attempt to treat it as a torus

void DrawCylinder(int sides, double cylinder_radius, int curve, double torus_radius)    
{
    double alpha, theta = 2 * PI / sides;
    double gamma, phi = 2 * PI / curve;

    for (gamma = 0; gamma <= 2*PI; gamma += phi)
    {
        for (alpha = 0; alpha <= 2 * PI; alpha += theta)
        {
            glColor3d(0.3 + 0.7*fabs(sin(alpha)), 0.3 + 0.7*fabs(sin(alpha)), 0.3 + 0.7*fabs(sin(alpha)));
            glBegin(GL_POLYGON);
            glVertex3d((torus_radius + cylinder_radius*cos(alpha))*cos(gamma), cylinder_radius*sin(alpha), (torus_radius + cylinder_radius*cos(alpha))*sin(gamma)); // point 1
            glVertex3d((torus_radius + cylinder_radius*cos(alpha))*cos(gamma + phi), cylinder_radius*sin(alpha + theta), (torus_radius + cylinder_radius*cos(alpha))*sin(gamma + phi)); // point 2
            glVertex3d((torus_radius + cylinder_radius*cos(alpha + theta))*cos(gamma + phi), cylinder_radius*sin(alpha + theta), (torus_radius + cylinder_radius*cos(alpha + theta))*sin(gamma + phi)); // point 3
            glVertex3d((torus_radius + cylinder_radius*cos(alpha + theta))*cos(gamma), cylinder_radius*sin(alpha), (torus_radius + cylinder_radius*cos(alpha))*sin(gamma)); // point 4      
            glEnd();
        }
    }   
}

I should mention, i built it when 4 vertexs drawn at the same time for a reason. I want to dress each polygon with a texture later on thx

Adler
  • 1
  • 1

0 Answers0