tags:

views:

121

answers:

2

In OpenGL, you can actually draw text with an XYZ position, and it will appear at that location, but in a fixed size.

If anyone's played MechWarrior 2, they used it there for nav points. The text had a 3d position, but it always appeared a fixed size. The nav point was actually a bit of text at that exact point in space.

Other than that the ability to place 3d text was pretty much useless.. you'd always want text to be 2d, righT?

I'm finally in a position where I want this feature. I have these points in space that I need to assign text information to, i.e. I need to draw text at a fixed size but with a 3d position. Can this be done from DirectX?

A: 

Assuming that you are rendering text on a 3d quad, you need to scale the text quad based on the z-distance from the camera. The exact formula depends on your world->view->screen transformation, but it should be easy to calculate by taking the inverse transform of a given height vector, say, (0, 1, 0) in homogenous screenspace coordinates.

EDIT: If all you want is the 2d position on screen, transform the 3d position from world space into screenspace.

MSN
No, I believe what he wants is 2d text (ie. an overlay) whose position is determined by the pixel position of a 3d point.
tloflin
@tloflin yes, exactly,
bobobobo
+1  A: 

ID3DXFont uses a 2D position. However you can use it still. D3DX also comes with a D3DXVec3Project that will allow you to convert a 3D coordinate to a screen position.

Goz
Very good! `// Get the raster pos for the origin` `D3DXVec3Project( ` `printf( "The vertex ended up at (%.2f, %.2f, %.2f)\r", rasterPos.x, rasterPos.y, rasterPos.z ) ;`
bobobobo