Transforming object world space matrix to a position in world space
- by Fredrik Boston Westman
Im trying to make a function for picking objects with a bounding sphere however I have run in to a problem.
First I check against my my bounding sphere, then if it checks out then I test against the vertexes. I have already tested my vertex picking method and it work fine, however when I check first with my bounding sphere method it dosnt register anything. My conclusion is that when im transform my sphere position in to the position of the object in world space, the transformation goes wrong ( I base this on the fact the the x coordinate always becomes 1, even tho i translate non of my meshes along the x-axis to 1). So my question is:
What is the proper way to transform a objects world space matrix to a position vector ?
This is how i do it now:
First i set my position vector to 0.
XMVECTOR meshPos = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
Then I trannsform it with my object space matrix, and then add the offset to the center of the mesh.
meshPos = XMVector3TransformCoord(meshPos, meshWorld) + centerOffset;