Exemple #1
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();
  }
 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);
 }
Exemple #4
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);
  }
  @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);
  }
Exemple #6
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);
  }
  @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);
  }
Exemple #8
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);
  }
Exemple #9
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);
  }
  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));
  }