Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

None of the current topics on billboarding seemed to answer this question.

But, given

  • a sprite (or quad) that has it's own 4x4 transformation matrix
  • a camera with a view matrix (a standard 4x4 transformation matrix)

is it possible to compute a 4x4 transformation matrix such that when the quad's matrix is multiplied with this matrix it has an orientation of looking at the camera?

share|improve this question
You may want a LookAt transformation matrix, like you would use for a camera. This description has the equations used:… – melak47 Jun 1 '12 at 15:52
My crude version: Create a vector from your sprite to the camera's location. Extract a vector representing your sprite's current facing based on it's matrix rotations. Create the matrix to rotate this vector to align with the camera's. Multiply and go forth. – Patrick Hughes Jun 1 '12 at 17:45
up vote 3 down vote accepted

Yes. Start with the rotation part of the camera-to-world matrix (inverse of the world-to-camera matrix, if that's what you meant by "view matrix"). Set the translation part of the matrix to zero. This will make the quads rotate with the camera. Then, given that the quads have the correct initial orientation, they will face the camera. That is, if the camera setup is such that an identity view matrix results in the camera looking along the +X axis (for example), the quads should be set up to face -X before the camera-facing matrix is applied.

This will make the quads parallel to the image plane. In some cases you might prefer that quads turn to directly face the camera rather than facing the image plane; that approach gives a different look that can be better or worse depending on the situation. Making the quads directly face the camera will require a different matrix for each quad, though, computed like Patrick Hughes suggested in his comment.

share|improve this answer
You're an amazing man, thank you so much for this. One further question, since inverting a matrix is usually an O(n^3) operation (I could be mistaken), would you recommend this operation being done on the CPU or should I just make a function in glsl to do it for me? I know I probably shouldn't be doing it every frame, but it seems like this is a job for a shader. – Ross Jun 1 '12 at 19:14
if you do it in the shader, you will potentially be re-inverting the matrix for every vertex – melak47 Jun 1 '12 at 19:20
Oh you're right. And since every vertex is going to be facing the camera, it would be utterly stupid to do that pervertex >.>;; Thanks for that. – Ross Jun 1 '12 at 19:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.