/**
   * Transform the Image Bitmap by the Angle passed
   *
   * @param imageView ImageView the ImageView whose bitmap we want to rotate
   * @param t transformation
   * @param rotationAngle the Angle by which to rotate the Bitmap
   */
  private void transformBitmap(View child, Transformation t, int rotationAngle) {

    final Matrix childMatrix = t.getMatrix();
    final int childHeight = child.getLayoutParams().height;
    final int childWidth = child.getLayoutParams().width;
    final int rotation = Math.abs(rotationAngle);

    mCamera.save();
    mCamera.translate(0.0f, 0.0f, 100.0f);
    // As the angle of the view gets less, zoom in
    if (rotation <= mMaxRotationAngle) {
      float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
      mCamera.translate(0.0f, 0.0f, zoomAmount);
      if (mCircleMode) {
        if (rotation < 40) mCamera.translate(0.0f, 155, 0.0f);
        else mCamera.translate(0.0f, (255 - rotation * 2.5f), 0.0f);
      }
      if (mAlphaMode) {
        ((ImageView) (child)).setAlpha((int) (255 - rotation * 2.5));
      }
    }
    mCamera.rotateY(rotationAngle);
    mCamera.getMatrix(childMatrix);
    childMatrix.preTranslate(-(childWidth / 2), -(childHeight / 2));
    childMatrix.postTranslate((childWidth / 2), (childHeight / 2));
    mCamera.restore();
  }
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    // Angle around the y-axis of the rotation at the given time
    // calculated both in radians and degrees.
    final double radians = Math.PI * interpolatedTime;
    float degrees = (float) (180.0 * radians / Math.PI);

    // Once we reach the midpoint in the animation, we need to hide the
    // source view and show the destination view. We also need to change
    // the angle by 180 degrees so that the destination does not come in
    // flipped around
    if (interpolatedTime >= 0.5f) {
      degrees -= 180.f;
      fromView.setVisibility(View.GONE);
      toView.setVisibility(View.VISIBLE);
    }

    if (forward) degrees = -degrees; // determines direction of rotation when flip begins

    final Matrix matrix = t.getMatrix();
    camera.save();
    camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();
    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
  }
Ejemplo n.º 3
0
 private synchronized void BeginRolate(Matrix matrix, float rolateX, float rolateY) {
   // Bitmap bm = getImageBitmap();
   int scaleX = (int) (vWidth * 0.5f);
   int scaleY = (int) (vHeight * 0.5f);
   camera.save();
   camera.rotateX(RolateY > 0 ? rolateY : -rolateY);
   camera.rotateY(RolateX < 0 ? rolateX : -rolateX);
   camera.getMatrix(matrix);
   camera.restore();
   // ┐поколл─хс
   if (RolateX > 0 && rolateX != 0) {
     matrix.preTranslate(-vWidth, -scaleY);
     matrix.postTranslate(vWidth, scaleY);
   } else if (RolateY > 0 && rolateY != 0) {
     matrix.preTranslate(-scaleX, -vHeight);
     matrix.postTranslate(scaleX, vHeight);
   } else if (RolateX < 0 && rolateX != 0) {
     matrix.preTranslate(-0, -scaleY);
     matrix.postTranslate(0, scaleY);
   } else if (RolateY < 0 && rolateY != 0) {
     matrix.preTranslate(-scaleX, -0);
     matrix.postTranslate(scaleX, 0);
   }
   setImageMatrix(matrix);
 }
 // ���Transformation
 @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 Camera camera = mCamera;
   final Matrix matrix = t.getMatrix();
   camera.save();
   if (mReverse) {
     camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
   } else {
     camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
   }
   if (mRotate.equals("y")) {
     camera.rotateY(degrees);
   } else if (mRotate.equals("x")) {
     camera.rotateX(degrees);
   } else if (mRotate.equals("z")) {
     camera.rotateZ(degrees);
   }
   // ȡ�ñ任��ľ���
   camera.getMatrix(matrix);
   camera.restore();
   matrix.preTranslate(-centerX, -centerY);
   matrix.postTranslate(centerX, centerY);
 }
