Sunday, April 14, 2013

[android help] How to get a 3D accordion effect on Android


I am planning to port the great 3D accordion effect found on iOS (https://github.com/xyfeng/XYOrigami) on Android.


so far I have something pretty close, here is a screenshot with "pinch-to-fold" to fold the view: http://imageshack.us/photo/my-images/822/3daccordion.png


as you can see, it remains a space between 2 opposite "panels". The process is simple:


  1. take the canvas of the main Layout

  2. create a Custom surface view which will replace all the view of the layout

  3. set as background image the taken canvas

  4. cut this canvas into X panels (here 16)

  5. redraw the surfaceview with all the "panels" with a calculated matrix

  6. recalculate the matrix while pinching to give the "folding effect"

here is the transformation matrix :



private Matrix getFoldingMatrix(int angle, int startFrom,int position) {
int move = (int) (
(mWidth - (Math.cos(angle * Math.PI / 180) * mWidth)) * position
) +1*position; //overlap of 1px the panels and not get space between panels

final Camera camera = new Camera();
final Matrix matrix = new Matrix();
camera.save();

camera.rotateY(angle);
camera.getMatrix(matrix);

if(position%2==1){
move += (int) (
(mWidth - (Math.cos(angle * Math.PI / 180) * mWidth))
) ;
matrix.preTranslate(-mWidth, -mHeight/2);
matrix.postTranslate(startFrom+mWidth-move, mHeight/2);
} else {
matrix.preTranslate(0f, -mHeight/2);
matrix.postTranslate(startFrom-move, mHeight/2);
}
camera.restore();

return matrix;
}


what am I getting wrong ? why is there still these spaces between opposite "panels"?



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...