Smooth cone normals
Asked Answered
S

2

3

I'm trying to calculate smooth normals for a cone. In looking around for code samples and explanations, I consistently come across directions for face normals. I've posted a couple pictures below of what I'm doing. The first -- which basically just normalizes the vertex position -- gives me decently smooth shading, but the edges are "missing" and the bottom face isn't solid. The second has edges, but the shading is flat (face normals) and my light isn't reflecting off of them correctly.

The cone is built out of GL_TRIANGLES.

Click the images for larger versions.


(source: bantherewind.com)


(source: bantherewind.com)

Symphonia answered 26/8, 2012 at 6:35 Comment(0)
H
2

At any point on the surface of a cone except the apex, there are two obvious kinds of tangent vectors: one tangent to the cross-sectional circle, or one up the slope. If you express the surface as a parametric equation with two parameters, you can get these tangent vectors as the two partial derivatives. Take the cross product of the tangents, and you get a normal vector. The order of the product determines whether the normal points inward or outward. Of course, the bottom face must be handled separately.

Hematuria answered 26/8, 2012 at 7:17 Comment(2)
Thanks, this is working and is a lot simpler than what I was trying. For the bottom face, I just normalized the vector from the tip to the center of the face.Symphonia
This looks right to me now: bantherewind.com/uploads/cone_normals_fixed.pngSymphonia
T
1

In addition to the answer by JWWalker I'd like to point out, that a vertex is a whole tuple of vector, that among other things includes position and normal. So if you have different normals at a single position, you got there different and multiple vertices.

In the case of the cone this is important, because the tip of the cone is not one single vertex, but a whole set of them (one tip vertex for each triangle the cone's coat. And then for the base circle you got at each position two vertices, the one for the triangle to the tip, and one for the base surface.

Both the tip and the edge are discontinuities and hence call for a be drawn using separate vertices.

Toinette answered 26/8, 2012 at 10:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.