Ejemplo n.º 5
0
  /**
   * Transform the Image Bitmap by the Angle passed
   *
   * @param imageView ImageView the ImageView whose bitmap we want to rotate
   * @param t transformation
   * @param rotationAngle the Angle by which to rotate the Bitmap
   */
  private void transformImageBitmap(ImageView child, Transformation t, float angle, float deltaY) {
    mCamera.save();
    final Matrix imageMatrix = t.getMatrix();
    final int imageHeight = child.getLayoutParams().height;
    final int imageWidth = child.getLayoutParams().width;

    mCamera.translate(0.0f, -(float) deltaY, 0.0f);
    mCamera.rotateZ(angle);
    mCamera.getMatrix(imageMatrix);
    imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
    imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
    mCamera.restore();
  }
Ejemplo n.º 6
0
 @Override
 protected void applyTransformation(float interpolatedTime, Transformation t) {
   super.applyTransformation(interpolatedTime, t);
   camera.save();
   camera.translate(width - interpolatedTime * width, 0, 0);
   camera.rotateY(interpolatedTime * 60);
   camera.getMatrix(matrix);
   Logger.e(matrix.toString());
   camera.restore();
   //        matrix.preScale(1,1+interpolatedTime);
   //        matrix.preTranslate(540, 0);
   t.getMatrix().postConcat(matrix);
 }
Ejemplo n.º 7
0
  protected float getOffsetXForRotation(float degrees, int width, int height) {
    mMatrix.reset();
    mCamera.save();
    mCamera.rotateY(Math.abs(degrees));
    mCamera.getMatrix(mMatrix);
    mCamera.restore();

    mMatrix.preTranslate(-width * 0.5f, -height * 0.5f);
    mMatrix.postTranslate(width * 0.5f, height * 0.5f);
    mTempFloat2[0] = width;
    mTempFloat2[1] = height;
    mMatrix.mapPoints(mTempFloat2);
    return (width - mTempFloat2[0]) * (degrees > 0.0f ? 1.0f : -1.0f);
  }
  protected static final float getOffsetXForRotation(float degrees, int width, int height) {
    OFFSET_MATRIX.reset();
    OFFSET_CAMERA.save();
    OFFSET_CAMERA.rotateY(Math.abs(degrees));
    OFFSET_CAMERA.getMatrix(OFFSET_MATRIX);
    OFFSET_CAMERA.restore();

    OFFSET_MATRIX.preTranslate(-width * 0.5f, -height * 0.5f);
    OFFSET_MATRIX.postTranslate(width * 0.5f, height * 0.5f);
    OFFSET_TEMP_FLOAT[0] = width;
    OFFSET_TEMP_FLOAT[1] = height;
    OFFSET_MATRIX.mapPoints(OFFSET_TEMP_FLOAT);
    return (width - OFFSET_TEMP_FLOAT[0]) * (degrees > 0.0f ? 1.0f : -1.0f);
  }
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    // Angle around the y-axis of the rotation at the given time. It is
    // calculated both in radians and in the equivalent degrees.
    final double radians = Math.PI * interpolatedTime;
    float degrees = (float) (180.0 * radians / Math.PI);

    // Once we reach the midpoint in the animation, we need to hide the
    // source view and show the destination view. We also need to change
    // the angle by 180 degrees so that the destination does not come in
    // flipped around. This is the main problem with SDK sample, it does not
    // do this.
    if (interpolatedTime >= 0.5f) {
      degrees -= 180.f;

      if (!visibilitySwapped) {
        fromView.setVisibility(View.GONE);
        toView.setVisibility(View.VISIBLE);

        visibilitySwapped = true;
      }
    }

    if (forward) degrees = -degrees;

    final Matrix matrix = t.getMatrix();

    camera.save();

    if (translateDirection == DIRECTION_Z) {
      camera.translate(0.0f, 0.0f, (float) (150.0 * Math.sin(radians)));
    } else if (translateDirection == DIRECTION_Y) {
      camera.translate(0.0f, (float) (150.0 * Math.sin(radians)), 0.0f);
    } else {
      camera.translate((float) (150.0 * Math.sin(radians)), 0.0f, 0.0f);
    }

    if (rotationDirection == DIRECTION_Z) {
      camera.rotateZ(degrees);
    } else if (rotationDirection == DIRECTION_Y) {
      camera.rotateY(degrees);
    } else {
      camera.rotateX(degrees);
    }

    //        camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
  }
