Author Topic: Billboarding ignores parent rotations  (Read 17809 times)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Billboarding ignores parent rotations
« on: December 06, 2008, 10:23:58 pm »
I don't know if this is a bug or if it is intentional, but I thought I would point it out just in case.  Billboarding does not take an Object3D's parents' rotations into account (i.e. when rotating the parent, the child Object3D behaves as if it were BILLBOARDING_DISABLED).  Subsequent movements of the camera then result in the object auto-aligning to a direction other than the camera.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Billboarding ignores parent rotations
« Reply #1 on: December 06, 2008, 11:27:37 pm »
Do you have a test case for this? There once was a problem with bill boarding and parent object but that should have been fixed in 1.15. You may try to set Config.oldStyleBillBoarding to true and see if that changes anything (or verify that it is actually false, which should be the default).

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Billboarding ignores parent rotations
« Reply #2 on: December 06, 2008, 11:36:22 pm »
This is the old thread talking about the problem. So at least something has been fixed...: http://www.jpct.net/forum2/index.php/topic,960.0.html

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Billboarding ignores parent rotations
« Reply #3 on: December 06, 2008, 11:46:38 pm »
You may also try to call Object3D.setMatrixCacheUsage(false);
Maybe something is wrong with that one...

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Billboarding ignores parent rotations
« Reply #4 on: December 07, 2008, 12:00:00 am »
I'm putting together a simple test case and I'll post it in a few minutes.  I'll try out your suggestions and post the results as well.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Billboarding ignores parent rotations
« Reply #5 on: December 07, 2008, 12:08:24 am »
That damn Config setting is never used in jPCT!!?? I must have eliminated the fix and its code somewhere on the way...how strange is that!? I'll look into it...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Billboarding ignores parent rotations
« Reply #6 on: December 07, 2008, 12:21:58 am »
Ok...the backup from december '07 contained the code in question, the one from january '08 was missing it...strange. Anyway, I've uploaded a jar that should fix the missing fix: http://www.jpct.net/download/beta/jpct.jar
Please try that one and tell me if it fixes your problem. If it does, i'll silently update the release version of 1.17 with that fix.
« Last Edit: December 07, 2008, 12:24:37 am by EgonOlsen »

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Billboarding ignores parent rotations
« Reply #7 on: December 07, 2008, 01:16:04 am »
That corrected the problem, thanks!  Makes things a lot easier than the ugly work-around I was using!

Here is a working example of a child Object3D with billboarding enabled: (it was going to be my test-case :D)

Billboarding Child Example  (Source code)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Billboarding ignores parent rotations
« Reply #8 on: December 07, 2008, 01:19:34 am »
On second thought, there is still a problem.  Now rotating the object works, but orbiting the camera doesn't.  In the above applet, mouse rotates the object, and arrow keys orbit the camera.  The latter results in the object not billboarding (basically the opposite from before).

Oh, and I am also using the new camera.setOrientation() method to turn the camera, although that shouldn't affect the billboarding (it should only be affected by setPosition()).
« Last Edit: December 07, 2008, 01:47:24 am by paulscode »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Billboarding ignores parent rotations
« Reply #9 on: December 07, 2008, 11:16:11 pm »
I've updated the jar that i've linked to in the above post. I seems to work fine now with my test case, but i have lost track of my calculations somehow...so i'm not sure about all this. Please give it a try and tell me if it helps.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Billboarding ignores parent rotations
« Reply #10 on: December 07, 2008, 11:22:48 pm »
Seems to be working great in my test cases, too.  Looks like the problem is solved!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Billboarding ignores parent rotations
« Reply #11 on: December 07, 2008, 11:27:42 pm »
Cool...but i still wonder how i did that... ;D

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Billboarding ignores parent rotations
« Reply #12 on: December 08, 2008, 12:27:10 am »
I hate to be the bearer of bad news, but I found another strange problem with the billboarded child.  It could be a problem in my code, so I'll try and see if I can rule that out.

The object seems to be changing position when it is billboarded vs. when it is not billboarded.  I re-uploaded the above test applet and source code to demonstrate (I removed the glowing stuff so you can see what's going on little better).

Here is how to replicate the problem with the above applet:
1) Orbit the camera around the firefly with the arrow keys so that you and the firefly are facing eachother.
2) Rotate the firefly object with the mouse so it is facing into the screen again.
3) Toggle between billboarding and non-billboarding with the "Enter" key, and you can see that the object is shifting position.

I was trying to think of other things that might cause this same behavior besides the object changing position.  I came up with two other possibilities:
1) Rotating around the wrong pivot point.
2) Object backwards (i.e. the polys could be located in the wrong direction from the object's center)
« Last Edit: December 08, 2008, 12:37:12 am by paulscode »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Billboarding ignores parent rotations
« Reply #13 on: December 08, 2008, 08:22:36 am »
I think the whole code assumes that the pivot is at the origin. Are you using another pivot? I always found it questionable to use another pivot for bill boarded objects, but maybe i've to rethink this...

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Billboarding ignores parent rotations
« Reply #14 on: December 08, 2008, 01:36:30 pm »
I changed the code, and added the following code after build() and world.buildAllObjects(), but still get the position shifting:

Code: [Select]
        buttShine.setOrigin( new SimpleVector( 0, 0, zoffset) );
        buttShine.setCenter( new SimpleVector( 0, 0, zoffset) );
        buttShine.setRotationPivot( new SimpleVector( 0, 0, zoffset) );

So in that case, pivit, center, and origin are all the same, correct?

As for when the origin should be different than the pivot point, isn't that the case where a child is offset from a parent, but you want it to rotate around it's own center, and not the parent's center?  I may be visualizing incorrectly how this works.  Anyway, the above would seem to indicate that the position-shift problem is related to something else, anyway, wouldn't it?  I can repost the demo applet and source with the above changes if that helps.