TonyJZ / opengl-tesselation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction

This simple application is used to test opengl tesselation method as I'm looking to use it to solve my problem which is cutting off holes from polygon.

Context

The context is I have polygons described by contours (outter boundarty). Some polygons contain holes which are also described by contours. Some hole contours are inside polygon but some are intersected with polygon contour. The requirement is cutting off holes from polygon and export the correct triangles.

Tessellation

The Polygon Tessellation in opengl can be found here.

When I added it in my project, I can not get correct results for some polygons. For example, Type 1

      h4---h1                q0------------q3
      |     |                |   h4---h1    |
  q0------------q3           |   |     |    |
  |   |     |    |           q1------------q2
  |   h3---h2    |               |     |
  q1------------q2               h3---h2

Type 2

      h4---h1                q0--h4---h1---q3
      |     |                |   |     |    |
  q0------------q3           |   |     |    |
  |   |     |    |           q1------------q2
  |   |     |    |               |     |
  q1--h3---h2---q2               h3---h2

I can get correct results for Type 1 polygons but failed for Type 2 polygons. For Type 2 polygons, I usually get results like below. Seems the winding number is wrong. (see winding rules)

    h4---h1                   hi---hj
    |     |                   |     |
    hi---hj                   h3---h2

I found this ORIGINAL CODES from SONHO's website and added a function tessellate4 to test my polygon cases. Finally I solved this problem by using gluTessNormal which specifying the normal for Tessellator, very senseful but less examples can be found talking about it.

Who may be interested in this application

If you are

  • looking for a method to generate polygon with holes,
  • looking for a method to implement polygon CSG operations,
  • or just very curious about tesselation.

Some instructions for Windows lover

To run this application on Windows, you need MinGW-w64, freeglut, and glew.

A good reference for the installation is here.

About


Languages

Language:C 54.9%Language:C++ 45.1%