我必须计算三角形条带的法线,并且遇到了一个问题,即每个其他三角形都是深色的,并且着色不好。我用的是平帘模型。我不知道这是否与缠绕方向有关。当我看三角形条带下面时,我注意到它和顶部是一样的,除了黑暗区域或切换。我认为问题可能是我试图计算的曲面法线使用了共享顶点。如果是这种情况,您是否建议切换到GL_TRIANGLES?你将如何解决这个问题?
这是截至目前我所拥有的。三角形类有一个triVerts数组,其中有三个Vert对象。Vert对象具有变量x、y和z。
Triangle currentTri = new Triangle();
int triPointIndex = 0;
List<Triangle> triList = new ArrayList<Triangle>()
GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
int counter1 = 0;
float stripZ = 1.0f;
float randY;
for (float x=0.0f; x<20.0f; x+=2.0f) {
if (stripZ == 1.0f) {
stripZ = -1.0f;
} else { stripZ = 1.0f; }
randY = (Float) randYList.get(counter1);
counter1 += 1;
GL11.glVertex3f(x, randY, stripZ);
Vert currentVert = currentTri.triVerts[triPointIndex];
currentVert.x = x;
currentVert.y = randY;
currentVert.z = stripZ;
triPointIndex++;
System.out.println(triList);
Vector3f normal = new Vector3f();
float Ux = currentTri.triVerts[1].x - currentTri.triVerts[0].x;
float Uy = currentTri.triVerts[1].y - currentTri.triVerts[0].y;
float Uz = currentTri.triVerts[1].z - currentTri.triVerts[0].z;
float Vx = currentTri.triVerts[2].x - currentTri.triVerts[0].x;
float Vy = currentTri.triVerts[2].y - currentTri.triVerts[0].y;
float Vz = currentTri.triVerts[2].z - currentTri.triVerts[0].z;
normal.x = (Uy * Vz) - (Uz * Vy);
normal.y = (Uz * Vx) - (Ux * Vz);
normal.z = (Ux * Vy) - (Uy * Vx);
GL11.glNormal3f(normal.x, normal.y, normal.z);
if (triPointIndex == 3) {
triList.add(currentTri);
Triangle nextTri = new Triangle();
nextTri.triVerts[0] = currentTri.triVerts[1];
nextTri.triVerts[1] = currentTri.triVerts[2];
currentTri = nextTri;
triPointIndex = 2;
}
}
GL11.glEnd();
我必须画一个有8-10个面和一些照明的金字塔,我使用三角形来正确照明。对于每个三角形,我都必须计算法线。它就是这样工作的。此外,我认为重要的是要保持顺时针/逆时针方向,为每个三角形绘制顶点。我希望它能有所帮助。