# Vertices Position

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

## Recommended Posts

I’m trying to merge 2 meshes together and I’ve run into a problem. When adding the second mesh’s vertices to the new Vertex Buffer I need to set the vertices positions and normals based off the mesh’s position, scale and rotation in the world. I thought the vector3’s Transform Coordinate and Transform Normal would do the trick using the second mesh’s World Transform Matrix but I’m getting unexpected results.

What is the proper way to set a mesh’s vertices/normals to maintain its current position, scale and rotation when adding them to a new VertexBuffer?

##### Share on other sites
After transforming the vertices with the world transform of the second mesh you also need to transform them with the inverted world transform of the first mesh to get them in lcoal space for the first mesh. If you don't know how to invert a matrix look at D3DXMatrixInvert.
To speed up the process you could multiply the two matrices with each other after you invert the matrix. That way you only need to transform with one matrix (the result of the multiply) when transforming the vertices.

##### Share on other sites

After transforming the vertices with the world transform of the second mesh you also need to transform them with the inverted world transform of the first mesh to get them in lcoal space for the first mesh. If you don't know how to invert a matrix look at D3DXMatrixInvert.
To speed up the process you could multiply the two matrices with each other after you invert the matrix. That way you only need to transform with one matrix (the result of the multiply) when transforming the vertices.

Thanks Pekarn - I was already doing that but the position of the second mesh is still incorrect. I get the scaling and rotation correctly of the second mesh but the position is incorrect.

My world matrix for all mesh is: scale X rotation(pitch) X rotation(yaw) X position.

I take the world matrix for mesh1 and invert it. Then I multiple it by the world matrix of mesh2.

When setting the vertex position I use the transform coordinate function with the current vertex's position and the Matrix I created above. Still the positioning is incorrect.

Any idea's as to why the position is wrong? It appears to always be very close to mesh1 even if I place mesh2 far away.

##### Share on other sites
Keep in mind that the order of multiplication matters when multiplying the two matrices. I think it should be mesh1 X mesh2 but it might be the other way around, make sure you try both. Also try it without multiplying the matrices, do the transforms one after the other just to make sure you get the same results.

It would be useful if you could post some code to better see exactly what you are doing.

##### Share on other sites

Keep in mind that the order of multiplication matters when multiplying the two matrices. I think it should be mesh1 X mesh2 but it might be the other way around, make sure you try both. Also try it without multiplying the matrices, do the transforms one after the other just to make sure you get the same results.

It would be useful if you could post some code to better see exactly what you are doing.

That was it Pekarn. I reversed the multiplication from (mesh1 matrix X mesh2 matrix) to (mesh2 matrix X mesh1 matrix) and it works. Theres a small percission issue but I think that's coming from the tranform coord funtion.

Thanks again Pekarn!