Ejemplo n.º 10
0
 protected boolean getChildStaticTransformation(View child, Transformation t) {
   t.clear();
   t.setTransformationType(Transformation.TYPE_MATRIX);
   mCamera.save();
   final Matrix imageMatrix = t.getMatrix();
   if (flag) {
     firstChildWidth = getChildAt(0).getWidth();
     Log.i(TAG, "firstChildWidth = " + firstChildWidth);
     firstChildPaddingLeft = getChildAt(0).getPaddingLeft();
     flag = false;
   }
   offsetX = firstChildWidth / 2 + firstChildPaddingLeft + mPaddingLeft - mWidth / 2;
   mCamera.translate(offsetX, 0f, 0f);
   mCamera.getMatrix(imageMatrix);
   mCamera.restore();
   return true;
 }
Ejemplo n.º 11
0
  private void drawFlippingHalf(Canvas canvas) {
    canvas.save();
    mCamera.save();

    final float degreesFlipped = getDegreesFlipped();

    if (degreesFlipped > 90) {
      canvas.clipRect(isFlippingVertically() ? mTopRect : mLeftRect);
      if (mIsFlippingVertically) {
        mCamera.rotateX(degreesFlipped - 180);
      } else {
        mCamera.rotateY(180 - degreesFlipped);
      }
    } else {
      canvas.clipRect(isFlippingVertically() ? mBottomRect : mRightRect);
      if (mIsFlippingVertically) {
        mCamera.rotateX(degreesFlipped);
      } else {
        mCamera.rotateY(-degreesFlipped);
      }
    }

    mCamera.getMatrix(mMatrix);

    positionMatrix();
    canvas.concat(mMatrix);

    setDrawWithLayer(mCurrentPage.v, true);
    drawChild(canvas, mCurrentPage.v, 0);

    drawFlippingShadeShine(canvas);

    mCamera.restore();
    canvas.restore();
  }
Ejemplo n.º 12
0
 /**
  * Transform the Image Bitmap by the Angle passed
  *
  * @param imageView ImageView the ImageView whose bitmap we want to rotate
  * @param t transformation
  * @param rotationAngle the Angle by which to rotate the Bitmap
  */
 private void transformImageBitmap(View child, Transformation t, int rotationAngle, int d) {
   mCamera.save();
   final Matrix imageMatrix = t.getMatrix();
   final int imageHeight = child.getLayoutParams().height;
   final int imageWidth = child.getLayoutParams().width;
   final int rotation = Math.abs(rotationAngle);
   // mCamera.translate(0.0f, 0.0f, 100.0f);
   // As the angle of the view gets less, zoom in
   // if (rotation <= mMaxRotationAngle) {
   float zoomAmount = (float) (-140 + (rotation * 2));
   if (rotationAngle < 0) {
     mCamera.translate((float) (-rotation * 0.5), (float) (-rotation * 0.3) + 5, zoomAmount);
   } else {
     mCamera.translate((float) rotation, (float) (-rotation * 0.3) + 5, zoomAmount);
   }
   Log.i("info", "---------------------->" + rotationAngle);
   if (mCircleMode) {
     if (rotation < 40) {
       mCamera.translate(0.0f, 155, 0.0f);
     } else {
       mCamera.translate(0.0f, (255 - rotation * 2.5f), 0.0f);
     }
   }
   if (mAlphaMode) {
     // child.setBackgroundDrawable(getResources().getDrawable(R.drawable.app_bg));
     // child.setBackgroundColor(255);
   }
   // }
   // mCamera.rotateY(rotationAngle);
   mCamera.getMatrix(imageMatrix);
   imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
   imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
   mCamera.restore();
 }
Ejemplo n.º 13
0
  private void transformMatrix(Matrix m, View view) {
    final float w = view.getWidth();
    final float h = view.getHeight();
    final boolean hasPivot = mHasPivot;
    final float pX = hasPivot ? mPivotX : w / 2f;
    final float pY = hasPivot ? mPivotY : h / 2f;

    final float rX = mRotationX;
    final float rY = mRotationY;
    final float rZ = mRotationZ;
    if ((rX != 0) || (rY != 0) || (rZ != 0)) {
      final Camera camera = mCamera;
      camera.save();
      camera.rotateX(rX);
      camera.rotateY(rY);
      camera.rotateZ(-rZ);
      camera.getMatrix(m);
      camera.restore();
      m.preTranslate(-pX, -pY);
      m.postTranslate(pX, pY);
    }

    final float sX = mScaleX;
    final float sY = mScaleY;
    if ((sX != 1.0f) || (sY != 1.0f)) {
      m.postScale(sX, sY);
      final float sPX = -(pX / w) * ((sX * w) - w);
      final float sPY = -(pY / h) * ((sY * h) - h);
      m.postTranslate(sPX, sPY);
    }

    m.postTranslate(mTranslationX, mTranslationY);
  }
