Sign in to follow this  
lucky6969b

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

Recommended Posts

lucky6969b    1330
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);		  
    //??
}

Share this post


Link to post
Share on other sites
vstrakh    2455

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.

Share this post


Link to post
Share on other sites
HappyCoder    5053
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

Share this post


Link to post
Share on other sites
Endurion    5411

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this