# Extracting Triangle from IntersectInformation

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

## Recommended Posts

Hi, guys. I'm stumped about how to find the actual triangle from an IntersectionInformation instance, which only gives you the index of the triangle. I was thinking of extracting the VB from the Mesh object and Locking it. However, how do I find the nth triangle? Thanks in advance. BTW, I'm using C# and MDX.

##### Share on other sites
Triangle n can be found by locking both the index buffer and the vertex buffer. Use the index of the triangle given to you by your intersection method. Use this to find the indices of your trianlge.

v0 = pVertexBuffer[pIindexBuffer[n*3+0]]
v1 = pVertexBuffer[pIindexBuffer[n*3+1]]
v2 = pVertexBuffer[pIindexBuffer[n*3+2]]

So now v0, v1, and v2 contain the vertices of the triangle that was intersected. Of course, this assumes that the variables "pVertexBuffer" and "pIndexBuffer" are arrays refering to your vertex and index data respectively. You can get these by locking the vertex and index buffers of your mesh.

neneboricua

##### Share on other sites
So like this?

CustomVertex.PositionNormalColored[] v = mesh.LockVertexBuffer(typeof(CustomVertex.PositionNormalColored),LockFlags.NoOverwrite,new int[]{1});int[] i = mesh.LockIndicesBuffer(typeof(int),LockFlags.NoOverwrite,new int[]{1});Vector3 v0 = v[i[3*index+0]].GetPosition;Vector3 v1 = v[i[3*index+1]].GetPosition;Vector3 v2 = v[i[3*index+2]].GetPosition;

Also, this returns the coordinates in mesh space, right?

##### Share on other sites
Pretty much. I'm not familiar with Managed DX but that seems correct. Just remember to unlock both your vertex and index buffers when you're done accessing the triangle information.

The coordinates will be in mesh space. So if you want to know where in world space your triangle is, you'll need to transform the vertices of the triangle by the mesh's World matrix.

neneboricua

##### Share on other sites
Thanks. Oh, and one more question, if you don't mind. Do you know if the origin of the Mesh returned by Mesh.Sphere is at the center of the sphere?

##### Share on other sites
Quote:
 Original post by yaroslavdThanks. Oh, and one more question, if you don't mind. Do you know if the origin of the Mesh returned by Mesh.Sphere is at the center of the sphere?

More than likely. In general, the artist working on a model defines what the "origin" of the model is. In the case of a sphere the mesh origin is probably the center of the sphere.

neneboricua

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633298
• Total Posts
3011256
• ### Who's Online (See full list)

There are no registered users currently online

×