Original Post
I''m trying to display sprites (the sdk calls them billboards) in my D3D application. In detail: I want to display objects that is located somewhere in my world and is always facing the viewer. I set up a rectangle (triangle-strip with 4 vertices) and when it should render I tried this (m_vecPos is the sprite position in world space):
// Set up the world matrix, only containing the position
D3DXMATRIX matWorld;
D3DXMatrixIdentity(&matWorld);
matWorld(3, 0) = m_vecPos.x;
matWorld(3, 1) = m_vecPos.y;
matWorld(3, 2) = m_vecPos.z;
m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, matWorld);
// Save the old view matrix
D3DXMATRIX matViewOld;
m_pD3DDevice->GetTransform(D3DTRANSFORMSTATE_VIEW, matViewOld);
// Set up a new view matrix, stripping rotations
D3DXMATRIX matView;
D3DXMatrixIdentity(&matView);
matView(3, 0) = matViewOld(3, 0);
matView(3, 1) = matViewOld(3, 1);
matView(3, 2) = matViewOld(3, 2);
m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, matView);
// Render the rectangle
if (FAILED(hr = m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_LVERTEX, m_pvVertices, 4, NULL)))
return hr;
// Restore the old view matrix
m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, matViewOld);
It does work, the sprite is always facing the viewer, but now I want it to also roll (Z-rotation) when the viepoint rolls and I totally stuck up with that.
Can anybody point me into the right direction? Or did I totally start wrong with my above solution?
ArgoN