Billboarding using rotation

Started by
7 comments, last by Cybertron 22 years, 2 months ago
I have a simple bilboard that uses the inverse of the camera rotation to always face the screen. It works perfectly for the Y axis (Pitch) but not for the X axiz (Yaw). When i rotate around it gradually gets flatter and flatter I think this problem may be caused by the fact that the camera rotates around the ''focal point''. Can I fix the rotation angle, or is ther a trig trick to use A solution could be to use already transformed vertexes. Are they still scaled on the Z axis?
Advertisement
Do you want the billboard to face the camera in all ways? (on the x, y, and z axis?)

Moe''s Site
a clean way to do it if you''re using untransformed vertices is to take the inverse of the view matrix as the world matrix for
those vertices.

a quick way to do this (rather than using D3DXInverse..())
is to transpose the 3x3 rotation matrix in the top-left corner
of the view matrix, and take the negative of the translation
vector which is the last row of the view matrix.

The billboard should face the camera at all times. The camera rotates around the focal point using Yaw and Pitch (by translating then rotating)

so to do the view matrix is to copy 11,12,13,21,22,23,31,32,33 from the view matrix into the world matrix, and copy the negative X, Y and Z position of the object into 41,42,and 43 (leaving 44 = 1 I assume)?
  //get the current view matrix	lpd3ddevice->GetTransform(D3DTS_VIEW, &matView);	//get the transposed matrix	D3DXMatrixTranspose(&matTransposed, &matView);	matTransposed._14 = matTransposed._24 = matTransposed._34 = 0.0f;	//position the billboard	matTransposed._41 = bb.position.x;	matTransposed._42 = bb.position.y;	matTransposed._43 = bb.position.z;	// Set as world transformation matrix	lpd3ddevice->SetTransform(D3DTS_WORLD, &matTransposed);	// Draw whatever - will be aligned with view   


Moe''s Site
D3DXMatrixTranspose, D''OH!!!! thanks man! works perfectly!
It worked perfect for me as well (well, ok, that part of my program worked perfectly).

Moe''s Site
just an idea, but if you already have to touch some data for 4 vertices (!) with the CPU, why not just do the whole projection in CPU and use transformed & lit vertices?
just an idea, but it should be sufficient to transform the center of the billboard, divide width and height by the "w" of the transformed centerpoint and construct the quad from it.

shouldnt be slower -- maybe not faster, but...
but then again, never touch a running system

bye,

--- foobar
We push more polygons before breakfast than most people do in a day
--- foobarWe push more polygons before breakfast than most people do in a day
When using the camera object, it is very simple


D3DXMATRIX mat = pView->m_Camera.GetBillboardMatrix();
mat._41 = m_vPos.x ;
mat._42 = m_vPos.y ;
mat._43 = m_vPos.z ;
pd3dDevice->SetTransform( D3DTS_WORLD, &mat );

The view matrix is inverted only once, when setting the camera.

Laurent

This topic is closed to new replies.

Advertisement