Ejemplo n.º 14
0
  @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 Camera camera = mCamera;

    final Matrix matrix = t.getMatrix();

    camera.save();

    camera.rotateY(degrees);

    camera.getMatrix(matrix);
    camera.restore();

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
  }
Ejemplo n.º 15
0
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromDegrees = mFromDegrees;
    float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);

    final Matrix matrix = t.getMatrix();

    mCamera.save();
    switch (mRollType) {
      case ROLL_BY_X:
        mCamera.rotateX(degrees);
        break;
      case ROLL_BY_Y:
        mCamera.rotateY(degrees);
        break;
      case ROLL_BY_Z:
        mCamera.rotateZ(degrees);
        break;
    }
    mCamera.getMatrix(matrix);
    mCamera.restore();

    matrix.preTranslate(-mPivotX, -mPivotY);
    matrix.postTranslate(mPivotX, mPivotY);
  }
Ejemplo n.º 16
0
  private void transformImageBitmap(ImageView child, Transformation t, int rotationAngle) {
    // 对效果进行保存
    mCamera.save();
    final Matrix imageMatrix = t.getMatrix();
    // 图片高度
    final int imageHeight = child.getLayoutParams().height;
    // 图片宽度
    final int imageWidth = child.getLayoutParams().width;

    // 返回旋转角度的绝对值
    final int rotation = Math.abs(rotationAngle);

    // 在Z轴上正向移动camera的视角,实际效果为放大图片。
    // 如果在Y轴上移动,则图片上下移动;X轴上对应图片左右移动。
    mCamera.translate(0.0f, 0.0f, 100.0f);
    // As the angle of the view gets less, zoom in
    if (rotation < mMaxRotationAngle) {
      float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
      mCamera.translate(0.0f, 0.0f, zoomAmount);
    }
    // 在Y轴上旋转,对应图片竖向向里翻转。
    // 如果在X轴上旋转,则对应图片横向向里翻转。
    mCamera.rotateY(rotationAngle);
    mCamera.getMatrix(imageMatrix);
    imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
    imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
    mCamera.restore();
  }
Ejemplo n.º 17
0
  /**
   * Transform an item depending on it's coordinates.
   *
   * @param child the child
   * @param transformation the transformation
   * @return the child static transformation
   */
  @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();

    mCamera.translate(
        ((CarouselItemView) child).getItemX(),
        ((CarouselItemView) child).getItemY(),
        ((CarouselItemView) 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);
    ((CarouselItemView) child).setCIMatrix(mm);

    // http://code.google.com/p/android/issues/detail?id=35178
    child.invalidate();
    return true;
  }
Ejemplo n.º 18
0
  private void transformImageBitmap(ImageView child, Transformation trans, int rotationAngle) {
    mCamera.save();

    final Matrix imageMatrix = trans.getMatrix();
    final int imageHeight = child.getLayoutParams().height;
    final int imageWidth = child.getLayoutParams().width;
    final int rotation = Math.abs(rotationAngle);

    // 在Z轴上正向移动camera的视角,实际效果为放大图片; 如果在Y轴上移动,则图片上下移动; X轴上对应图片左右移动。
    mCamera.translate(0.0f, 0.0f, -20.0f);

    // As the angle of the view gets less, zoom in
    if (rotation < mMaxRotationAngle) {
      float zoomAmount = (float) (mMaxZoom + (rotation * 1.0));
      mCamera.translate(0.0f, 0.0f, zoomAmount);
    }

    mCamera.rotateY(rotationAngle); // rotationAngle 为正,沿y轴向内旋转; 为负,沿y轴向外旋转

    mCamera.getMatrix(imageMatrix);
    imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
    imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));

    mCamera.restore();
  }
Ejemplo n.º 19
0
  @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 Camera camera = mCamera;

    final Matrix matrix = t.getMatrix();

    camera.save();

    if (mDirection == ROTATION_X) camera.rotateX(degrees);
    else camera.rotateY(degrees);

    camera.getMatrix(matrix);
    camera.restore();

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

    matrix.preScale(
        scaleType.getScale(scale, interpolatedTime),
        scaleType.getScale(scale, interpolatedTime),
        centerX,
        centerY);
  }
