Triangulation

Member
Posts: 129
Joined: 2005.02
Post: #1
I'm looking down several routes for a project I am starting. I'm starting to create a small 3d engine for a game I want to make. Strolling some of the message boards on the net, I have decided that I want to render everything as triangle strips.

For now, I have resorted to OBJ files. However, obj files may contain quads ( among others ), and not soley triangles. I'd rather not muck with the model files, and would rather post-process the models from quads ( or which ever polygon ) into triangles, so that they may be processed into tristrips ( hopefully I can use NvTripStrips without a lot of work--or at least thats my objective ).

So, the basic OBJ loading is easy. Can someone point me into a good direction to learn how to triangulate the vertices in a face?

Also, I'm looking for any input as far as the method I am using. Does this seem bad?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
The most reliable method is to triangulate the models before you save them, its not a bad thing to put some restraints on the type of object your loading, as long as you provide appropriate error messages in the case that its data you dont want to handle.
Trianglulating polygons could be done in different ways so you may not always get the results you want from the algorithm, when loading from a file this becomes a problem of the model, not the engine.

If you are going to triangulate, this is a really really good program
http://www.cs.cmu.edu/~quake/triangle.html

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #3
Using triangle strips for everything seems like it would be cripplingly limited. You probably just want to go with GL_TRIANGLES.

Triangulating a polygon is pretty easy. Just sit down with a piece of paper, label the vertices from 0 to n, and work out which three vertices you would need to use to construct each triangle with the appropriate winding order. From there, it should be pretty clear how to implement it.
Quote this message in a reply
Hog
Member
Posts: 151
Joined: 2002.09
Post: #4
ThemsAllTook Wrote:Using triangle strips for everything seems like it would be cripplingly limited. You probably just want to go with GL_TRIANGLES.

i second that. you'd most probably have to check what polygons are adjacent to each other in order to wrap triangle strips around them, you'd also have to find a path which connects them in order to make full use of triangle strips. i'd recomend against using 1 triangle strip for each polygon also. what you probably want to do is something like:
Code:
for each polygon
    for i to polygon.size-3
       append the triangle with vertices (0,i+1,i+2) of the polygon to some sort of list or array
Quote this message in a reply
Post Reply