2017-09-01 149 views
0

所以,我实现了一个旋转木马就像Android 3D Carouselandroid:camera.rotateY()神秘地扭曲旋转木马

现在,只要我的getChildStaticTransformation(查看孩子,转型改造)方法是这样的:一旦

enter image description here

,但正如我:

@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; 
} 

项目的位置搞砸了,看项目的相对距离中心项目:

enter image description here

我的想法。任何想法这是从哪里来的?

回答

0

你必须切换矩阵乘法的方向。 我的意思是,你必须先申请轮换。只有在此之后,您才可以翻译该对象。

使用方向:缩放,旋转,翻译。

+0

所以招行 ** mCamera.translate(((CarouselItem)子).getItemX(),((CarouselItem)子).getItemY(), ((CarouselItem)子).getItemZ()); * ** //旋转结束后** **? – murkr

+0

移动上面提到的线没有做到这一点。旋转木马看起来不同,但仍然很奇怪。我切换了错误的行吗? – murkr

+0

如果我有先旋转线,然后翻译线,旋转木马项目进一步分开,项目上下(从中心项目:上升,下降,停留,上下)。 – murkr