Specifying the order of a triangle strip?

Started by
17 comments, last by GroZZleR 20 years, 2 months ago
quote:
When I get verticies like these:
-1, 0.5, 1 (A)
-0.5, 0.5, 1 (B)
-0.5, 0.5, -1 (C)
-1, 0.5, -1 (D)

And I order them, it does come out to
A B
C D


The vertex ordering is flawed.

Note that if we read in the vertices (x,y,z), the ones youve produced up there will be:

A--------B
|*******|
|*******|
D--------C

And thats where the problem lies..... the two triangles overlap..... moreover DX draws vertices anticlockwise, which means the first triangle wont draw at all.

For the order youve shown above try the two below

IB = { A,D,B,B,D,C }
The above one works if its anticlockwise ordering
The one below if its clockwise ordering
IB = { A,B,D, D,B,C }

Try em both....

Prasan


[edited by - psamty10 on February 8, 2004 12:18:36 AM]

[edited by - psamty10 on February 8, 2004 12:19:05 AM]
Advertisement
A wimpier way to do it is:

pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

This sets off backface culling so that vertex ordering doesnt matter
First and foremost, thank you very much for your help psamty10, you've been invaluable. But now I've quite a little quirk, I'm curious about.

Heres output, right from my quad class as I set up the vertices. My vertices are ordered like this:

-1	0.5	1-0.5	0.5	1-0.5	0.5	-1-1	0.5	-1


As (you've corrected), that comes out to:
A B
D C

But when I use the CCW method you've described below:
IB = { A,D,B,B,D,C }

Which is clearly counter-clockwise (unless I don't know the clock as well as I think I do), but with the cullmode set to CCW, it culls out the frontfaces and draws the back faces? I can tell this because my boxes are now being rendered inverted (I'm sure you know what I mean).

If I set the cullmode to CW, then it renders just fine.

And oddly enough, if I setup the other method you've described here:
IB = { A,B,D, D,B,C }

And turn the cull mode to CCW, then it renders just fine, even though those verticies are being drawn in a CW manner.

Does this lead me to change my thinking on how backface culling works? That it culls in the opposite? The backfaces of the frontfaces would be drawn in the opposite order of the way they're drawn, correct?

So if you draw in CW, the backfaces are CCW, and they're the ones that are culled out?

I was always under the impression that it culled the backface of the frontfaces that are drawn in the culled method.

If you can follow =P

Anyone have some input here?

[edited by - GroZZleR on February 9, 2004 1:49:38 AM]
Keep in mind that different APIs order their vertices differently.

The real way to think about it is that the normal is projected outwards from the face drawn (either CW or CCW DEPENDING on the API being used).

Back face culling removes faces with normals facing AWAY from the camera.

It doesnt cull the back face OF the front faces.
A face is either a BACK face OR a FRONT face - not both.

[edited by - psamty10 on February 9, 2004 1:54:45 AM]
I don''t currently calculate the normal, I figured that was just for lighting. My FVF only specifies 3 points and a colour.

Once I calculate the normals and add that to FVF, will I find I might have to re-order the drawing order?
DX calculates the normal, even if you dont.
The Normal is usually not calculated at all actually, its interpolated using the 3 verts
Ah, alright.

Thanks a lot psamty10, good luck in your future projects =)
If your wanting to do more complicated geometry as well then you want to just remder traingles (lists) with an index buffer like said above. That''ll make life much easier. I had a good link to a site on index buffers but I haven''t got it with me - typical. I''ll try and find it out.
I found this really useful - it only applies to the draw indexed primative comand but it's a reall good tutorial.

http://bellsouthpwp.net/d/f/dfrey69/dip.htm

I credit the person who wrote it (someone on these forums) cus it really helped me out.

I also recomend you try using the draw indexed primative comadn to try drawing each triangle individually and try other things like checking the IB and the VB to make sure the right data's there. It may take a bit of fiddeling but it'll be worth doing.

Good Luck!

[edited by - de_matt on February 9, 2004 7:51:40 AM]

This topic is closed to new replies.

Advertisement