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

前端 未结 2 1755
滥情空心
滥情空心 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 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

提交回复
热议问题