2
votes

i am trying to learn how to do lighting in opengl 2.0. i have a cube which is located on (0,0,0), and the camera is on (0,0,20). at the vertices i manually added all the necessary information and when i got to the normals, i just looked at the cube from the camera prespective, suggesting that the front face normal will be (0,0,-1) and the back face normal (0,0,1). also, the right face is (1,0,0), left - (-1,0,0), top - (0,1,0), bottom - (0,-1,0);

now, the problem is, that if i switch the front and back normals, it works. but i just don't understand.. the same logic i used for all the other normals (which works as is) mean that the front SHOULD be (0,0,-1).. but evidently i'm wrong.. i just don't get it..

1

1 Answers

1
votes

You said:

[...] a cube which is located on (0,0,0) [...] the camera is on (0,0,20) [...]

The normal vector of the front face must point from the cube to the camera. The vector from the cube to the camera is (0, 0, 20). Therefore the normal vector of the front face must be (0, 0, 1).

In general, in the OpenGL view space coordinate system, the Z axis points out of the view. The view space coordinate system is Right-handed system, where the X-axis points to the right and the Y-axis points up. The Z-axis points out of the view, because the Z-Axis is given by the cross product of the X-Axis and the Y-Axis.