Jump to content
  • Advertisement
Sign in to follow this  
ProgrammerNr1

point combination (rectangle)

This topic is 5132 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Could anyone explain to me how the the "logic" of the combination of points by creating a rectangle is or works? for example we got 4 points and 6 vertices and we want to create a rectangle. We made it by guessing the combination but we were not able to realize the logic behind it. (especially in which order DX wants the points to be and what should be drawn first (hypotenuse or kathede(spelled right?))?)

Share this post


Link to post
Share on other sites
Advertisement
There are three ways of drawing a rectangle -- triangle list, triangle strip, and triangle fan. The order of the vertices are different for each. Also, there are two ways to break up a rectangle into two triangles, but I'm only going to show one (you can figure out the other).

1 2
+-----------+
|\ |
| \ |
| \ |
| \ |
| \ |
| \|
+-----------+
3 4
The first thing you need to know is the "winding order". When looking at the "front" side of a triangle, the order of the vertices follows the winding order. The normal winding order for D3D is clockwise (CW). The normal winding order for OpenGL is counter-clockwise (CCW). I am going to assume CW.

Triangle list -

A triangle list is simply a list of triangles. The triangles don't need to be adjacent and the their order doesn't matter. You make the list by specifying the three vertices for each triangle according to the winding order. To make the rectangle above using a triangle list, simply list the vertices in this order: 1-4-3-1-2-4. 1-4-3 is the first triangle (4-3-1 or 3-1-4 also work), and the second triangle is 1-2-4 (2-4-1 and 4-1-2 also work).

Triangle strip -

In the triangle list above, you will notice that vertices 1 and 4 were listed twice. A triangle strip is a way of specifying a list of triangles without duplicating vertices. Basically, after the first triangle, each triangle is specified by a vertex combined with the previous two vertices in the strip. The vertices in the first triangle are specified according to the winding order. The triangle strip for the rectangle above is 3-1-4-2. 3-1-4 makes the first triangle and 1-4-2 makes the second triangle. Two things to note: 1. Because each triangle uses the vertices from the previous two triangles, you have to get the order just right. 2. You will notice that the winding order is reversed in every other triangle. The renderer automatically accounts for this.

Triangle fan -

There is another way to order vertices so that you don't have to duplicate them. In a triangle fan, you specify the "root" vertex, then the first vertex of the first triangle, and then every vertex that follows is combined with the first vertex and the previous vertex to make a triangle. Vertexes are specified according to the winding order. The triangle fan for the rectangle above is 1-2-4-3. 1-2-4 makes the first triangle, and 1-4-3 makes the second. 4-3-1-2 would also work.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!