Rotating billboard

Hi,



My question is: how to rotate billboard around it’s centre?



Right now it rotates itself around its side (like a flag rotating around its pole).

You can put your object of interest in some extra node with translation, so it’s center will be at 0,0,0 of parent node. Then attach billboard control to parent node.



With text, I’m actually setting ‘box’ to move text to the left by half of it’s width, which allows me to avoid creating new node just for bilboard control. Issue is that after you set the box, it is kept in text node, so if you want to change the text, you need to set box to null, change txt, retrieve width and set new box based on that.

1 Like

Thanks that worked :slight_smile:

Hi,

This might be an old topic, but I’m using Arthur’s solution to implement health bars. It actually works although I don’t understand why.

This is my former structure

[java]
Node
/
Box Healthbar
[/java]

and I add the billboard control to the health bar. The effect is the health bar rotates on its side like on a flagpole as mentioned by monkey.

With this structure,

[java]
Node
/
Box ExtraNode
|
Healthbar
[/java]

It works. But the two structures looks identical to me. Thanks.

Well, presumably you’ve attached the billboard control to the ExtraNode and then rotated your HealthBar or something. There is more to the restructure than you are showing or yeah, the results would be identical.

Here is a simple code snippet:

[java]
Node boxAndBar = new Node(“Box and HP Bar”);

Box b = new Box( 1, 1, 1 );
Geometry boxGeom = new Geometry(“Box”, b);

Material boxMat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
boxMat.setColor(“Color”, ColorRGBA.Blue);
boxGeom.setMaterial(boxMat);

Quad healthbar = new Quad(2, 0.125f);
Geometry healthbarGeom = new Geometry(“Health Bar”, healthbar);
healthbarGeom.move( -1, 1.125f, 0 );

Material healthbarMat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
healthbarMat.setColor(“Color”, ColorRGBA.Red);
healthbarGeom.setMaterial(healthbarMat);

boxAndBar.attachChild(boxGeom);
boxAndBar.attachChild(healthbarGeom);
rootNode.attachChild(boxAndBar);

BillboardControl billboardControl = new BillboardControl();
billboardControl.setAlignment(BillboardControl.Alignment.Camera);
healthbarGeom.addControl(billboardControl);
[/java]

The health bar rotates on its side.

Replacing the last six lines with these:
[java]
Node extraNode = new Node( “Extra Node” );
boxAndBar.attachChild(boxGeom);
boxAndBar.attachChild(extraNode);
extraNode.attachChild(healthbarGeom);
rootNode.attachChild(boxAndBar);

BillboardControl billboardControl = new BillboardControl();
billboardControl.setAlignment(BillboardControl.Alignment.Camera);
extraNode.addControl(billboardControl);
[/java]
would cause the health bar to rotate on its center. Although I can’t understand why an extra node would be necessary. Thanks. :-?

Well, I guess the health bar’s rotation is already correct but when you attach the billboard control to it then it rotates it to where the billboard wants. But when you put the billboard on the parent then it rotates the parent and so you get to keep the rotation you already have on the healthbar.