Skip to main content
gamedev.net
🔒 Locked

Billboarding Problem

Started by MattCarpenter Jul 31, 2002 at 10:42 PM 4 replies 450+ views
Original Post
MattCarpenter
MattCarpenter
I'm making a game where I have a couple hundred trees made from 2d quads. I tried to billboard them with this code, but they seem to get stretched out really high and really messed up. m_pD3DDevice->GetTransform(D3DTS_VIEW,&view_matrix); D3DXMatrixTranslation(&location_matrix,x,y,z); D3DXMatrixTranspose(&trans_matrix,&view_matrix); world_matrix=trans_matrix; //Now we plug in the location values into our world matrix. world_matrix._41 = location_matrix._41; world_matrix._42 = location_matrix._42; world_matrix._43 = location_matrix._43; m_pD3DDevice->SetTransform(D3DTS_WORLD,&world_matrix); Whats wrong with this code? thanks /\/\att [edited by - mattcarpenter on July 31, 2002 12:23:10 AM]
//att
Pactuul
Pactuul
trying inversing the matrix instead of tranposing...
-Pac "The thing I like about friends in my classes is that they can't access my private members directly." "When listening to some one tell about their problem (whether it's code or not), don't listen to what went right or wrong, but what they assumed....."
TitanDirtBag
TitanDirtBag
have you tried looking at d3d8sdk? i think there''s one.. or nehe try to grab some ideas.

hope that helps
StuartSlater
StuartSlater
Microsoft produce some excellent code in the billboard example of the SDK have adapted it myself to remove all of the class stuff if your interested let me know.

Stu
StuartSlater
StuartSlater
Heres the code I use

struct TREEVERTEX
{
D3DXVECTOR3 position; // Vertex position
D3DXVECTOR3 normal;
DWORD color; // Vertex color
FLOAT tu, tv; // Vertex texture coordinates
};

LPDIRECT3DVERTEXBUFFER8 m_pTreeVB; // Vertex buffer for rendering a tree
LPDIRECT3DTEXTURE8 m_pTreeTextures[3]; // Tree images


void setuptree (void)
{

DWORD colour=RGB(255,255,255);

DXTigerPage.D3DDevice->CreateVertexBuffer(4*sizeof(CUSTOMVERTEX),0,
D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED,&m_pTreeVB);

CUSTOMVERTEX* pVertices;
if( FAILED( m_pTreeVB->Lock( 0, 0, (BYTE**)&pVertices, 0 ) ) )
MessageBox(NULL,"Could not Lock Vertex Buffer","ERROR DETECTED",MB_OK);


pVertices[0].position = D3DXVECTOR3(-1.0f, -1.0f, 0.0f);
pVertices[0].normal = D3DXVECTOR3(0.0f, 0.0f, -1.0f);
pVertices[0].color = colour;
pVertices[0].tu = 0.0f;
pVertices[0].tv = 1.0f;

pVertices[1].position = D3DXVECTOR3(-1.0f, 1.0f, 0.0f);
pVertices[1].normal = D3DXVECTOR3(0.0f, 0.0f, -1.0f);
pVertices[1].color = colour;
pVertices[1].tu = 0.0f;
pVertices[1].tv = 0.0f;

pVertices[2].position = D3DXVECTOR3(1.0f, -1.0f, 0.0f);
pVertices[2].normal = D3DXVECTOR3(0.0f, 0.0f, -1.0f);
pVertices[2].color = colour;
pVertices[2].tu = 1.0f;
pVertices[2].tv = 1.0f;

pVertices[3].position = D3DXVECTOR3(1.0f, 1.0f, 0.0f);
pVertices[3].normal = D3DXVECTOR3(0.0f, 0.0f, -1.0f);
pVertices[3].color = colour;
pVertices[3].tu = 1.0f;
pVertices[3].tv = 0.0f;

m_pTreeVB->Unlock();


D3DXCreateTextureFromFile(DXTigerPage.D3DDevice,"Tree02S.tga",&m_pTreeTextures[0]);
D3DXCreateTextureFromFile(DXTigerPage.D3DDevice,"Tree01S.tga",&m_pTreeTextures[1]);
//D3DXCreateTextureFromFile(DXTigerPage.D3DDevice,"Tree35S.tga",&m_pTreeTextures[2]);
D3DXCreateTextureFromFile(DXTigerPage.D3DDevice,"house7.tga",&m_pTreeTextures[2]);


}

void displaytree(D3DXMATRIX matWorld)
{
DXTigerPage.D3DDevice->SetStreamSource(0,m_pTreeVB,sizeof(CUSTOMVERTEX));
DXTigerPage.D3DDevice->SetVertexShader(D3DFVF_CUSTOMVERTEX);
DXTigerPage.D3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
DXTigerPage.D3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
DXTigerPage.D3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

for (int icount = 0; icount < treecount; icount++)
{
D3DXMatrixTranslation(&matWorld,trees[icount].x+movex,trees[icount].y+movey,z_pos);
DXTigerPage.D3DDevice->SetTransform( D3DTS_WORLD, &matWorld );


DXTigerPage.D3DDevice->SetTexture(0,m_pTreeTextures[trees[icount].texture]);
DXTigerPage.D3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
}
}


nlo
nlo
Matt, maybe i understand what u mean that quads r messed, b''cuz i have the same problem like u b4, but i realize what happen at last.

ok, if u need to use transpose to get the "face-to-camera" matrix, i suggest u dont use the function which D3D provide, write the function yourself, why ? billboard only need a matrix that rotated, so inside the matrix, which values for rotation ? yes, only "11,12,13,21,22,23,31,32,33", but the D3D provided transpose function will do all values inside matrix, that will mess up all the rotations, so write your self a transpose function like this :


  
// simple 3x3 matrix transpose

// matTemp is the View Matrix, i transpose in my camera update function

camera->matBB._11 = matTemp._11;
camera->matBB._12 = matTemp._21;
camera->matBB._13 = matTemp._31;
camera->matBB._21 = matTemp._12;
camera->matBB._22 = matTemp._22;
camera->matBB._23 = matTemp._32;
camera->matBB._31 = matTemp._13;
camera->matBB._32 = matTemp._23;
camera->matBB._33 = matTemp._33;
// Zero the 14,24,34

camera->matBB._14=camera->matBB._24=camera->matBB._34=0.0f;


then add your billboard position to "41,42,43" will give the correct result.

hope this can help u.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.