This topic is now archived and is closed to further replies.


Help with billboards..

Recommended Posts

Below is a little testfunction i made for drawing a billboard. Unfortunatly the quaddrawn is tilted against the camera in a very odd way and streches all the way from the position to the camera. As I said, odd. Can anyone see some error with the transposematrix, the quad is drawn correctly if use the location_matrix instead of the transpose as the worldmatrix. But then it isn''t facing the camera of course. Hope you can find something. void CGraphics::RenderBillboard(HTEXTURE hTexture, float fX, float fY, float fZ, float fWidth, float fHeight) {      D3DXMATRIX location_matrix, temp_matrix, trans_matrix, view_matrix;      m_v3dVerticies[0].tu          = 0.0f;      m_v3dVerticies[0].tv          = 0.0f;      m_v3dVerticies[0].position     = D3DXVECTOR3(-(fWidth/2), -(fHeight/2), 0.0f);      m_v3dVerticies[0].normal     = D3DXVECTOR3( 0.0f, 0.0f, -1.0f);      m_v3dVerticies[1].tu          = 1.0f;      m_v3dVerticies[1].tv          = 0.0f;      m_v3dVerticies[1].position     = D3DXVECTOR3( (fWidth/2), -(fHeight/2), 0.0f);      m_v3dVerticies[1].normal     = D3DXVECTOR3( 0.0f, 0.0f, -1.0f);      m_v3dVerticies[2].tu          = 0.0f;      m_v3dVerticies[2].tv          = 1.0f;      m_v3dVerticies[2].position     = D3DXVECTOR3(-(fWidth/2),  (fHeight/2), 0.0f);      m_v3dVerticies[2].normal     = D3DXVECTOR3( 0.0f, 0.0f, -1.0f);      m_v3dVerticies[3].tu          = 1.0f;      m_v3dVerticies[3].tv          = 1.0f;      m_v3dVerticies[3].position     = D3DXVECTOR3( (fWidth/2),  (fHeight/2), 0.0f);      m_v3dVerticies[3].normal     = D3DXVECTOR3( 0.0f, 0.0f, -1.0f);      m_p3DDevice->SetTexture(0, m_pTextureList->Get(hTexture));      D3DXMatrixIdentity(&location_matrix);      D3DXMatrixIdentity(&temp_matrix);      D3DXMatrixIdentity(&trans_matrix);      D3DXMatrixIdentity(&view_matrix);      D3DXMatrixTranslation( &location_matrix, fX, fY, fZ);      m_p3DDevice->SetTransform(D3DTS_VIEW, m_pCamera->ViewMatrix());      m_p3DDevice->GetTransform(D3DTS_VIEW,&view_matrix);      D3DXMatrixTranspose(&trans_matrix, &view_matrix);      trans_matrix._41 = location_matrix._41;      trans_matrix._42 = location_matrix._42;      trans_matrix._43 = location_matrix._43;      m_p3DDevice->SetTransform(D3DTS_WORLD, &trans_matrix ;      m_p3DDevice->DrawPrimitiveUP(        D3DPT_TRIANGLESTRIP ,        2,        (void*)&m_v3dVerticies,        sizeof(VERTEX3D)      ; }

Share this post

Link to post
Share on other sites
I am having the exact same problem!!

Here is a screenshot of what it looks like in my program. You might also want to check out this.

If you figure it out on your own, could you please e-mail me at

EDIT - I am bad with html.

Edited by - Moe on June 27, 2001 8:23:16 PM

Share this post

Link to post
Share on other sites
The link lays out exactly what to do!

I would post my code, but I implemented his procedure in a vertex shader, so that would probably just confuse things.

If you search for billboard, matrix, etc. on google there are lots of good pointers.

Share this post

Link to post
Share on other sites
Thank you CrazedGenius, I got it working by using the
code from your link instead of the Transpose-thingy.

Now, let me tell you what I''m using the billboard
technique for. I just playing around with creating
an outdoor game so I have my terrain drawn form a
height field. Well, I didn''t wan''t to create a
level editor so I decided to make an in game level
editor. Each vertex has a star, the billboard, drawn
at it''s place, you can select one of these green stars
and it will be marked as red. Then you move the vertex up
and down by using the mouse. Then you click, and voila,
the height field changes. This way I can run around with
my little character, deciding that there should be a
mountain to the right. To make that I just pause the game
, enter edit mode and create it, then I can climb that

Below are 2 little pictures of the effect at work.
(PS. The game is just a little thing I''m working on
to learn 3D programming so don''t complain to much
about the looks of it.)


Share this post

Link to post
Share on other sites
After you transpose the matrix, you might want to clear out certain parts of it:

D3DXMATRIX matTransposed, matView;

// Get view matrix

pD3DDevice->GetTransform(D3DTS_VIEW, &matView);

// Transpose

D3DXMatrixTranspose(&matTransposed, &matView);

// Clear out portions

matTransposed._14 = matTransposed._24 = matTransposed._34 = 0.0f;

// Add translation coordinates

matTransposed._41 = x;
matTransposed._42 = y;
matTransposed._43 = z;


Share this post

Link to post
Share on other sites
As soon as I added that one line of code that cleared the certain parts of the tranposed matrix, it worked fine. Now how would I stop it from rotating on the x axis (so I can do things like trees, etc)?

Share this post

Link to post
Share on other sites