how to find postion of a mesh

Started by
2 comments, last by RabblePants 18 years, 5 months ago
i have my mesh in 3d, when i render it to the screen lets say i want to put text next to it obviously text is 2d. so is there a way to find the 2d coords of a 3d mesh. using directx and c++
Advertisement
By 2D coords you mean 2D screen coords? If that's the case, then it should be fairly simple. Taking the position of the 3D Mesh you can just transform that with your World-View-Projection matrix. Then take the x/y components and remap that to your screen coords.

Keep in mind that the transformed pos will be in the range of -1 to +1 for x, y and z. In other words, if x is -1, it's on the leftmost side of the screen, and if it's +1 it's on the rightmost side of the screen. Same applies to the y.
so once i do the transformations your saying i can place my text like this?


font.print("TEST", mesh.getXPos(), mesh.GetYPos() );
Essentially yes. You'll just have to figure out how to remap the coordinates resulting from the WorldViewProj transformation into screenspace. Lemme know if you have problems =)

This topic is closed to new replies.

Advertisement