Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

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

This topic is 1094 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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.

Share this post


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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!