Billboard Control weird behavior. (Fixed)

I’ve been scratching my head about the billboard control since yesterday.



The code is simple enough:

[java]

private void attachSelector(int selected) {



Quad q = new Quad(2, 2);

Geometry cube = new Geometry(“My Textured Box”, q);

Material mat_stl = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);

Texture tex_ml = assetManager.loadTexture(“Interface/Logo/Monkey.jpg”);

mat_stl.setTexture(“m_ColorMap”, tex_ml);

cube.setMaterial(mat_stl);

Node bb = new Node(“billboard”);

BillboardControl bbC = new BillboardControl();

// I have tried all four Alignments possible

// Screen, Camera, AxialY and AxialZ

bbC.setAlignment(BillboardControl.Alignment.Screen);

bb.addControl(bbC);

cube.setLocalTranslation(OctreeList.findStarByID(selected).getXYZ());

bb.attachChild(cube);

rootNode.attachChild(bb);



if (sunLight==null) {

sunLight = new DirectionalLight();

sunLight.setDirection(pShipModel.getLocalTranslation());

sunLight.setColor(ColorRGBA.White);

sNode.addLight(sunLight);

}

rootNode.attachChild(sNode);

rootNode.updateGeometricState();

}

[/java]



You can see the results in the YouTube video I made. It would pretty hard to explain without visuals.



http://www.youtube.com/watch?v=bTuz3YDcg20



Hopefully some light can be shed on this.



My goal here is to have my “selector” on the star that has been selected. It should rotate around its placement so it always faces the camera, but it’s not doing that. It’s either rotating “correctly” but too far from where it should be, wrongly placed and too far, or simply goes crazy (as in the case of both Axial).



In order on the video (because since the video hasn’t been completely processed, it’s unreadable) I did:



1 - Screen

2 - Camera

3 - AxialY

4 - AxialZ



Thoughts?

YouTube says the video is private.

Yep. Private video.



From your description, it sounds like you want the default alignment (Screen). Are you sure the “too far” issue isn’t because of the translation ending up in the wrong place due to the attachment of spatials that already have a translation (i know i have done that mistake a couple of times)

It was supposed to be Unpublished, not private…



It’s public now. Sorry.

rickard said:
Yep. Private video.

From your description, it sounds like you want the default alignment (Screen). Are you sure the "too far" issue isn't because of the translation ending up in the wrong place due to the attachment of spatials that already have a translation (i know i have done that mistake a couple of times)


I'm not attaching the image to a spatial. The stars on the screen are point sprites.

I'm gathering the XYZ from a reference number (ID) that is put with the original's star's coordinates on the rootNode. It goes something like this:
[java]ptSun.setUserData("ID", visibleStars.get(i).getID());[/java]

Then onPick, I get that ID, look for it in the current node and use the star's corresponding XYZ and use that to locate the placement of the image.

If I use a normal image it's located exactly where it should be. But not the billboard.

[java]quad.setLocalTranslation(OctreeList.findStarByID(selected).getXYZ());[/java]
That's how the billboard's quad is attached to the coordinates. I tried normalized(), normalizedLocal(), etc, but with different but all wrong results.

So… Is the lack of reply an oversight or should I take it as it is working as intended?

I can’t really help out with the problem, but i implemented a billboardcontrol last week (some screen aligned text), and it works as i intended. Is the error consistent, ie does the billboard show up at the same position relative to the actual position (of different stars) all the time?

I might have some time thursday/friday to take a look at the latest issues that surfaced.

rickard said:
I can't really help out with the problem, but i implemented a billboardcontrol last week (some screen aligned text), and it works as i intended. Is the error consistent, ie does the billboard show up at the same position relative to the actual position (of different stars) all the time?


I would call it consistent inconsistencies. Depending on the galaxy type generated and the leaf I'm in, the picture might be drawn very far away, or closer. I have made it so that a selection doesn't disappear if you select a second star, so it "looks" ok when comparing placement of two images to the position they should be if they were attached to the star that has been clicked on... But even then, only at certain angles will they be rightly positioned.

Does that make sense?

