【问题标题】:Obtaining normal of vertices of torus mesh获取圆环网格顶点的法线
【发布时间】:2011-10-15 18:04:27
【问题描述】:

我正在尝试创建我自己的具有平滑阴影的圆环。然而,正常的似乎是错误的。这是我的代码。

GLfloat NoMat[]             =   {   0.0f,   0.0f,   0.0f,   1.0f    };
GLfloat MatAmbient[]        =   {   0.7f,   0.7f,   0.7f,   1.0f    };
GLfloat MatAmbientColor[]   =   {   0.21f,  0.13f,  0.05f,  1.0f    };
GLfloat MatDiffuse[]        =   {   0.71f,  0.43f,  0.18f,  1.0f    };
GLfloat Shine               =   100.0f; 
GLfloat NoShine             =   0.0f;

glMaterialfv(GL_FRONT, GL_AMBIENT, MatAmbientColor);
glMaterialfv(GL_FRONT, GL_DIFFUSE, MatDiffuse);
glEnable(GL_NORMALIZE);

glMaterialfv(GL_FRONT, GL_SPECULAR, MatAmbient);
glMaterialf(GL_FRONT, GL_SHININESS, Shine);

int i, j, k;
double s, t, x, y, z;

for (i = 0; i < nsides; i++) {
    glBegin(GL_QUAD_STRIP);
    for (j = 0; j <= rings + 1; j++) {
        for (k = 1; k >= 0; k--) { //for both negative and positive
            s = (i + k) % nsides + 0.5;
            t = j % rings;

            x = (totalRadius + centerRadius * cos(s*2*M_PI/nsides)) * cos(t*2*M_PI/rings);
            z = (totalRadius + centerRadius * cos(s*2*M_PI/nsides)) * sin(t*2*M_PI/rings);
            y = centerRadius * sin(s*2*M_PI/nsides);
            glVertex3f(x, y, z);
            glNormal3f(x, y, z);
        }
    }
    glEnd();
}

但是,照明无法正常工作,因为它的行为类似于平面阴影而不是平滑阴影。我做了一些谷歌搜索,但显然我需要使用差异。但是,我不太确定如何做到这一点。有人知道吗?

【问题讨论】:

    标签: opengl vertex differentiation


    【解决方案1】:

    您将顶点位置用于法线?这仅适用于(并且仅适用于)单位半径球体

    您需要计算法线。那就是

    圆环的好处是,您可以在纸上轻松评估它,为您提供精确公式,而不是使用数值近似。

    【讨论】:

      猜你喜欢
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-24
      相关资源
      最近更新 更多