【发布时间】:2018-06-25 01:34:49
【问题描述】:
我是 openGL 4.5 的新手,目前正在使用灯光,在几何绘图期间计算顶点法线时一切正常,但现在我必须计算圆锥的面法线,我不知道该怎么做它。我正在用 GL_TRIANGLE_STRIP 绘制它。我们可以在下面看到当前的sn-p:
float coneAngle = (float) Math.atan(radius / height);
coneCos = (float) Math.cos(coneAngle);
coneSin = (float) Math.sin(coneAngle);
// circleResolution * heightResolution * 3
for(int i = 0; i <= circleResolution; i++)
{
for(int j = 0; j <= heightResolution; j++)
{
angle = 2 * ((float) Math.PI) * (i / (float) circleResolution);
cos = ((float) Math.cos(angle));
sin = ((float) Math.sin(angle));
x = radius * cos;
z = radius * sin;
// Cone Bottom
vertices.add(x);
vertices.add(0.0f);
vertices.add(z);
// Cone Bottom Normal
vertices.add(coneCos * cos);
vertices.add(coneSin);
vertices.add(coneCos * sin);
// Cone Top
vertices.add(0f);
vertices.add(height);
vertices.add(0f);
// Cone Top Normal
vertices.add(0f);
vertices.add(0f);
vertices.add(0f);
}
}
// Center of Bottom Circle - Vertices
vertices.add(0.0f);
vertices.add(0.0f);
vertices.add(0.0f);
// Center of Bottom Circle - Normal
vertices.add(0.0f);
vertices.add(-1.0f);
vertices.add(0.0f);
// CircleResolution - Bottom Circle - TRIANGLE_FAN
for (int j = 0; j <= circleResolution; j++)
{
angle = (2 * ((float) Math.PI)) * ( j / (float) circleResolution );
x = (float) Math.cos(angle);
z = (float) Math.sin(angle);
vertices.add(radius * x);
vertices.add(0.0f);
vertices.add(radius * z);
// Normal
vertices.add(0.0f);
vertices.add(-1.0f);
vertices.add(0.0f);
}
【问题讨论】:
-
锥体有面吗?你的意思是一个近似圆锥的多边形?请准确。
-
是的,我的意思是近似圆锥的多边形。我添加了我当前多边形的图片。