I am following "Raycasting Tutorial" in this site Rayacasting Tutorial, in order to create a 3D perspective in a 2D map similar to an old game known as Wolfenstein_3D.
Here is the result so far as shown in this image:
What I am confused about is the math behind rendering a billboard 2d sprite which is always facing the camera direction.
Here is the billboard 2d sprite how it looks like:
I followed the tutorial about sprite rendering, that you can find it here Draw_Sprite, and I managed to display the billboard sprite in my scene as you can see in the first image, and in the tutorial, they used the inverse matrix, they multiplied the relative position of the sprite with the inverse of the camera matrix.
the relative position of the sprite is combined with 2 coordinates since we are working on a 2d map and it's as follows:
(Disable the dark theme if you want to see a clear image)
and the camera matrix is as follows:
in the tutorial as I mentioned earlier they multiplied the relative position of the sprite with the inverse of the camera matrix as shown below:
But I don't understand how it works, why we need to multiply the inverse of the camera matrix with the matrix of our sprite, I want to understand the logic behind it, How this formula makes the sprite rotate to be always facing the camera direction ?! I am still new in game development.