Skip to main content
gamedev.net
🔒 Locked

Billboarding

Started by giant Feb 27, 2003 at 6:07 PM 0 replies 300+ views
Original Post
giant
giant
Hi. I am trying to implement billboarding into my 3D Engine but am having some problems. The billboard is being drawn but it is not being rotated to always face the camera as a billboard should. The billboard has the following properties,
  
D3DXVECTOR3 m_vPos;
float m_fSize;
float m_fPitch, m_fRoll, m_fYaw;
  
m_vPos is the position that the billboard has in 3d space. m_fSize is the size of the billboard. m_fPitch, m_fRoll and m_fYaw are used so that the user can rotate the billboard if they desire but is currently just set to 0.0f, 0.0f, 0,0f; The code I use to render the billboard is as follows
  
//Get the View Matrix

	D3DXMATRIX view = Camera.GetViewMatrix();

	if (!m_pAnim) return;

	// Set up a rotation matrix to orient the explo sprite towards the camera.

	D3DXMATRIX matScale, matTranslate, matTranspose, matBillboardRot, matWorld;
	D3DXMATRIX matRot; // user-specified rotation

	D3DXMatrixTranspose(&matTranspose, &view);
	D3DXMatrixIdentity(&matBillboardRot);

	//Turn on Alpha Blending and Off Z Buffering

	pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
	pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
	pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_DESTALPHA );
	pDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
  
	matBillboardRot._11 = matTranspose._11;
	matBillboardRot._12 = matTranspose._12;
	matBillboardRot._13 = matTranspose._13;
	matBillboardRot._21 = matTranspose._21;
	matBillboardRot._22 = matTranspose._22;
	matBillboardRot._23 = matTranspose._23;
	matBillboardRot._31 = matTranspose._31;
	matBillboardRot._32 = matTranspose._32;
	matBillboardRot._33 = matTranspose._33;
      
	D3DXMatrixTranslation(&matWorld, m_vPos.x, m_vPos.y, m_vPos.z);
	D3DXMatrixRotationYawPitchRoll(&matRot, m_fRotationYaw, m_fRotationPitch, m_fRotationRoll);

	D3DXMatrixScaling(&matScale, m_fSize, m_fSize, 1);
	//m_pAnim->Render(m_Timer, matScale * matRot * matBillboardRot * matWorld, pDevice );

	m_pAnim->Render(m_Timer, matScale * matBillboardRot * matWorld, pDevice );

	//Turn Alpha Blending and Z Buffering Off and On Respectively

	pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
	pDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
  
The Billboard is being rendered but it is not being rotated to face the camera as desireable. Does anyone know what I am doing wrong? The above code is based on the billboard from the explosions section of "Special Effects Programming with DirectX". Thanks Giant

Topic Locked

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

Sign in to reply to this topic.