Ejemplo n.º 20
0
  // @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    float degrees = m_FromDegrees + ((m_ToDegrees - m_FromDegrees) * interpolatedTime);
    final Camera camera = m_Camera;
    final Matrix matrix = t.getMatrix();
    camera.save();

    if (m_YAxis) camera.rotateY(degrees);
    else camera.rotateX(degrees);

    camera.getMatrix(matrix);
    camera.restore();
    matrix.preTranslate(-m_CenterX, -m_CenterY);
    matrix.postTranslate(m_CenterX, m_CenterY);
  }
Ejemplo n.º 21
0
  @Override
  public void apply(Canvas canvas, String textValue, float x, float y, Paint paint) {

    camera.getMatrix(cameraMatrix);
    camera.save();
    camera.rotateX(rotationX);
    camera.rotateY(rotationY);
    camera.getMatrix(cameraMatrix);

    cameraMatrix.preTranslate(cameraTransXPre, cameraTransYPre);
    cameraMatrix.postTranslate(cameraTransXPost, cameraTransYPost);

    camera.restore();

    canvas.concat(cameraMatrix);
  }
Ejemplo n.º 22
0
  /**
   * Transform the Image Bitmap by the Angle passed
   *
   * @param view ImageView the ImageView whose bitmap we want to rotate
   * @param t transformation
   * @param rotationAngle the Angle by which to rotate the Bitmap
   */
  private void transformImageBitmap(View view, Transformation t, int rotationAngle) {
    mCamera.save();
    final Matrix imageMatrix = t.getMatrix();
    final int imageHeight = view.getLayoutParams().height;
    final int imageWidth = view.getLayoutParams().width;
    final int rotation = Math.abs(rotationAngle);

    mCamera.translate(0.0f, 0.0f, 100.0f);

    // As the angle of the view gets less, zoom in
    if (rotation < mMaxRotationAngle) {
      float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
      mCamera.translate(0.0f, 0.0f, zoomAmount);
    }

    mCamera.rotateY(rotationAngle);
    mCamera.getMatrix(imageMatrix);
    imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
    imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
    mCamera.restore();
  }
  private void prepareMatrix(final Matrix outMatrix, int distanceY, int r) {
    // clip the distance
    final int d = Math.min(r, Math.abs(distanceY));
    // use circle formula
    final float translateZ = (float) Math.sqrt((r * r) - (d * d));

    // solve for t: d = r*cos(t)
    double radians = Math.acos((float) d / r);
    double degree = 90 - (180 / Math.PI) * radians;

    mCamera.save();
    mCamera.translate(0, 0, r - translateZ);
    mCamera.rotateX((float) degree);
    if (distanceY < 0) {
      degree = 360 - degree;
    }
    mCamera.rotateY((float) degree);
    mCamera.getMatrix(outMatrix);
    mCamera.restore();

    // highlight elements in the middle
    mPaint.setColorFilter(calculateLight((float) degree));
  }
Ejemplo n.º 24
0
  protected void applyTransformation(float var1, Transformation var2) {
    double var3;
    if (this.mReverse) {
      var3 = 0.0D;
    } else {
      double var10 = (double) var1;
      double var12 = 2.6179938779914944D * var10;
      var3 = 2.0943951023931953D + var12;
    }

    Camera var5 = this.mCamera;
    Matrix var6 = var2.getMatrix();
    var5.save();
    if (this.mReverse) {
      float var7 = this.mCenterX * var1;
      float var8 = this.mCenterY * var1;
      float var9 = this.mDepthZ * var1;
      var5.translate(var7, var8, var9);
    } else {
      float var14 = this.mCenterX;
      float var15 = this.mMoveX * var1;
      float var16 = (float) Math.cos(var3);
      float var17 = var15 * var16;
      float var18 = var14 + var17;
      float var19 = this.mCenterY;
      float var20 = this.mMoveY * var1;
      float var21 = (float) Math.sin(var3);
      float var22 = var20 * var21;
      float var23 = var19 - var22;
      float var24 = this.mDepthZ;
      var5.translate(var18, var23, var24);
    }

    var5.getMatrix(var6);
    var5.restore();
  }
