Archived

This topic is now archived and is closed to further replies.

Theory on rotating with billboards....

This topic is 5241 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, im trying to create a billboard, but havent been able to get it working. Like what i tried doing was find the angles from the billboard to the camera point. eg x -axis, y axis z axis like i worked the angles like this xAxis=getbearing(bz,by,cz,cy) yAcis=getbearing(bx,bz,cx,cz) etc get bearing was just a function i made to work out the angle between 2 points on a graph. bx etc is for billboard and c etc is for camera point when i ran this code it worked sometimes but if you got the camera 2 close to it, it would flip over and look a little bit silly. Any ideas on how to do it properly? Thanks

Share this post


Link to post
Share on other sites
simply use the inverted camera-matrix
like this:

D3DXMATRIX mCamera;
D3DXMATRIX mTransform;
D3DXVECTOR3 vPosition; // the position vektor
g_pDirect3DDevice->GetTransform(D3DTS_VIEW,&mCamera);
D3DXMatrixInvert(&mTransform,&mCamera);
mTransform._m41 = vPosition.x;
mTransform._m42 = vPosition.y;
mTransform._m43 = vPosition.z;
g_pDirect3DDevice->SetTransform(D3DTS_WORLD,&mTransform);
// drawing goes here

Share this post


Link to post
Share on other sites

float GetBearing(float a, float b, float a2, float b2)
{
float offA= abs(a-a2);
float offB= abs(b-b2);
float answer;

if (a2>a && b2<b) answer= atan(offB/offA);
if (a2<=a && b2>b) answer= atan(offA/offB)+(D3DX_PI/2);
if (a2<a && b2<=b) answer= atan(offB/offA)+D3DX_PI;
if (a2>=a && b2<b) answer= atan(offA/offB)+(3*D3DX_PI/2);

return answer;
}


ill try your suggestions

and i don''t know of any traditional matrix solution...

Share this post


Link to post
Share on other sites