www.jpct.net

jPCT - a 3d engine for Java => Bugs => Topic started by: paulscode on December 06, 2008, 10:23:58 pm

Title: Billboarding ignores parent rotations
Post by: paulscode 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.
Title: Re: Billboarding ignores parent rotations
Post by: EgonOlsen 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).
Title: Re: Billboarding ignores parent rotations
Post by: EgonOlsen 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 (http://www.jpct.net/forum2/index.php/topic,960.0.html)
Title: Re: Billboarding ignores parent rotations
Post by: EgonOlsen on December 06, 2008, 11:46:38 pm
You may also try to call Object3D.setMatrixCacheUsage(false);
Maybe something is wrong with that one...
Title: Re: Billboarding ignores parent rotations
Post by: paulscode 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.
Title: Re: Billboarding ignores parent rotations
Post by: EgonOlsen 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...
Title: Re: Billboarding ignores parent rotations
Post by: EgonOlsen 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 (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.
Title: Re: Billboarding ignores parent rotations
Post by: paulscode 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 (http://www.paulscode.com/source/BillboardChild/)  (Source code (http://www.paulscode.com/source/BillboardChild/BillboardChildSource.zip))
Title: Re: Billboarding ignores parent rotations
Post by: paulscode 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()).
Title: Re: Billboarding ignores parent rotations
Post by: EgonOlsen 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.
Title: Re: Billboarding ignores parent rotations
Post by: paulscode on December 07, 2008, 11:22:48 pm
Seems to be working great in my test cases, too.  Looks like the problem is solved!
Title: Re: Billboarding ignores parent rotations
Post by: EgonOlsen on December 07, 2008, 11:27:42 pm
Cool...but i still wonder how i did that... ;D
Title: Re: Billboarding ignores parent rotations
Post by: paulscode 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)
Title: Re: Billboarding ignores parent rotations
Post by: EgonOlsen 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...
Title: Re: Billboarding ignores parent rotations
Post by: paulscode 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.
Title: Re: Billboarding ignores parent rotations
Post by: EgonOlsen on December 08, 2008, 03:30:17 pm
An application would be much easier to handle as a test case than an applet... ;)
Title: Re: Billboarding ignores parent rotations
Post by: paulscode on December 08, 2008, 08:59:17 pm
Oh, ok.  I will convert it into an application and re-upload.
Title: Re: Billboarding ignores parent rotations
Post by: paulscode on December 08, 2008, 09:42:02 pm
Ok, I have it in application form:

http://www.paulscode.com/source/BillboardChild/BillboardChildApplication.zip (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--
Title: Re: Billboarding ignores parent rotations
Post by: paulscode 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 (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".
Title: Re: Billboarding ignores parent rotations
Post by: paulscode 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
Title: Re: Billboarding ignores parent rotations
Post by: EgonOlsen on December 09, 2008, 03:45:08 pm
Sooo...i consider this case to be closed for now?
Title: Re: Billboarding ignores parent rotations
Post by: paulscode 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.