Confusing result in calculating normals

46 Views Asked by At

I am working on a 3D graphics engine and one thing that is important is defining a "front" face and a "back" face of triangles that I define.

A convention is, that the vertices of the triangle should be arranged in a way, that is counter-clockwise to the observer. That way, I can calculate a normal vector, which will always point toward the observer, as long as I arrange the points counter-clockwise from that observer's view.

Here is an example:

Let's say in a 3D coordinate system, an observer (Let's just say the observer is located at (0,0,1) is looking down in the direction (0,0,-1) at a triangle with the vertices (0,0,0), (0,1,0) and (1,0,0).

Now if I wanted that triangle's front face facing the observer, I would have to arrange the vertices in an order, that is counter-clockwise to the observer. For example:

a = (0,0,0) b = (1,0,0) c = (0,1,0)

Then I can calculate the normal vector like this using the cross product:

normal calculation

The resulting normal vector is (0,0,1). In this case, this normal vector is directly opposed to the viewing direction of (0,0,-1), which makes sense, since the observer is looking down at the front face of the triangle and the normal vector faces outward of the front face of that triangle.

My problem is with this scenario:

The observer is located at (2,4,3) and is looking down at a direction of (0,-1,0).

The vertices of the triangle are (0,-1,0), (1,-1,1) and (1,-1,0).

Here is a small sketch:

sketch

Now, from this view, I arrange the vertices in a counter-clockwise way, like this:

a = (0,-1,0) b = (1,-1,0) c = (1,-1,1)

I would expect the normal vector, similar to the previous example, to be directly opposed to the viewing direction, since the view plane and the plane defined by the triangle are parallel, but the resulting normal vector (calculated the same way as in the previous example) is (0,-1,0)! That's the exact same as the viewing direction! Which means the camera is actually looking at the back side of the triangle.

Why?

I arranged the vertices in a manner, that is counter-clockwise to the observer, so why is the observer facing the backside and not the front side?