Getting vertex position at certain point

Started by
6 comments, last by BornToCode 11 years, 10 months ago
How do I get a mesh vertex position at a certain point?
Advertisement
This all depends on how your mesh is stored, what language you are using, and what you wish to achieve by this. Can you elaborate on what you wish to achieve, and which language you are using so members here can more easily answer.

Aimee.

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

I am using C++ and DirectX 9.

Thanks,
Please explain a little bit what do you mean by "at a certain point".
I have a terrain, I want to get the terrain vertex top Y axis based on X, Y axis, so I can move a character for example over the terrain.
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.
Can you please post code sample?

Thanks,
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.

This topic is closed to new replies.

Advertisement