• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Vertices Position

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1DJTN  Members

Posted 11 June 2011 - 07:26 PM

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?

### #2pekarn  Members

Posted 12 June 2011 - 12:46 PM

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.

### #3DJTN  Members

Posted 12 June 2011 - 01:31 PM

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.

### #4pekarn  Members

Posted 12 June 2011 - 01:45 PM

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.

### #5DJTN  Members

Posted 12 June 2011 - 02:02 PM

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!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.