How can I draw a numbered bullet point above the agent?

Started by
2 comments, last by Endurion 8 years, 6 months ago
I want to draw a bullet point above the agent to indicate which object is which. How do I draw that number right above where the agent is at? Thanks Jack
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);		  
    //??
}
Advertisement

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.

You will want to have a texture with the numbers on the texture, then just create a quad with the texture coordinates mapped to show the number you want they draw that quad.

vstrakh described what you could do if you wanted to make the number appear as if it were a gui on the screen
My current game project Platform RPG

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;
    }

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement