Sign in to follow this  

label over a mesh like world of warcraft

This topic is 4224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, im trying to display a text right near the top of a sphere mesh. i would like the text to become smaller as i move farther away from the mesh, just as the mesh sphere itself becomes smaller. it should also become larger as one moves towards it, just like the sphere does. how can i do that? basically like how the names for characters in world of warcraft are displayed together with the 3d character. it goes with them wherever they go. thanks for your time, Zahid

Share this post


Link to post
Share on other sites
Definitely billboarded sprites. You can have a variable that holds the distance of the mesh to the camera or some kind of scaling variable. When the mesh comes closer to the camera, increase this variable and then scale the billboarded sprite appropriately and visa versa. That's a simple way to do it.

I hope this helps.
Take care.

Share this post


Link to post
Share on other sites
You'll want a font-class capable of printing scaled fonts.

Take the position of the character + the offset to where you want the label to be (in world-space)

Transform that point from 3D -> 2D by multiplying it with the WorldViewProjection matrix. That will give you the position in [0..1][0..1][-1..1] coordinates. <0 for Z means that it's behind you, and should not be drawn.

Pick a scale the size of the text based on the distance from the camera. Easy way to do this is to say

Distance = (Target-Camera).Magnitude;
at 0..D1, text is size A
D1..D2, text is lerped A-B
D2..Outofrange, text is size B
further away than Outofrange, don't draw.

Then pass the screen-position and the scale into a font-class to draw the text on screen as a 2D effect after the world's finished rendering.

Allan

Share this post


Link to post
Share on other sites
hello Allan,

i have a Vector3 object that represents the center of the mesh that im drawing on screen. So i projected that to screen space using the Project method of the Vector3 class.

I took the X and Y values of the projected vector and made a point object called 'nelementNameLocationOnScreen' and than i used the DrawText method of the Font class to draw a text using that point. below is some code:

this.nelementOriginLocation.Project ( nelementsDrawingDevice.Viewport, nelementsDrawingDevice.Transform.Projection , nelementsDrawingDevice.Transform.View , nelementsDrawingDevice.Transform.World );
this.nelementNameLocationOnScreen = new Point ( Convert.ToInt32 ( this.nelementOriginLocation.X ), Convert.ToInt32 ( this.nelementOriginLocation.Y ) );
this.nelementOriginLocation.Unproject ( nelementsDrawingDevice.Viewport, nelementsDrawingDevice.Transform.Projection , nelementsDrawingDevice.Transform.View , nelementsDrawingDevice.Transform.World );
this.textFont.DrawText ( null, this.representedNelement.nelementName, this.nelementNameLocationOnScreen, Color.White );

the problem is that when the text is shown on screen, its location keeps changing and doesnt show up right in the center of the sphere as i want it to. the text keeps going in circles around the screen and doesnt stay in one place on top of the sphere. is this because the project method isnt very accurate and keeps projecting different values each time it is run?

how do u suggest i should fix it?

by the way, im also apply a rotation to the sphere. do u think that is causing the circling of the text and if it is how should i proceed to achieve a rotating sphere and a text that stays near the sphere instead of moving around?

thanks for your time,

Zahid

Share this post


Link to post
Share on other sites

This topic is 4224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this