Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a set of planar polygons in 3D space defined by their vertices in counterclockwise order. Let's define the 'positive face' as being the face of the 3D polygon such as when observed, the vertices appear in counterclockwise order, and the 'negative face', the face which when observed, the vertices appear in clockwise order.

I'm doing perspective projection of the set of polygons onto a projection polygon defined by the points in this order: (0, h, 0), (0, 0, 0), (w, 0, 0), and (w, h, 0), where w and h are strictly positive integers. The positive face of this projection polygon is oriented towards positive Z, and the camera point is somewhere at (0, 0, d), where d is a strictly negative number.

In order to 'clip' the projected polygons into the projection polygon, I'm applying the Greiner-Hormann (PDF) clipping algorithm, which requires that the clipper and the to-be-clipped polygons be in the same order (i.e. clockwise or counterclockwise).

My question is the following:

How can I determine whether the projected face of the 3D polygon is the negative or the positive one? Meaning, how do I find out if I have to work with the vertices in normal or inverted order for the algorithm to work?

I noticed that only if the 3D polygon is facing the projection polygon with its negative face, both of them are in the same order (counterclockwise), otherwise, a modification needs to be done.

Here is a picture (PNG) that illustrates this.

Note that the planes described by the polygon from the set and the projection polygon may not always be parallel.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Given three points of the polygon in normal order p0, p1, p2

  1. Calculate the direction of the normal of the plane the triangle defined by points p0, p1, p2 lies in:

    normal_direction = cross(p0 - p1, p2 - p1)
    

    Do it for both polygons, the projection polygon and the 3D polygon in question

  2. Take the dot product of the normal of both polygons. if the dot-product is bigger or equal 0, both are in the same order. If it is smaller than zero, you need to inverse the order of the points.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.