/**
   * 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
  public boolean getWorkspaceChildStaticTransformation(
      ViewGroup parent,
      View view,
      Transformation transformation,
      Camera camera,
      float ratio,
      int currentScreen,
      float indicatorOffset,
      boolean isPortrait) {
    // TODO Auto-generated method stub
    float width = 0.0f;
    float height = 0.0f;
    float angle = 0.0f;
    Matrix matrix = transformation.getMatrix();

    if (isPortrait) {
      width = view.getMeasuredWidth();
      height = view.getMeasuredHeight() - indicatorOffset;

      angle = -90.0f * ratio;
      matrix.setRotate(angle, width / 2.0f, height);
    } else {
      width = view.getMeasuredWidth() - indicatorOffset;
      height = view.getMeasuredHeight();

      angle = 90.0f * ratio;
      matrix.setRotate(angle, width, height / 2.0f);
    }

    transformation.setTransformationType(Transformation.TYPE_MATRIX);
    return true;
  }
  public boolean stepAnimation(long now) {
    if (mEnterAnimation == null && mExitAnimation == null) {
      return false;
    }

    if (!mStarted) {
      if (mEnterAnimation != null) {
        mEnterAnimation.setStartTime(now);
      }
      if (mExitAnimation != null) {
        mExitAnimation.setStartTime(now);
      }
      mStarted = true;
    }

    mExitTransformation.clear();
    boolean moreExit = false;
    if (mExitAnimation != null) {
      moreExit = mExitAnimation.getTransformation(now, mExitTransformation);
      if (DEBUG) Slog.v(TAG, "Stepped exit: " + mExitTransformation);
      if (!moreExit) {
        if (DEBUG) Slog.v(TAG, "Exit animation done!");
        mExitAnimation.cancel();
        mExitAnimation = null;
        mExitTransformation.clear();
        if (mSurface != null) {
          mSurface.hide();
        }
      }
    }

    mEnterTransformation.clear();
    boolean moreEnter = false;
    if (mEnterAnimation != null) {
      moreEnter = mEnterAnimation.getTransformation(now, mEnterTransformation);
      if (!moreEnter) {
        mEnterAnimation.cancel();
        mEnterAnimation = null;
        mEnterTransformation.clear();
        if (mBlackFrame != null) {
          mBlackFrame.hide();
        }
      } else {
        if (mBlackFrame != null) {
          mBlackFrame.setMatrix(mEnterTransformation.getMatrix());
        }
      }
    }

    mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
    setSnapshotTransform(mSnapshotFinalMatrix, mExitTransformation.getAlpha());

    return moreEnter || moreExit;
  }
Beispiel #4
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);
  }
 // ���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);
 }
Beispiel #6
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();
 }
  @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);
  }
Beispiel #8
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
    // 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);
  }
Beispiel #10
0
  public void drawNinePatch(NinePatchTexture tex, int x, int y, int width, int height) {

    NinePatchChunk chunk = tex.getNinePatchChunk();

    // The code should be easily extended to handle the general cases by
    // allocating more space for buffers. But let's just handle the only
    // use case.
    if (chunk.mDivX.length != 2 || chunk.mDivY.length != 2) {
      throw new RuntimeException("unsupported nine patch");
    }
    if (!tex.bind(this, mGL)) {
      throw new RuntimeException("cannot bind" + tex.toString());
    }
    if (width <= 0 || height <= 0) return;

    int divX[] = mNinePatchX;
    int divY[] = mNinePatchY;
    float divU[] = mNinePatchU;
    float divV[] = mNinePatchV;

    int nx = stretch(divX, divU, chunk.mDivX, tex.getWidth(), width);
    int ny = stretch(divY, divV, chunk.mDivY, tex.getHeight(), height);

    setAlphaValue(mTransformation.getAlpha());
    Matrix matrix = mTransformation.getMatrix();
    matrix.getValues(mMatrixValues);
    GL11 gl = mGL;
    gl.glPushMatrix();
    gl.glMultMatrixf(toGLMatrix(mMatrixValues), 0);
    gl.glTranslatef(x, y, 0);
    drawMesh(divX, divY, divU, divV, nx, ny);
    gl.glPopMatrix();
  }
 protected void applyTransformation(float interpolatedTime, Transformation t) {
   View view = mView.get();
   if (view != null) {
     t.setAlpha(mAlpha);
     transformMatrix(t.getMatrix(), view);
   }
 }
Beispiel #12
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();
  }
  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 onDraw(Canvas canvas) {
    if (mImage != null) {
      // Switch the current animation if needed.
      if (mCurrentAnim == null || mCurrentAnim.hasEnded()) switchAnimation(canvas);

      // Animate and draw
      mCurrentAnim.getTransformation(AnimationUtils.currentAnimationTimeMillis(), mTrans);
      mStartPos[0] = 0;
      mStartPos[1] = 0;
      mTrans.getMatrix().mapPoints(mStartPos);

      mSrc.set(0, 0, mImage.getWidth(), mImage.getHeight());
      mDst.set(
          (int) mStartPos[0],
          (int) mStartPos[1],
          (int) mStartPos[0] + mScaledImageWidth,
          (int) mStartPos[1] + mScaledImageHeight);
      mPaint.setFilterBitmap(true);
      canvas.drawBitmap(mImage, mSrc, mDst, mPaint);
      super.onDraw(canvas);

      // Request another draw operation until time is up.
      invalidate();
    }
  }
  void updateSurfacesInTransaction() {
    if (!mStarted) {
      return;
    }

    if (mSurface != null) {
      if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
        if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
        mSurface.hide();
      }
    }

    if (mCustomBlackFrame != null) {
      if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
        if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
        mCustomBlackFrame.hide();
      } else {
        mCustomBlackFrame.setMatrix(mFrameTransformation.getMatrix());
      }
    }

    if (mExitingBlackFrame != null) {
      if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
        if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding exiting frame");
        mExitingBlackFrame.hide();
      } else {
        mExitFrameFinalMatrix.setConcat(mExitTransformation.getMatrix(), mFrameInitialMatrix);
        mExitingBlackFrame.setMatrix(mExitFrameFinalMatrix);
      }
    }

    if (mEnteringBlackFrame != null) {
      if (!mMoreStartEnter && !mMoreFinishEnter && !mMoreRotateEnter) {
        if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding entering frame");
        mEnteringBlackFrame.hide();
      } else {
        mEnteringBlackFrame.setMatrix(mEnterTransformation.getMatrix());
      }
    }

    setSnapshotTransformInTransaction(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
  }
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float degrees = mFromDegrees + ((mToDegrees - mFromDegrees) * interpolatedTime);
    if (mPivotX == 0.0f && mPivotY == 0.0f) {
      t.getMatrix().setRotate(degrees);
    } else {
      t.getMatrix().setRotate(degrees, mPivotX, mPivotY);
    }

    float dx = mFromXDelta;
    float dy = mFromYDelta;
    if (mFromXDelta != mToXDelta) {
      dx = mFromXDelta + ((mToXDelta - mFromXDelta) * interpolatedTime);
    }
    if (mFromYDelta != mToYDelta) {
      dy = mFromYDelta + ((mToYDelta - mFromYDelta) * interpolatedTime);
    }

    t.getMatrix().postTranslate(dx, dy);
  }
Beispiel #17
0
 @Override
 protected boolean getChildStaticTransformation(View child, Transformation t) {
   Matrix m = getViewMatrix(child);
   if (m != null) {
     t.getMatrix().set(m);
     t.setTransformationType(Transformation.TYPE_MATRIX);
     return true;
   } else {
     return false;
   }
 }
  @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);
  }
  @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);
 }
Beispiel #21
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();
  }
Beispiel #22
0
  /*
   * interpolatedTime 动画从0开始到1结束 t 动画的属性
   */
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {

    Matrix m = t.getMatrix();
    m.setTranslate((float) (Math.sin(interpolatedTime * 10) * 15), 0);
    if (state == 0) {
      t.setAlpha(interpolatedTime);
    } else {
      t.setAlpha(1 - interpolatedTime);
    }

    super.applyTransformation(interpolatedTime, t);
  }
