2
\$\begingroup\$

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?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You may want a LookAt transformation matrix, like you would use for a camera. This description has the equations used: msdn.microsoft.com/en-us/library/windows/desktop/… \$\endgroup\$
    – user13213
    Jun 1, 2012 at 15:52
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Jun 1, 2012 at 17:45

1 Answer 1

4
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ 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. \$\endgroup\$
    – Ross
    Jun 1, 2012 at 19:14
  • \$\begingroup\$ if you do it in the shader, you will potentially be re-inverting the matrix for every vertex \$\endgroup\$
    – user13213
    Jun 1, 2012 at 19:20
  • \$\begingroup\$ 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. \$\endgroup\$
    – Ross
    Jun 1, 2012 at 19:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .