guiNode coordinate conversion

Hi All,



I have a vehicle and a BitmapText. The BitmapText is attached to the guiNode so that the text remains visible even when the node moves. However I would like the text on the UI node to move with the vehicle (so in effect translate xyz to xy):



[java]public void updateLabelPosition(float x, float z) {

if (hudText != null) {

hudText.setLocalTranslation(x, hudText.getLineHeight(), z);

}

}[/java]



updateLabelPosition is called as the local translation of the vehicle changes. For this to work however I presume that I need to perform a localToWorld or worldToLocal (neither of which works) conversion…Could that be correct? If so, any other thoughts?



Thanks.

cam.getScreenCoordinates() and getWorldCoordinates()

1 Like

Thanks!

I’m afraid I still don’t quite follow. updateLabelPosition is part of my vehicle class:





[java]

public void updateLabelPosition(Vector3f worldPos) {

// worldPos = worldPos.mult(_application.getCamera().getLocation());

Vector3f screenPos = _application.getCamera().getScreenCoordinates(worldPos);

if (_label != null) {

_label.setLocalTranslation(screenPos.x, screenPos.y, screenPos.z);

}

}

[/java]



Every time that the vehicle or camera moves, I update the label position:



[java]

vehicle.localToWorld(vehicle.getLocalTranslation(), worldCoords);

vehicle.updateLabelPosition(vehicle.getLocalTranslation());

[/java]



The problem is that I want the text label to “stick” to the vehicle (I’m not using the billboard control as I don’t want the text to get smaller once the camera moves away - The label needs to remain of a constant size).



The problem right now is that the label on the guiNode doesn’t actually remain with the vehicle…I guess I need to only translate the x and z coordinates and then use the vehicle’s y coordinate produced with vehicle.localToWorld(vehicle.getLocalTranslation(), worldCoords); (however this too doesn’t do the trick).



Any more thoughts? :slight_smile:

Why do you do the localToWorld when you don’t use it? Wouldn’t it be vehicle.updateLabelPosition(vehicle.getWorldTranslation())?

1 Like

Why do you do the localToWorld when you don’t use it?

Because I’m an idiot :stuck_out_tongue: Haha, it works now. Thanks Normen :slight_smile: