Character labels

Tempest

23-01-2006 19:30:51

I posted this on the regular forums as well, but haven't gotten much help. So maybe someone here has done something similar.

I'm using an Overlay to display character names above their head. I took a look at the article on Movable Text and I'm doing something very similar to translate from 3D to 2D:


private void translate3Dto2Dpixels(ref Camera pCam, Vector3 vertex, out int x, out int y)
{
Vector3 hsc = pCam.GetProjectionMatrix() * pCam.GetViewMatrix() * vertex;

RenderTarget rt = Root.GetSingleton().GetRenderTarget(mRenderWindow.GetName());

x = (int)((hsc.x + 1.0f) / 2.0f * rt.GetWidth());
y = (int)((-hsc.y + 1.0f) / 2.0f * rt.GetHeight());
}


I'm then passing the MainCamera and the position of the node containing the character:


Vector3 vertex = mNode.GetPosition();
vertex.y += fCharacterHeight;

Camera pCam = mSceneManager.GetCamera("MainCamera");

translate3Dto2Dpixels(ref pCam, vertex, out intX, out intY);

OverlayElement elePanel = OverlayManager.getSingleton().getOverlayElement("EP/Overlays/CharacterPanel");
elePanel.setPosition(intX, intY);


This works perfectly if the character is standing at 0,0,0. However, it gets *way* off as you walk further and further away from the origin.

Any thoughts?

mysticjovy

18-02-2006 03:32:15

think you should try something to be cool ok 8)


--------------------
mysticjovy here