1
\$\begingroup\$

I am successfully using Matrix.CreateBillboard in my XNA game to print the characters name above the models. The problem I have is with the offset (to appear above the models). Currently, I am creating the location of the text using;

Vector3 objTextPosition = objPlayerShip.objShipVector + new Vector3(0, 3, 0);

This works fine if I stay within the same general lateral location. If I rotate above or below the model the text either appears on top of, or is covered by (or even below) the model. To compensate for this, I would need to create a rotation around the model (should I use a quaternion?) with the top always pointing up (with a Vector3(0, 3, 0) offset).

Am I over thinking this? Is there a simple way to achieve this?

Thanks in advance!


Here is the correct way (above the model)

Above


Here is looking from top, down

In Front

\$\endgroup\$
1
\$\begingroup\$

A Vector that you can use to always cause the text to be slightly above the ship on the screen regardless of camera angle would be:

Vector3 objTextPosition = objPlayerShip.objShipVector + (Matrix.Invert(view).Up * 3);

essentially, it does what you were thinking of (transforming global UP by "some" rotation). But since the camera already using that "some" rotation , it just borrows a vector from it. (although it needs to be inverted to world space first).

\$\endgroup\$
  • \$\begingroup\$ P.S. I found your blog last night while attempting to figure this out. It's going to me mandatory lunchtime reading for me for the next few day's! :-) People like you make this such a fun hobby to have! I cant thank you enough. \$\endgroup\$ – Linuxx Jan 9 '13 at 3:42
  • \$\begingroup\$ Since you are setting the world space position of the text, you need world space vectors. The view matrix gets inverted to cause it's basis vectors to represent world space vectors instead of camera space vectors. \$\endgroup\$ – Steve H Jan 9 '13 at 13:54
  • \$\begingroup\$ Thanks, I'm a hobbyist too. I agree, 3D programming is very fun. \$\endgroup\$ – Steve H Jan 9 '13 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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