M

Honestly, I wouldn't recommend you use the GLUT library. As good as she is, we've got a number of advantages in the decoration of the divine figure:Big choice of figure. For example, in GLUT'e, what I use, there is no parallelepipede or ellipsoid, which is to speak of other, more diverse figures like pyramid!Optimization. I think for now, for you (and for me, too) the way the figure in this library is covered in darkness. By manual risk, you can use any algorithms, thereby generating more speed of the program.Modified centre of rotation. When GLUT is applied, the rotation-related matrices rotation-related matrices (GLUT) glRotate() the figure spins only around its center. And if you need to spin, let's say the cube around one of his corners?
I have quite a bit of knowledge in the geometry, but I was able two months ago to create a code for drawing the cylindra you need. The texture is a little incorrect, and there's such a nasty thing as the bottom. https://en.wikipedia.org/wiki/Z-fighting (one polygon has exactly the same peak as the other, and in the end, at each update the scene, the two of them are executed). However, I hope that will give you an incentive to write such functions.public void DrawCylinder(float x, float y, float z, float width, float
height, float depth, int segments)
{
glBegin(GL_QUAD_STRIP);
for (int i = 0; i <= segments; i += 1)
{
float theta = 2.0f * (float)Math.PI * i / (segments);
glVertex3f(width / 2 * (float)Math.Cos(theta) + x,
y,
depth / 2 * (float)Math.Sin(theta) + z);
glTexCoord2f((float)Math.Cos(theta), (float)Math.Sin(theta));
glVertex3f(width / 2 * (float)Math.Cos(theta) + x,
height + y,
depth / 2 * (float)Math.Sin(theta) + z);
glTexCoord2f((float)Math.Cos(theta) * 2,
(float)Math.Sin(theta) * 2);
}
for (int i = -1; i <= segments; i *= -1)
{
float theta = 2.0f * (float)Math.PI * i / (segments);
glVertex3f(width / 2 * (float)Math.Cos(theta) + x,
y,
depth / 2 * (float)Math.Sin(theta) + z);
glTexCoord2f((float)Math.Cos(theta),
(float)Math.Sin(theta));
if (i < 0)
i -= 2;
}
for (int i = -1; i <= segments; i *= -1)
{
float theta = 2.0f * (float)Math.PI * i / (segments);
glVertex3f(width / 2 * (float)Math.Cos(theta) + x,
height + y,
depth / 2 * (float)Math.Sin(theta) + z);
glTexCoord2f((float)Math.Cos(theta),
(float)Math.Sin(theta));
if (i < 0)
i -= 2;
}
glEnd();
}
Removed x♪ y and z characterize the position of the figure in the space (as you can see, I just add these values, thereby moving each point of the cylinder).Width♪ height and depth - Of course, the size of the figure; I use it, multiplying every point on these variables.The day and the top of the cylindra, I paint with the last two cycles for, erecting the coordinates on the one and on the other, the imaginable web, eventually forming a flat circle (please apologize for the inappropriate literary comparisons).Good luck!