0
所以,我实现了一个旋转木马就像Android 3D Carousel。android:camera.rotateY()神秘地扭曲旋转木马
现在,只要我的getChildStaticTransformation(查看孩子,转型改造)方法是这样的:一旦
,但正如我:
@Override
protected boolean getChildStaticTransformation(View child, Transformation transformation) {
transformation.clear();
transformation.setTransformationType(Transformation.TYPE_MATRIX);
// Center of the view
float centerX = (float)getWidth()/2, centerY = (float)getHeight()/2;
// Save camera
mCamera.save();
// Translate the item to it's coordinates
final Matrix matrix = transformation.getMatrix();
matrix.reset();
mCamera.translate(((CarouselItem)child).getItemX(), ((CarouselItem)child).getItemY(),
((CarouselItem)child).getItemZ());
// Align the item
mCamera.getMatrix(matrix);
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
float[] values = new float[9];
matrix.getValues(values);
// Restore camera
mCamera.restore();
Matrix mm = new Matrix();
mm.setValues(values);
((CarouselItem)child).setCIMatrix(mm);
//http://code.google.com/p/android/issues/detail?id=35178
child.invalidate();
return true;
}
一切正常添加y轴旋转:
@Override
protected boolean getChildStaticTransformation(View child, Transformation transformation) {
transformation.clear();
transformation.setTransformationType(Transformation.TYPE_MATRIX);
// Center of the view
float centerX = (float)getWidth()/2, centerY = (float)getHeight()/2;
// Save camera
mCamera.save();
// Translate the item to it's coordinates
final Matrix matrix = transformation.getMatrix();
matrix.reset();
mCamera.translate(((CarouselItem)child).getItemX(), ((CarouselItem)child).getItemY(),
((CarouselItem)child).getItemZ());
// rotation start
float rotationAngle = ((CarouselItem)child).getCurrentAngle();
if(rotationAngle > 90){
rotationAngle = 180 - rotationAngle;
}
if(rotationAngle < -90){
rotationAngle = 180 - rotationAngle;
rotationAngle = -1 * (360 - rotationAngle);
}
mCamera.rotateY(rotationAngle);
// rotation end
// Align the item
mCamera.getMatrix(matrix);
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
float[] values = new float[9];
matrix.getValues(values);
// Restore camera
mCamera.restore();
Matrix mm = new Matrix();
mm.setValues(values);
((CarouselItem)child).setCIMatrix(mm);
//http://code.google.com/p/android/issues/detail?id=35178
child.invalidate();
return true;
}
项目的位置搞砸了,看项目的相对距离中心项目:
我的想法。任何想法这是从哪里来的?
所以招行 ** mCamera.translate(((CarouselItem)子).getItemX(),((CarouselItem)子).getItemY(), ((CarouselItem)子).getItemZ()); * ** //旋转结束后** **? – murkr
移动上面提到的线没有做到这一点。旋转木马看起来不同,但仍然很奇怪。我切换了错误的行吗? – murkr
如果我有先旋转线,然后翻译线,旋转木马项目进一步分开,项目上下(从中心项目:上升,下降,停留,上下)。 – murkr