Cycling through triangles in a mesh
Author Message Cycling through triangles in a mesh

How can I cycle through all the triangles of a mesh (3 verticies at a
time)?  I've tried using an index buffer with a vertex buffer with no
success. Any help would be greatly appriciated. Thx,

-Flav

Thu, 10 Feb 2005 13:49:01 GMT  Cycling through triangles in a mesh
do you mean read the data or draw?

to read, you need to lock and step thru the pointer.

to draw, use a triangle list, and then each set of 3 vertices defines a
triangle. this can either be implicit ordering, or explicit ordering using
an index buffer.

iirc, SDK samples do use index buffers so there are examples.

--

Phil Taylor
PM : DirectX SDK, Managed DirectX, Windows XP Inbox 3D screensavers, and a
few more bits and bobs.
http://msdn.microsoft.com/directx
This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:
> How can I cycle through all the triangles of a mesh (3 verticies at a
> time)?  I've tried using an index buffer with a vertex buffer with no
> success. Any help would be greatly appriciated. Thx,

> -Flav

Sat, 12 Feb 2005 02:37:02 GMT  Cycling through triangles in a mesh
Sorry for being unclear; what I ment was how I could cycle through the
vertices of a mesh (either through a vertex buffer or an index buffer)
so that i could apply a collision algorithm using the 3 vertices of a
triangle.  I fixed my vertex buffer so that i can get an array of all
the vertices in a mesh but I don't know how to get a triangle at a
time. I tried:

Dim Tri(2) as VERTEX
For i = 0 to nVertices -1 Step 3
Tri(0) = Vertices(i)
Tri(1) = Vertices(i + 1)
Tri(2) = Vertices(i + 2)
CheckCollision(Tri)
Next i

OR:

For i = 0 to nIndices -1 Step 3
Tri(0) = Vertices(Indices(i))
Tri(1) = Vertices(Indices(i + 1))
Tri(2) = Vertices(Indices(i + 2))
CheckCollision(Tri)
Next i

I've tried both methods but both generated triangles that didn't exist
in the mesh (i.e. the vertices weren't in order).

I apprieciate your help :)

-Flav

Quote:
> do you mean read the data or draw?

> to read, you need to lock and step thru the pointer.

> to draw, use a triangle list, and then each set of 3 vertices defines a
> triangle. this can either be implicit ordering, or explicit ordering using
> an index buffer.

> iirc, SDK samples do use index buffers so there are examples.

> --

> Phil Taylor
> PM : DirectX SDK, Managed DirectX, Windows XP Inbox 3D screensavers, and a
> few more bits and bobs.
> http://msdn.microsoft.com/directx
> This posting is provided "AS IS" with no warranties, and confers no rights.

> > How can I cycle through all the triangles of a mesh (3 verticies at a
> > time)?  I've tried using an index buffer with a vertex buffer with no
> > success. Any help would be greatly appriciated. Thx,

> > -Flav

Sun, 13 Feb 2005 02:08:30 GMT  Cycling through triangles in a mesh
Assuming that the mesh it structured as an indexed triangle list, as it
would be if using the D3DX mesh classes, then the second method is
correct (at least in structure... I'm a C++ junkie, so can't vouch for
the VB syntax, but appears correct).

--
Robert Dunlop
The X-Zone
http://www.mvps.org/directx
Microsoft DirectX MVP
-------------
The opinions expressed in this message are my own personal views and do
not reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation
with Microsoft.

Quote:
> Sorry for being unclear; what I ment was how I could cycle through the
> vertices of a mesh (either through a vertex buffer or an index buffer)
> so that i could apply a collision algorithm using the 3 vertices of a
> triangle.  I fixed my vertex buffer so that i can get an array of all
> the vertices in a mesh but I don't know how to get a triangle at a
> time. I tried:

> Dim Tri(2) as VERTEX
> For i = 0 to nVertices -1 Step 3
>    Tri(0) = Vertices(i)
>    Tri(1) = Vertices(i + 1)
>    Tri(2) = Vertices(i + 2)
>    CheckCollision(Tri)
> Next i

> OR:

> For i = 0 to nIndices -1 Step 3
>    Tri(0) = Vertices(Indices(i))
>    Tri(1) = Vertices(Indices(i + 1))
>    Tri(2) = Vertices(Indices(i + 2))
>    CheckCollision(Tri)
> Next i

> I've tried both methods but both generated triangles that didn't exist
> in the mesh (i.e. the vertices weren't in order).

Fri, 18 Feb 2005 20:14:01 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages
 7. Triangle