Beispiel #23
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);
  }
Beispiel #24
0
  // This is a GLSurfaceView.Renderer callback
  public void onSurfaceChanged(GL10 gl1, int width, int height) {
    Log.v(TAG, "onSurfaceChanged: " + width + "x" + height + ", gl10: " + gl1.toString());
    GL11 gl = (GL11) gl1;
    mGL = gl;
    gl.glViewport(0, 0, width, height);

    gl.glMatrixMode(GL11.GL_PROJECTION);
    gl.glLoadIdentity();

    GLU.gluOrtho2D(gl, 0, width, 0, height);
    Matrix matrix = mTransformation.getMatrix();
    matrix.reset();
    matrix.preTranslate(0, getHeight());
    matrix.preScale(1, -1);
  }
Beispiel #25
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;
 }
Beispiel #26
0
  public void copyTexture2D(RawTexture texture, int x, int y, int width, int height)
      throws GLOutOfMemoryException {
    Matrix matrix = mTransformation.getMatrix();
    matrix.getValues(mMatrixValues);

    if (isMatrixRotatedOrFlipped(mMatrixValues)) {
      throw new IllegalArgumentException("cannot support rotated matrix");
    }
    float points[] = mapPoints(matrix, x, y + height, x + width, y);
    x = (int) points[0];
    y = (int) points[1];
    width = (int) points[2] - x;
    height = (int) points[3] - y;

    GL11 gl = mGL;
    int newWidth = Util.nextPowerOf2(width);
    int newHeight = Util.nextPowerOf2(height);
    int glError = GL11.GL_NO_ERROR;

    gl.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId());

    int[] cropRect = {0, 0, width, height};
    gl.glTexParameteriv(GL11.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, cropRect, 0);
    gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP_TO_EDGE);
    gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    gl.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, x, y, newWidth, newHeight, 0);
    glError = gl.glGetError();

    if (glError == GL11.GL_OUT_OF_MEMORY) {
      throw new GLOutOfMemoryException();
    }

    if (glError != GL11.GL_NO_ERROR) {
      throw new RuntimeException("Texture copy fail, glError " + glError);
    }

    texture.setSize(width, height);
    texture.setTextureSize(newWidth, newHeight);
  }
Beispiel #27
0
  public void clipRect(int x, int y, int width, int height) {
    float point[] = mapPoints(mTransformation.getMatrix(), x, y + height, x + width, y);

    // mMatrix could be a rotation matrix. In this case, we need to find
    // the boundaries after rotation. (only handle 90 * n degrees)
    if (point[0] > point[2]) {
      x = (int) point[2];
      width = (int) point[0] - x;
    } else {
      x = (int) point[0];
      width = (int) point[2] - x;
    }
    if (point[1] > point[3]) {
      y = (int) point[3];
      height = (int) point[1] - y;
    } else {
      y = (int) point[1];
      height = (int) point[3] - y;
    }
    mGL.glScissor(x, y, width, height);
  }
Beispiel #28
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);
  }
Beispiel #29
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();
  }
Beispiel #30
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;
  }