2013-04-24 116 views
0

我試圖使用平移和旋轉旋轉立方體。我正在使用Google示例中提供的名爲Rotate3dAnimation.java的類。旋轉工作得很好,我正在努力在旋轉時使立方體上的深度錯覺變得更加靠近屏幕。
要做到這一點,我修改了方法applyTransformation(float interpolatedTime, Transformation t),但問題在於,立方體(旋轉時隱藏的那個)的表面必須在前半段時間進一步移動,在第二個時間點再次靠近半。Android動畫 - applytransformation - 做一個攝像頭翻譯Z軸的一半時間

恢復:

Camera.translate(float x, float y, float z) 

在Z翻譯應減少對上半年並增加下半年。

這裏是代碼我使用:

@Override 
protected void applyTransformation(float interpolatedTime, Transformation t) { 
    final float fromDegrees = mFromDegrees; 
    float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime); 

    final float centerX = mCenterX; 
    final float centerY = mCenterY; 
    final String orientation = mOrientation; 
    final Camera camera = mCamera; 

    final Matrix matrix = t.getMatrix(); 
    camera.save(); 
    float midTime = getDuration()/2; 
    if (mReverse) { 
     camera.translate(0.0f, 0.0f, (interpolatedTime<midTime)? 
      (mDepthZ * interpolatedTime): (mDepthZ * (1.0f - interpolatedTime))); 

    } else { 

     camera.translate(0.0f, 0.0f, (interpolatedTime<midTime)? 
      (mDepthZ * (1.0f - interpolatedTime)): (mDepthZ * interpolatedTime)); 

    } 
    if(orientation.equals("horizontal")) 
     camera.rotateY(degrees); 
    else 
     camera.rotateX(degrees); 
    camera.getMatrix(matrix); 
    camera.restore(); 

    matrix.preTranslate(-centerX, -centerY); 
    matrix.postTranslate(centerX, centerY); 
} 

但我不認爲這是工作非常好...任何建議嗎?

謝謝!

回答

0

我實際上有同樣的問題,並經過一些調試後,我意識到interpolatedTime不是以毫秒爲單位,因爲我(我猜你)預期。這很好,所以你不必真的計算midTime的真實情況,你只需要知道插值的進度。

要檢查,如果你中途與動畫只使用

(interpolatedTime < .5)

在三元聲明。