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.
Do we need 6 or 12 normals? Since OpenGL ES uses only triangles which means we need 12 normals but I could be wrong.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With