Theory on rotating with billboards....

Started by
5 comments, last by johnnyBravo 20 years, 9 months ago
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
Advertisement
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
Can you show your getbearing function? And why not use the tradional matrix solution?

.lick
How would you use the inverted camera matrix to rotate only about the Y axis?

pan narrans | My Website | Study + Hard Work + Loud Profanity = Good Code
Minister of Propaganda : leighstringer.com : Nobody likes the man who brings bad news - Sophocles (496 BC - 406 BC), Antigone
Maybe this will help:
http://www.mvps.org/directx/articles/view_oriented_billboards.htm

.lick
		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...
Why not try to get the view matrix, and then extract the Y rotation out of it? THe above tutorial shows you how, IIRC!

.lick

This topic is closed to new replies.

Advertisement