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:
- take the canvas of the main Layout
- create a Custom surface view which will replace all the view of the layout
- set as background image the taken canvas
- cut this canvas into X panels (here 16)
- redraw the surfaceview with all the "panels" with a calculated matrix
- 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