Also, if you want to test it out, take the Billboard tutorial, but move those square farther from the map's origin, you should see what I'm talking about. It's less obvious because of the scale, but it's definitively there. It's as if the origin (0,0,0) of the map has something to do with what's happening on the screen.

Even if it's me, it is a sure thing Axials billboard control alignments are broken. That much is sure.

I wish I wouldn't have to bother anyone and fix it myself. :(
Momoko_Fan said:
I might have some time thursday/friday to take a look at the latest issues that surfaced.


Thanks! It's much appreciated.

I'll continue working on a tentative HUD and battling with Gimp during that time. ;)

@Momoko_Fan

Have you had some time to look it up?

Sorry I didn’t look at this yet. Its possible that the way billboard control applies the transforms to the model might be a bit incorrect.

Can you try removing the updateGeometricState() call at the end of the attachSelector() method? Also try replacing the billboard with another shape e.g box and see if its still in an incorrect position.

Since my last post a week ago I did some testing and I noticed that the placement of the quad I’m attaching to the billboard seems to be done around the origin of the scene (0,0,0). I have modified the way the game works a bit so those attached quads don’t get removed when I switch leaf and when I’m close to the origin, all of them are around that point. (That’s using Camera alignment).


Momoko_Fan said:
Sorry I didn't look at this yet.

Don't worry. It's all good. :)

Its possible that the way billboard control applies the transforms to the model might be a bit incorrect.

I'm not using a model. A simple quad to a geometry. (You might be referring to that geometry as a model, if that's the case, sorry for my ignorance.)

Can you try removing the updateGeometricState() call at the end of the attachSelector() method?

No change. I was expecting the game to crash but it didn't. I find that odd, but you know better than me so that's ok. :D

Also try replacing the billboard with another shape e.g box and see if its still in an incorrect position.

Well... That went odd.
I made a box and I got the same result than with the billboard, but had the desired result (as I always have) using the selector routine.

First here's the modification using the box:
[java]
Box q = new Box(s.getXYZ(),1,1,1);
Geometry quad = new Geometry("Quad", q);
Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
mat_stl.setTexture("m_ColorMap", tex_ml);
quad.setMaterial(mat_stl);
quad.setLocalTranslation(s.getXYZ());
// Node bb = new Node("billboard");
// BillboardControl bbC = new BillboardControl();
// bbC.setAlignment(BillboardControl.Alignment.Camera);
// bb.addControl(bbC);
// bb.attachChild(quad);
rootNode.attachChild(quad);
[/java]

Then the other routine.
[java]
Quad selectorQuad = new Quad(.15f, .15f);
Geometry selectorGeom = new Geometry("Selector", selectorQuad);

Material matSelector = new Material(assetManager, "MatDefs/Misc/SimpleTextured.j3md");
matSelector.setTexture("m_ColorMap", assetManager.loadTexture("Textures/Selector.png"));
matSelector.setTransparent(true);
matSelector.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
matSelector.getAdditionalRenderState().setDepthTest(true);

selectorGeom.setQueueBucket(Bucket.Transparent);
selectorGeom.setMaterial(matSelector);
selectorGeom.setLocalTranslation(s.getXYZ());

sNode.attachChild(selectorGeom);
[/java]
That last one attaches the Selector.png at the right place (lower left corner of the image is at the position of the selected star as expected since I hadn't had the time to properly center the image at the position).

Finally, the last lines:
[java]
rootNode.attachChild(sNode);
//rootNode.updateGeometricState();
[/java]

Note that sNode represents the "Selector Node". I used that in my original routine because it's easier and faster to remove the selector image than going through the rootNode.

Ok, now I'm freaking confused!
I just uncommented the whole method, using both the selector and the box but now I also attach the box to sNode and I still get the same result! :o The selector is at the star's coordinates but the damn box isn't!

What is it I'm doing wrong here? (It's almost funny!)

Little update.



If I use a box in the second routine (using selector.png) instead of a quad, that box gets rendered exactly at the same spot as the first one, ie: at the wrong place. :S



hits head on desk top

Haven’t had the opportunity to check that problem in some time, but I found the problem. As usual, it was my fault.



For some reason, I was attaching the BillboardControl to the node and not the Spatial.



Works fine now, as it would if I had done it right the first time. :slight_smile: