# Getting vertex position at certain point

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

## Recommended Posts

How do I get a mesh vertex position at a certain point?

##### Share on other sites
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.

##### Share on other sites
I am using C++ and DirectX 9.

Thanks,

##### Share on other sites
Please explain a little bit what do you mean by "at a certain point".

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
Can you please post code sample?

Thanks,

##### Share on other sites
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. Edited by BornToCode

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633660
• Total Posts
3013222
×