I am encountering some issues with billboarding. Although my situation is a bit complicated.
So, I am modeling the solar system, and I am also placing labels on everything. For an example, I'll use Uranus and one of its moons.
So Uranus is in world coordinates, it's moon is in coordinates local to Uranus, and the moon's label is in coordinates local to Uranus' moon.
What I am trying to do is billboard the label, and also orient them so they look like normal text.
I have successfully been able to billboard the label to face the camera, so all the labels are facing the camera, but they are all turned and rotated in different directions.
How I achieved this:
I should note, the labels are X-Z axis aligned, so the positive y-axis is coming out of the front of the label, and we are working in coordinates local to the body.
LocalToWorld : Matrix CameraPosition : Vector BodyPosition : Vector // obtain vector from body to camera Vec3 vec = Vec3(0, 0, 0) - CameraPosition * LocalToWorld.inverse(); Quaternion r; // rotation quaternion that rotates y vector of label to vector from body to camera r.makeRotate(Vec3(0, 1, 0, vec);
Now, this logic is able to turn the labels to always face the camera, but now I want the text to always be oriented to the bottom of the screen.
Up: Vector (World Coordinates) // Get the right direction of the label Vec3 labelRight = r * Vec3(1, 0, 0); // Get Up vector in local coordinates Up = Up * LocalToWorld.inverse(); // Cross Up with vec to get right Vec3 camRight = Up x vec; Quat rUp; // rotate right of label to right of camera rUp.makeRotate(labelRight, camRight);
So, I believe that buy combining these two quaternions, I should get my labels facing me, and also oriented to the bottom of the screen. Is my math wrong at some point?