Author Topic: Eccentric billboards  (Read 3779 times)

Offline rjm49

  • byte
  • *
  • Posts: 8
    • View Profile
Eccentric billboards
« on: May 09, 2012, 04:42:15 pm »
I want to label objects (and parts of objects) in my world using billboards.  I'm not talking about blitting, I want the labels to have a z co-ordinate, but they should stay attached to their object.  For some reason they don't work as I'd expect.

I have created a demo to explain the situation, but I'm not sure how to get the screenshots onto this forum.  Lots of other people have done so, so there must be a way.  Any suggestions?

Thanks!

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: Eccentric billboards
« Reply #1 on: May 09, 2012, 05:25:34 pm »
Just add a child to the desired object with object3d.addChild(child), move it higher with child.translate(0,-20,0).
Don't forget to set Billboarding ability with child.setBillboarding(true).
http://www.jpct.net/doc/com/threed/jpct/Object3D.html#setBillboarding%28boolean%29
www.forgottenelements.com
Free Action JAVA MMORPG

Offline rjm49

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Eccentric billboards
« Reply #2 on: May 09, 2012, 05:41:22 pm »
Hi Marlon,  I do understand the billboarding concept.  There is a specific case I am working with that does not behave as expected.

I am happy to go into code, but it would probably be much easier if I could post images.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Eccentric billboards
« Reply #3 on: May 09, 2012, 05:47:10 pm »
For sharing images you can use TinyPic or ImageUpload

Offline rjm49

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Eccentric billboards
« Reply #4 on: May 09, 2012, 10:41:37 pm »
Thanks Thomas!  OK, we're in business.

To help me see what's going on, I built a basic set of "axes" using a line plotter algorithm, and I put these at the centre of the "Hello World" spinning cube demo (i.e. all centred at (0,0,0)), made the cube a bit transparent so that you can see everything.  There's also a little Cone at the end of the x-axis.  That is there simply to help you work out which way everything is pointing.



First, I create a quad, add it to world and as child of box, but I don't "build()" it:
Code: [Select]
//box and axes already created, omitted for space
Object3D label = new Object3D(2);

SimpleVector upperLeft=new SimpleVector(0,-1,0);
SimpleVector upperRight=new SimpleVector(1,-1,0);
SimpleVector lowerLeft=new SimpleVector(0,0,0);
SimpleVector lowerRight=new SimpleVector(1,0,0);

// Front
label.addTriangle(upperLeft,0,0, lowerLeft,0,1, upperRight,1,0);
label.addTriangle(upperRight,1,0, lowerLeft,0,1, lowerRight,1,1);

//label.setTexture("demo texture");
label.setBillboarding(true);

world.addObject(label);
box.addChild(label);
box.build();
//label.build();

i.e. it creates a square quad with lower-left corner at (0,0,0).  The quad doesn't move, the cube and axes spin round it.  So far so good:


But obviously this is no use if I want a label, as I have to texture it.  So I "setTexture()" and "build()" by uncommenting those lines in the listing above.  My texture is terrible, but that's not the real problem here :)

When I run the programme I see this:


The label is now "off centre" and I cannot understand why.  It moves in a weird way that is hard to describe, like it is eccentric to (0,0,0).  It seems that "build()" is doing this, rather than the texturing step.

In order to try to understand this better, I moved the camera round to (0,-6,0) to get a "plan" view.  Then I see the following, without "build()":


With "build()":


I added the red circle myself - that is the "attachment" point, i.e. the billboard pivots around this point (looks like (0,0,0.5) in cube-space) as the whole cube assembly spins.

Since I've not done any translations, I am a bit confused by this!  I cannot see why it would make any difference just to do the "build()" and it certainly doesn't give the result I would expect.  Any explanations of what is happening here would be most welcome.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Eccentric billboards
« Reply #5 on: May 10, 2012, 07:01:53 am »
build() also calculates the rotation pivot based on the objects geometry. Try to add a setRotationPivot(new SimpleVector(0,0,0)); after calling build() to see if that gives you what you want.

Offline rjm49

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Eccentric billboards
« Reply #6 on: May 10, 2012, 01:03:11 pm »
I see, that explains it.  Yes, setting the rotation pivot back to (0,0,0) brings success - many thanks Egon.