How do I get a mesh vertex position at a certain point?
Getting vertex position at certain point
Started by Medo3337, Jun 03 2012 04:49 PM
7 replies to this topic
Sponsor:
#6 Members - Reputation: 589
Posted 04 June 2012 - 08:59 AM
All the vertices info are store into your VertexBuffer. You can lock the vertexbuffer with a ReadOnly Flag and extract the vert you need. So for example if your vertex info is 3d position only therefore your vertex stride would be 12 bytes per vertex so doing simple math you can extract the vertex you want. For example if you want to extract vertex 2 you can just do 2*stride to get the pointer to point to the second vertex. I hope that helps, if you have any more question feel free to let me know.
Edited by BornToCode, 04 June 2012 - 09:00 AM.
#8 Members - Reputation: 589
Posted 05 June 2012 - 10:24 AM
It is very simple. The function that locks your vertexbuffer retursn an void* which is the address of the first element of your vertex. So if you do this
float* addr = (float*)vBuffer->Lock(); addr will point to the x element of your first vertex. To point to any vertex just multiply by the vertex index you want * whatever the sizeof one vertex is in your vertex buffer. From there using simple pointer arihmetic and dereferecing you should be able to get the values.
float* addr = (float*)vBuffer->Lock(); addr will point to the x element of your first vertex. To point to any vertex just multiply by the vertex index you want * whatever the sizeof one vertex is in your vertex buffer. From there using simple pointer arihmetic and dereferecing you should be able to get the values.
Edited by BornToCode, 05 June 2012 - 10:25 AM.