Ejemplo n.º 25
0
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float FromDegree = mFromDegree;
    float degrees = FromDegree + (mToDegree - mFromDegree) * interpolatedTime;
    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Matrix matrix = t.getMatrix();

    if (degrees <= -76.0f) {
      degrees = -90.0f;
      mCamera.save();
      mCamera.rotateY(degrees);
      mCamera.getMatrix(matrix);
      mCamera.restore();
    } else if (degrees >= 76.0f) {
      degrees = 90.0f;
      mCamera.save();
      mCamera.rotateY(degrees);
      mCamera.getMatrix(matrix);
      mCamera.restore();
    } else {
      mCamera.save();
      // 这里很重要哦。
      mCamera.translate(0, 0, centerX);
      mCamera.rotateY(degrees);
      mCamera.translate(0, 0, -centerX);
      mCamera.getMatrix(matrix);
      mCamera.restore();
    }

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
  }
Ejemplo n.º 26
0
  void rotate(int degreeX, Bitmap turnBmpBack) {

    deltaX += degreeX;

    if (isLR) {

      if (deltaX > 180) {
        deltaX = 180;
      } else if (deltaX < 0) {
        deltaX = 0;
      } else if (deltaX > 90) {
        tmpLbmp = turnBmpBack;
      } else if (deltaX < 90) {
        tmpLbmp = Lbmp;
      }

      mCamera.save();
      mCamera.rotateY(deltaX);
      mCamera.translate(-centerX, 0, 0);
      mCamera.getMatrix(mMatrix);
      mCamera.restore();

      mMatrix.preTranslate(0, -centerY);
      mMatrix.postTranslate(centerX, centerY);

      Log.d(LOGTAG, "rotate you click [LEFT] deltaX " + deltaX);
    } else {

      if (deltaX < -180) {
        deltaX = -180;
      } else if (deltaX > 0) {
        deltaX = 0;
      } else if (deltaX < -90) {

        tmpRbmp = turnBmpBack;
      } else if (deltaX > -90) {
        tmpRbmp = Rbmp;
      }

      mCamera.save();
      mCamera.translate(0, 0, -1);
      mCamera.rotateY(deltaX);
      mCamera.getMatrix(mMatrix);
      mCamera.restore();

      mMatrix.preTranslate(0, -centerY);
      mMatrix.postTranslate(0, centerY);

      Log.d(LOGTAG, "rotate you click [RIGHT] deltaX " + deltaX);
    }

    mCamera.save();

    shadowX = (float) (centerX * Math.cos(Math.abs(deltaX * 1d)));

    Log.d(
        LOGTAG,
        "rotate shadowX >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "
            + shadowX
            + " Math.abs(deltaX*1d)) = "
            + Math.abs(deltaX * 1d)
            + "Math.cos(Math.abs(deltaX*1d) = "
            + Math.cos(Math.abs(deltaX * 1d)));
    Log.d(
        LOGTAG,
        "rotate shadowX >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Math.cos(75) = "
            + Math.cos(75.0 * 180 / Math.PI));
    postInvalidate();
  }
Ejemplo n.º 27
0
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float FromDegree = mFromDegree;
    float degrees = FromDegree + (mToDegree - mFromDegree) * interpolatedTime;
    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Matrix matrix = t.getMatrix();

    float[] values = new float[9];
    matrix.getValues(values);
    Log.d(
        TAG,
        "MATRIX  scale:"
            + values[0]
            + ", degrees:"
            + degrees
            + ", centerX:"
            + centerX
            + ", centerY:"
            + centerY);

    if (degrees <= -76.0f) {
      degrees = -90.0f;
      mCamera.save();
      mCamera.rotateY(degrees);
      mCamera.getMatrix(matrix);
      mCamera.restore();
    } else if (degrees >= 76.0f) {
      degrees = 90.0f;
      mCamera.save();
      mCamera.rotateY(degrees);
      mCamera.getMatrix(matrix);
      mCamera.restore();
    } else {
      mCamera.save();

      //			mCamera.translate(0, 0, centerX);
      //			mCamera.rotateY(degrees);
      //			mCamera.translate(0, 0, -centerX);

      // 逐渐拉远
      float deltaZ = 120 * LinkLinkApplication.SCREEN_DENSITY * Math.abs(degrees) / 90;
      mCamera.translate(0, 0, deltaZ);
      mCamera.rotateY(degrees);
      mCamera.translate(0, 0, -deltaZ);

      mCamera.getMatrix(matrix);
      mCamera.restore();
    }

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