0

我试图让我的照明在 OpenGL 中工作,使用 LWJGL 作为实现库。我认为我遇到的问题是我没有正确设置我的法线,因此照明在某些角度不起作用。这是我正在测试的多维数据集的代码:

glBegin(GL_QUADS);

glColor3f(r,g,b);

glNormal3f(position.x, position.y, position.z - radius - 0.1f);
glVertex3f(position.x + radius, position.y + radius, position.z - radius);
glVertex3f(position.x + radius, position.y - radius, position.z - radius);
glVertex3f(position.x - radius, position.y - radius, position.z - radius);
glVertex3f(position.x - radius, position.y + radius, position.z - radius);

glNormal3f(position.x, position.y, position.z + radius + 0.1f);
glVertex3f(position.x + radius, position.y + radius, position.z + radius);
glVertex3f(position.x + radius, position.y - radius, position.z + radius);
glVertex3f(position.x - radius, position.y - radius, position.z + radius);
glVertex3f(position.x - radius, position.y + radius, position.z + radius);

glNormal3f(position.x - radius - 0.1f, position.y, position.z);
glVertex3f(position.x - radius, position.y + radius, position.z + radius);
glVertex3f(position.x - radius, position.y - radius, position.z + radius);
glVertex3f(position.x - radius, position.y - radius, position.z - radius);
glVertex3f(position.x - radius, position.y + radius, position.z - radius);

glNormal3f(position.x + radius + 0.1f, position.y, position.z);
glVertex3f(position.x + radius, position.y + radius, position.z + radius);
glVertex3f(position.x + radius, position.y - radius, position.z + radius);
glVertex3f(position.x + radius, position.y - radius, position.z - radius);
glVertex3f(position.x + radius, position.y + radius, position.z - radius);

glNormal3f(position.x, position.y - radius - 0.1f, position.z);
glVertex3f(position.x + radius, position.y - radius, position.z + radius);
glVertex3f(position.x - radius, position.y - radius, position.z + radius);
glVertex3f(position.x - radius, position.y - radius, position.z - radius);
glVertex3f(position.x + radius, position.y - radius, position.z - radius);

glNormal3f(position.x, position.y + radius + 0.1f, position.z);
glVertex3f(position.x + radius, position.y + radius, position.z + radius);
glVertex3f(position.x - radius, position.y + radius, position.z + radius);
glVertex3f(position.x - radius, position.y + radius, position.z - radius);
glVertex3f(position.x + radius, position.y + radius, position.z - radius);

glEnd();
4

1 回答 1

1

法线向量是相对于顶点本身的并且总是归一化的(即:它们的长度为 1)。

所以,像这样的一行:

glNormal3f(position.x, position.y, position.z - radius - 0.1f);

应替换为:

glNormal3f(0.0f, 0.0f, 1.0f);
于 2013-03-09T21:54:45.773 回答