www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: devcat on October 18, 2014, 10:46:34 pm

Title: Stange Overlay shear effect
Post by: devcat on October 18, 2014, 10:46:34 pm
Hi,

i try to apply a shear operation to an Overlay. I tried the following code with the jPCT PC version and it works fine.
Code: [Select]
// inside some update routine
Matrix mat = overlay.getObject3D().getRotationMatrix();
mat.set(0, 1, shearY);
mat.set(1, 0, shearX);

Then i tried it on android and for some reason it does an additional translation besides the shear operation.
Any suggestions?

Thanks
Title: Re: Stange Overlay shear effect
Post by: EgonOlsen on October 18, 2014, 11:00:14 pm
I don't see, why it should do that. Can you try to add a call to

Code: [Select]
overlay.getObject3D().compile();

to the desktop version to see if this has a similar translation effect there. Are you setting a rotation pivot to the Overlay, btw?
Title: Re: Stange Overlay shear effect
Post by: devcat on October 18, 2014, 11:32:45 pm
When i call in the desktop version
Code: [Select]
overlay.getObject3D().compile();
the overlay don't appear on screen.
And nope, I don't set the rotation pivot in the Overlay.
Title: Re: Stange Overlay shear effect
Post by: EgonOlsen on October 18, 2014, 11:48:02 pm
I see...Overlays in the desktop version are obviously not supposed to be compiled. Ok...i've no idea then. I really don't see, where this translation should come from. How large is it? Dso you have a screen shot with and without the shearing?
Title: Re: Stange Overlay shear effect
Post by: devcat on October 19, 2014, 12:02:27 am
Actually it's peaty simple to write an example, then you can see it in motion for your self. Just take your HelloWorld-AE example and add the following lines
Code: [Select]
public void onSurfaceChanged(GL10 gl, int w, int h) {
// ...
// world.addObject(cube);

// new code
overlay = new Overlay(world, fb, "texture");
overlay.setNewCoordinates(300, 150, 400, 250);
// ...
}

public void onDrawFrame(GL10 gl) {

// new code
com.threed.jpct.Matrix mat = overlay.getObject3D().getRotationMatrix();
mat.set(1, 0, (float) Math.cos(shearX));
shearX += 0.01f;
// ...
}
Hope this helps :).
Title: Re: Stange Overlay shear effect
Post by: EgonOlsen on October 19, 2014, 03:03:07 pm
I see...still no idea where this comes from. I'll look at it, but maybe not today...
Title: Re: Stange Overlay shear effect
Post by: EgonOlsen on October 20, 2014, 04:43:08 pm
Seems to be an issue with the way in which the position is calculated. If the rotation matrix isn't a proper rotation matrix, this fails and i don't see how to fix this. In desktop jPCT, it works because the pipeline for these Overlays is different and obviously not affected. I found a work-around though. Take these jars

jPCT-AE: http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar)
jPCT: http://jpct.de/download/beta/jpct.jar (http://jpct.de/download/beta/jpct.jar)

They add a new method to the Overlay class called setInitialMatrix(). Just apply your shear operation to that one and leave the rotation matrix alone. At least it works for jPCT-AE, i'm not sure about desktop jPCT though.
Title: Re: Stange Overlay shear effect
Post by: devcat on October 21, 2014, 09:11:15 pm
Thanks for the really fast workaround, now both versions support the Overlay shearing perfectly. Just have to make sure to don't call accidentally overlay.compile(), because this will leave to some known side effects ^^.