What are the normals for 3d cube as used in OpenGL ES?

前端 未结 2 1756
滥情空心
滥情空心 2021-02-09 03:19

I have a cube defined as :

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


        
相关标签:
2条回答
  • 2021-02-09 03:59

    The normal of a surface is simply a direction vector. Since the normal will be the same for two surfaces that are coplanar, you will only need 6 surface normals. However, often, it's the case that normals are expected to be defined per vertex, in which case you'll need 36 (one for each vertex of each triangle on each face of the cube).

    To compute the normals, simply use the following calculation: http://www.opengl.org/wiki/Calculating_a_Surface_Normal

    0 讨论(0)
  • 2021-02-09 04:05

    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.

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

    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

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

    0 讨论(0)
提交回复
热议问题