I'm trying to come up with a proper algorithm to create a matrix which gets the quad to face the camer straight up but I'm having difficulty.
The quad I'm drawing is facing downwards, here's the code I have so far:
D3DXVECTOR3 pos;
pos = D3DXVECTOR3(-2.0f, 6.0f, 0.1f);
D3DXMATRIX transform;
D3DXMatrixTranslation(&transform, pos.x, pos.y, pos.z);
D3DXVECTOR3 axis = D3DXVECTOR3(0, -1, 0);
D3DXVECTOR3 quadtocam = pos - EmCameraManager::Get().GetPosition();
D3DXVec3Normalize(&quadtocam,&quadtocam);
D3DXVECTOR3 ortho;
D3DXVec3Cross(&ortho, &axis, &quadtocam);
float rotAngle = acos(D3DXVec3Dot(&axis,&quadtocam));
D3DXMATRIX rot;
D3DXMatrixRotationAxis(&rot,&ortho,rotAngle);
transform = rot*transform;
This works when it comes to making the quad face the camera however it doesn't stay up right when facing it from all angles.
In this screen shot: http://imgur.com/hFmzc.png On the left the quad is being viewed straight on (vector is 0,0,1), in the other its being viewed from an arbitrary angle.
Both times it's facing the camera, however when from an arbitrary angle its tilting along its local z axis. I'm not sure how to fix it and was wondering what the next step here would be?