**2**

# Vertices Position

###
#1
Members - Reputation: **207**

Posted 11 June 2011 - 07:26 PM

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?

###
#2
Members - Reputation: **169**

Posted 12 June 2011 - 12:46 PM

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.

###
#3
Members - Reputation: **207**

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.

###
#4
Members - Reputation: **169**

Posted 12 June 2011 - 01:45 PM

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

###
#5
Members - Reputation: **207**

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!