Sign in to follow this  

Extracting Triangle from IntersectInformation

This topic is 4712 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

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by yaroslavd
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?

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

Share this post


Link to post
Share on other sites

This topic is 4712 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this