/** * 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) { 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); }
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(); }
@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); }
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(); }
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); }
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) { // 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); }
// ���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); }
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(); }
@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); }
@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); }
@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); }
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); }
// @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); }
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 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); }
@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); }
/** * 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)); }
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(); }