Jump to content
  • Advertisement
Sign in to follow this  
Pirosan

another question about getting information from meshes!! WEE

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

Ok, so i created a function that checks each mesh to see if the player is hitting it (for ground collision only so far) and i made it so i could walk on a simple level. I got a little farther and wanted to implement collision for.. lets say walls or objects in the world. Now this required me to access the mesh and get the vertice information. For a while it wasnt working, what i would do is render another triangle using the 3 vertice coordinates taken from the mesh. I took the grid and broke it up into separate triangles (basically leaving space in between each triangle, so no vertices were ever connected or the same). Then it worked FLAWLESSLY... the triangles lit up and everything. I guess the question is, why is it that i have to separate every single triangle from one another for the retrieval of the polygon information is correct? is it possible that my mesh data is using strips in some cases? i came to that conclusion because before (when the scene wasnt broken up) the triangle would render using vertices from the mesh, but not in the right places, sometimes creating odd looking polygons out of seemingly random vertices taken from the mesh... Any ideas? Chris

Share this post


Link to post
Share on other sites
Advertisement
To save duplicating verts in the vert buffer, the tri information is stored in the index buffer. Each group of 3 WORDs in the index buffer refers to the 3 offsets into the vert buffer corresponding to the 3 verts of that tri. Hence if you where expecting your tri verts to be stored in contiguous groups of 3 in the vert buffer this will cause the seemingly random behaviour you experienced when degenerate verts are present. Hope this clears things up for you.

PS: for efficient collision detection you probably want to be using simple shapes to approximate the render mesh rather than the actual render mesh tris anywho

Share this post


Link to post
Share on other sites
So how would you propose i go about getting the index buffer information and using it to get the correct vertex information in the vertex buffer in the mesh? Im not exactly sure how i would do this.


Chris

Share this post


Link to post
Share on other sites
For example, say you want to get all the verts from tri number 'n'. All the tri vert offsets are stored in the index buffer in blocks of three (three verts per tri). So lock the index buffer and read out the three offsets in the block corresponding to that tri. Then use those offsets to get the correct verts out of the vertex buffer. For example for the nth tri:


WORD* offsets = NULL;
IndexBuffer->Lock(n*3, 3, (void**)&offsets, NULL);

Vertex* verts = NULL;
VertexBuffer->Lock(0, 0, (void**)&verts, NULL);

Vertex triVerts[3];
triVerts[0] = verts[offsets[0]];
triVerts[1] = verts[offsets[1]];
triVerts[2] = verts[offsets[2]];

IndexBuffer->Unlock();
VertexBuffer->Unlock();





See what I mean?? If this is still confusing you I recommend reading the DirectX documentation that comes with the SDK. Hope this sorts your problem

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!