Billboarding ignores parent rotations

Started by paulscode, December 06, 2008, 10:23:58 PM

Previous topic - Next topic

paulscode

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.

EgonOlsen

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).

EgonOlsen

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

EgonOlsen

You may also try to call Object3D.setMatrixCacheUsage(false);
Maybe something is wrong with that one...

paulscode

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.

EgonOlsen

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...

EgonOlsen

#6
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.

paulscode

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)

paulscode

#8
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()).

EgonOlsen

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.

paulscode

Seems to be working great in my test cases, too.  Looks like the problem is solved!

EgonOlsen

Cool...but i still wonder how i did that... ;D

paulscode

#12
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)

EgonOlsen

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...

paulscode

I changed the code, and added the following code after build() and world.buildAllObjects(), but still get the position shifting:

        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.