gpt4 book ai didi

java - 外观呈三角形 strip 。表面法线?还是绕组?

转载 作者:行者123 更新时间:2023-12-02 06:27:33 26 4
gpt4 key购买 nike

下面是我的结果的图片。

我正在使用平面着色,并将每个顶点放入其可尊敬的三角形对象中。然后我使用这些顶点来计算表面法线。我一直在读,因为我的三角形共享相似的顶点,计算法线可能是一个问题?但对我来说,这看起来像是一个绕组问题,因为其他所有绕组都已关闭。

我向任何想要查看代码并更好地了解问题所在的人提供了下面的一些代码。

A triangle strip with

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();

最佳答案

您应该在调用 glVertex3f (...) 之前设置正常的 。调用glVertex*基本上是最终确定顶点的过程,它将当前颜色、法线、纹理坐标等与您传递的位置处的顶点相关联并发出新的顶点。


glVertex — specify a vertex

Description

glVertex commands are used within glBegin / glEnd pairs to specify point, line, and polygon vertices. The current color, normal, texture coordinates, and fog coordinate are associated with the vertex when glVertex is called.

When only x and y are specified, z defaults to 0.0 and w defaults to 1.0. When x, y, and z are specified, w defaults to 1.0.

<小时/>

很有可能是您问题的很大一部分。三角带旨在解决隐式缠绕问题。当您使用 strip 时,您必须反转每个三角形的缠绕顺序,但光栅化器通过翻转每个备用三角形内部用于前/后的缠绕顺序来补偿这一点。

更新:

当然要理解,光栅化器足够智能,可以在使用 strip 时翻转每个交替三角形的前/后绕组,但您的代码不是(至少目前不是)。当您在CPU端计算法线时,您需要补偿交替反向缠绕。

关于java - 外观呈三角形 strip 。表面法线?还是绕组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20386089/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com