我必须计算三角形条的法线,并且遇到一个问题,其他每个三角形都是黑暗的,没有很好的阴影。我正在使用平面阴影模型。我不知道它是否与缠绕方向有关。当我看到三角形条带下面时,我注意到除了黑暗区域或切换之外它与顶部相同。我认为问题可能是我试图计算的表面法线使用共享顶点。如果是这种情况,你会建议切换到GL_TRIANGLES吗?你怎么解决这个问题?
这是我现在所拥有的。三角形类中包含三个Vert对象的triVerts数组。 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();
答案 0 :(得分:0)
我不得不画一个约8-10个面和一些灯光的金字塔,我用三角形来正确点亮。对于每个三角形,我必须计算正常值。这种方式有效。此外,我认为保持顺时针/计数器感应很重要,您可以在其中绘制每个三角形的顶点。我希望它有所帮助。