OpenGL ES中使用的3d立方体的法线是什么? [英] What are the normals for 3d cube as used in OpenGL ES?

查看:93
本文介绍了OpenGL ES中使用的3d立方体的法线是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定义为的多维数据集:

I have a cube defined as :

  float vertices[] = {
            //Vertices according to faces
                -1.0f, -1.0f, 1.0f, //Vertex 0
                1.0f, -1.0f, 1.0f,  //v1
                -1.0f, 1.0f, 1.0f,  //v2
                1.0f, 1.0f, 1.0f,   //v3

                1.0f, -1.0f, 1.0f,  //...
                1.0f, -1.0f, -1.0f,         
                1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, -1.0f,

                1.0f, -1.0f, -1.0f,
                -1.0f, -1.0f, -1.0f,            
                1.0f, 1.0f, -1.0f,
                -1.0f, 1.0f, -1.0f,

                -1.0f, -1.0f, -1.0f,
                -1.0f, -1.0f, 1.0f,         
                -1.0f, 1.0f, -1.0f,
                -1.0f, 1.0f, 1.0f,

                -1.0f, -1.0f, -1.0f,
                1.0f, -1.0f, -1.0f,         
                -1.0f, -1.0f, 1.0f,
                1.0f, -1.0f, 1.0f,

                -1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f,           
                -1.0f, 1.0f, -1.0f,
                1.0f, 1.0f, -1.0f,
                                    };

此多维数据集的法线是什么?我需要法线的实际值.

What are the normals for this cube? I need the actual values for the normals.

我们需要6个或12个法线吗?由于OpenGL ES仅使用三角形,这意味着我们需要12个法线,但我可能是错的.

Do we need 6 or 12 normals? Since OpenGL ES uses only triangles which means we need 12 normals but I could be wrong.

推荐答案

法线是针对每个顶点指定的,并且由于共享每个顶点的三个面的法线是正交的,因此,通过指定一个只有8个顶点的立方体,然后对三个面法线取平均值,以得到顶点法线.它会被阴影化为一个球体,但形状像一个立方体.

Normals are specified per-vertex, and since the normals for the three faces that share each vertex are orthogonal, you'll get some really wonky looking results by specifying a cube with just 8 vertices and averaging the three face normals to get the vertex normal. It'll be shaded as a sphere, but shaped like a cube.

您将需要指定24个顶点,因此绘制多维数据集的每个面时不会与其他顶点共享顶点.

You'll instead need to specify 24 vertices, so each face of the cube is drawn without sharing vertices with any other.

至于价值观,很容易死.如果我们假设x向右增加,y随着上移而增加,z随着向前移动而增加,则右侧的法线为(1、0、0),左侧的法线为(-1、0, 0),顶边是(0,1,0),依此类推,等等

As to the values, 'tis dead easy. If we assume that x increases to the right, y increases as we go up, and z increases as we move forwards, the normal for the right-hand side is (1, 0, 0), left is (-1, 0, 0), top side is (0,1,0), etc, etc

总结:不要画一个立方体,只画6个恰好具有重合顶点的四边形

To summarise: don't draw a cube, draw 6 quads that just happen to have coincident vertices

这篇关于OpenGL ES中使用的3d立方体的法线是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