- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
下面是我的结果的图片。
我正在使用平面着色,并将每个顶点放入其可尊敬的三角形对象中。然后我使用这些顶点来计算表面法线。我一直在读,因为我的三角形共享相似的顶点,计算法线可能是一个问题?但对我来说,这看起来像是一个绕组问题,因为其他所有绕组都已关闭。
我向任何想要查看代码并更好地了解问题所在的人提供了下面的一些代码。
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*
基本上是最终确定顶点的过程,它将当前颜色、法线、纹理坐标等与您传递的位置处的顶点相关联并发出新的顶点。
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/
所以昨天我写了 WaveFront .obj 3D 模型加载器,它现在工作正常(虽然不支持所有内容)所以我写了简单的测试来在屏幕上绘制任何 3D 模型,在我为场景添加照明之前一切正常.光出现了,但法线
我的代码(用 C++ 编码)在处理更新模型法线的 for 循环中存在瓶颈。我用来测试的模型有大约 ~2.2k 个顶点(指示),工作正常并且在 60 fps 限制下工作,但法线与指示器(~12k)一样多
我无法将法线和 u,v 对发送到我的着色器。如果我删除法线,一切都会按预期进行。 编辑看起来 v_normal 正在接收用于 v_coord 的值。我仍然不知道。/编辑 这是我的顶点: struct
我正在寻找一种方法来获取矩形的所有顶点,该矩形的中心、法线、长度和高度我都知道。我的数学有点弱所以请帮助我。编辑:飞机在 3D 空间中。 最佳答案 通过从中心点的 x/y 位置减去/加上宽度/高度的一
是否可以从片段着色器内访问表面法线(与片段平面相关的法线)?或者也许这可以在顶点着色器中完成? 当我们沿着着色器管道走下去时,相关几何体的所有知识是否都会丢失,或者是否有一些巧妙的方法可以在片段着色器
我无法使用 VBO 正确渲染法线。下面是我正在使用的代码,顶点是一个包含顶点的数组,法线是一个包含法线的数组: //Create the buffers and such GLuint VBOID;
我已经有了这个不再那么小的基于图 block 的游戏,这是我的第一个真正的 OpenGL 项目。我想将每个图 block 渲染为 3D 对象。因此,首先我创建了一些对象,例如立方体和球体,为它们提供了
我正在尝试添加一个垂直于我单击的面的框(称为“标记”)。 为此,单击时,我会转换一条射线,如果它击中某些物体,我会获取法线的交点值并将它们传输到“标记”作为其旋转值。在问这个问题之前,我阅读了这个答案
这与另一个问题(那里的图像)中描述的问题有关: Opengl shader problems - weird light reflection artifacts 我有一个 .obj 导入器,它创建一
我正在尝试制作一个在 OpenGL 2.1 和 Qt5 中渲染的简单 map 。但我在非常基本的问题上失败了。我在这里展示的是表面法线。 我有 4 个由单个三角形几何体组成的对象。一个简单的几何图形是
我正在开发一个类似 JavaScript/Canvas 3D FPS 的引擎,迫切需要一个法线向量(如果您愿意,也可以是观察向量)来进行近平面和远平面裁剪。我有 x 轴和 y 轴旋转 Angular
我正在编写用于在我的 DirectX 应用程序中存储、加载和渲染静态网格的类。 我知道 Box 模型可以使用 8 个顶点,但通常它使用 24 或 36 个(因为一个“空间中的顶点”实际上是 3 个具有
我无法使 phong 着色看起来正确。我很确定我的 OpenGL 调用或我加载法线的方式有问题,但我想这可能是其他问题,因为 3D 图形和 Assimp 对我来说都还很陌生。尝试加载 .obj/.mt
我是一名优秀的程序员,十分优秀!