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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Billboarding ignores parent rotations
« Reply #15 on: December 08, 2008, 03:30:17 pm »
An application would be much easier to handle as a test case than an applet... ;)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Billboarding ignores parent rotations
« Reply #16 on: December 08, 2008, 08:59:17 pm »
Oh, ok.  I will convert it into an application and re-upload.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Billboarding ignores parent rotations
« Reply #17 on: December 08, 2008, 09:42:02 pm »
Ok, I have it in application form:

http://www.paulscode.com/source/BillboardChild/BillboardChildApplication.zip

I tweaked the numbers a little to amplify the position shift problem.  The source code is included in the above .zip file.  You can see from the source code that the pivot and origin are the same, yet the position still appears to change when toggling between billboarded or not.

--EDIT--
Oh, and I thought I would point this out (although you could probably figure it out for yourself), in case you are confused about how the child object is set up.  It is basically a box with two polys coloring one side (i.e. the object's center/pivot/origin is not on the polys - it is in the center of the imaginary box).

So when the firefly was facing out of the screen (along the -z axis), then when the child "box" is billboarded it would be pointed one direction (-z direction), and when not-billboarded it would be pointed the opposite direction (+z direction).  Hince one would expect that the polys would shift position in that case, as they should.

However in the scenario I described in my earlier post (orbiting the camera, then rotating the firefly), the firefly winds up facing along the +z axis just like it started out (i.e. his butt is pointing out of the screen).  In that case, the child "box" should be oriented in the same direction whether it is billboarded or not, and the polys should not change position when toggling between billboarded or not.  Problem is, they are changing position.

I hope that clarifies the problem a little better.
--END EDIT--
« Last Edit: December 08, 2008, 10:11:24 pm by paulscode »

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Billboarding ignores parent rotations
« Reply #18 on: December 08, 2008, 10:38:48 pm »
In an effort to be able to visualize what is going on a little better, I made a colorful cube and used it as the child billboarded object rather than the 2-poly quad.  I of course commented out the unneed three lines of code:
Code: [Select]
        buttShine.setOrigin( new SimpleVector( 0, 0, zoffset) );
        buttShine.setCenter( new SimpleVector( 0, 0, zoffset) );
        buttShine.setRotationPivot( new SimpleVector( 0, 0, zoffset) );

And to my suprise, the "position shifting" problem is not present in this case!  It looks to me like this would indicate that jpct is rotating the billboarded child around some other pivot, and not the one that I specified.  I am starting to suspect that this is not a jPCT bug, and that I have simply misinterpreted what the above three methods actually do.
So what would be the correct way to make an imaginary "box" with two polys on one side ???

Anyway, here is the working application which uses a cube instead of a 2-poly quad:

http://www.paulscode.com/source/BillboardChild/BillboardChildApplication.zip

A workaround for this problem might be to use four polys instead of two when creating the "quad" (two of them on the other side of the imaginary box).  That way jpct would calculate the center of the object where I want it to be.  A simple work-around, but it would still be nice to be able to just specify a pivot/center, rather than having to "trick the system".
« Last Edit: December 08, 2008, 10:52:11 pm by paulscode »

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Billboarding ignores parent rotations
« Reply #19 on: December 08, 2008, 11:10:00 pm »
ARGH! I finally understand what you said six posts ago!  I misinterpreted what you typed, which started me on the whole setOrigin() quest.  Sorry if I confused you :-[

You mentioned in your earlier post that you shouldn't use another pivot for billboarded objects.  I changed the object's center and rotation pivot in my program (to turn it into an imaginary box instead of a flat plane).  That is why jpct is rotating it around a different point than the one I expected it to, which makes it look like the polys are shifting position.

Another problem with my example is that setOrigin() refers to the world space coordinate to start from before performing any translations (i.e. it has nothing to do with object space).  There is no reason I would ever need to change that in the first place to create an imaginary box, so that line of code shouldn't even have been in there at all.

So moral of the story: you can't specify a different pivot for a billboarded object, and the work-around that I mentioned in my last post is a requirement.

Let me know if I'm still on a different wavelength ;D

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Billboarding ignores parent rotations
« Reply #20 on: December 09, 2008, 03:45:08 pm »
Sooo...i consider this case to be closed for now?

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Billboarding ignores parent rotations
« Reply #21 on: December 09, 2008, 09:01:22 pm »
Yes, billboarded child Object3D works as well as any other billboarded Object3D now.  Whether you should be able to choose a different pivot or not for a billboarded Object3D is unrelated and certainly not a bug.  Thanks for clarifying that for me, BTW.