OpenGL / GLUT cone surface norms

I created a cone with GL_TRIANGLE_FAN

// draw the upper part of the cone
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0, 0, height);
for (int angle = 0; angle < 360; angle++) {
    glVertex3f(sin(angle) * radius, cos(angle) * radius, 0);
}
glEnd();

// draw the base of the cone
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0, 0, 0);
for (int angle = 0; angle < 360; angle++) {
    // normal is just pointing down
    glNormal3f(0, -1, 0);
    glVertex3f(sin(angle) * radius, cos(angle) * radius, 0);
}
glEnd();

How to get surface normals? For the bottom, I have the right to say that normal just points down?

UPDATE

I tried to use

for (int angle = 0; angle < 360; angle++) {
    glNormal3f(sin(angle), cos(angle), 0);
    glVertex3f(sin(angle) * radius, cos(angle) * radius, 0);
}

But he looks weird from different angles ...

enter image description here

enter image description here

Does the second image look like just one solid color?

+4
source share
1 answer

, h r, (, + Y ), , : ( α). , , h r.

, , h, r. , h Y , r cathetus X. .

Angular and normal coordinates

, , hyponetuse :

(cos(coneAngle), sin(coneAngle))

coneAngle = atan(r / h)

, , 2D, 3D-. XZ.

(cos(circleAngle), 0, sin(circleAngle))

. . Y, (X Z):

(cos(coneAngle) * cos(circleAngle), sin(coneAngle), cos(coneAngle) * sin(circleAngle))

: , , , . , , XY 2D ( ) , ( Y). , XY , :

cos(coneAngle) * (cos(circleAngle), 0, sin(circleAngle)) + sin(coneAngle) * (0, 1, 0)

Update

, , , : c = sqrt(h * h + r * r), , :

n_x / 1 = n_x = h / c

n_y / 1 = n_y = r / c

, :

1/c * (h, r)

, 1/c (h, r).

+7

All Articles