void RenderNumber() {
D3DXVECTOR3 pos(0.0f, 20.0f, 0.0f);
D3DXMATRIX matW;
D3DXMatrixTransformation(&matW, NULL, NULL, NULL, NULL, NULL, &pos);
matW = matW * m_matWorld;
d3d::m_pDevice->SetTransform(D3DTS_WORLD, &matW);
//??
}
How can I draw a numbered bullet point above the agent?
Assuming you want to draw 2d sprite, not affected by camera's rotation and perspective projection.
First you take bullet location in world, say, +something by Y axis to agent location.
Transform it with camera's ModelViewProjection matrix. In resulting vector divide xyz elements with its w element.
You got normalized device coordinates for bullet. X/Y will directly correspond to coordinates within viewport, ranging [-1; 1]
Now you can render bullet with orthographic projection built for gui. Which will it be - NDC or pixels in window, depends on your preferences.
vstrakh described what you could do if you wanted to make the number appear as if it were a gui on the screen
The key word here is billboarding. You can either do it vstrakhs way, which will project the 3d pos on the screen. This way the bullet will be in front of every 3d object.
Or you want a triangle/quad, that's parallel to the screen surface, but still placed in the 3d world really above the object.
My code for calculating the billboard matrix is this. Pass in the used view matrix and the wanted location in 3d space. If you set the resulting matrix as world matrix you can then draw a 3d object that's oriented parallel to the screen with 0,0 being the position you passed in:
matrix4& Billboard( const matrix4& matView, const GR::tVector& vectPos )
{
*this = matView;
Transpose();
ms._14 = ms._24 = ms._34 = 0.0f;
//position the billboard
ms._41 = vectPos.x;
ms._42 = vectPos.y;
ms._43 = vectPos.z;
return *this;
}