開始只是知道公告板就是不管攝相機怎么轉,對象總是在攝相機前面。這是公告板中的一種,也是最常見的一種
如游戲中人物、NPC的名字等,就是用貼圖技術,然后再用公告板,這樣不管玩家怎么轉動視角,總是能看見名字正對著自己,
終于自己實現了一回公告板函數
void Billboard(IDirect3DDevice9* Device,D3DXMATRIX &matInput,D3DXMATRIX &matOutput)
{
//=========================
//公告板技術
//==========================
D3DXMATRIX matBillboard,matView;
D3DXMatrixIdentity(&matBillboard);//初始化為單位矩陣
Device->GetTransform(D3DTS_VIEW,&matView);//取得觀察矩陣
matBillboard._11 = matView._11;//賦值
matBillboard._13 = matView._13;
matBillboard._31 = matView._31;
matBillboard._33 = matView._33;
D3DXMatrixInverse(&matBillboard,NULL,&matBillboard);//求其逆矩陣
matOutput = matBillboard * matInput;
//公告板結束
}
函數說明:
返回值:void
Device 是一個IDirect3DDevice9* 類型的參數
&matInput 是一個D3DXMATRIX 類型的參數
&matOutput 是一個D3DXMATRIX 類型的參數
功能,將傳入的matInput 矩陣,與攝相機矩陣的Look方向矩陣相乘,得到matOutput
用法
D3DXMATRIX matWorld;
D3DXMatrixIdentity(&matWorld);
D3DXMatrixTranslation(&matWorld,1,1,1); //對matWorld 進行必要的變換 如translation ,rotation 之類的。
Billboard(g_pDevice,matWorld,matWorld);
g_pDevice->SetTransform(D3DTS_WORLD,&matWorld);
接下來就可以進行材料,紋理設置、繪制等工作了!
雖然是很簡單的技術,但卻很實用。