Esempio n. 1
0
  @Override
  public Transformation getParentToLocalTransformation() {
    if (this.mParentToLocalTransformation == null) {
      this.mParentToLocalTransformation = new Transformation();
    }

    final Transformation parentToLocalTransformation = this.mParentToLocalTransformation;
    if (this.mParentToLocalTransformationDirty) {
      parentToLocalTransformation.setToIdentity();

      /* Offset. */
      parentToLocalTransformation.postTranslate(this.mLocalOffsetCenterX, this.mLocalOffsetCenterY);

      /* Translation. */
      parentToLocalTransformation.postTranslate(-this.mX, -this.mY);

      /* Rotation. */
      final float rotation = this.mRotation;
      if (rotation != 0) {
        final float localRotationCenterX = this.mLocalRotationCenterX;
        final float localRotationCenterY = this.mLocalRotationCenterY;

        parentToLocalTransformation.postTranslate(-localRotationCenterX, -localRotationCenterY);
        parentToLocalTransformation.postRotate(rotation);
        parentToLocalTransformation.postTranslate(localRotationCenterX, localRotationCenterY);
      }

      /* Skew. */
      final float skewX = this.mSkewX;
      final float skewY = this.mSkewY;
      if ((skewX != 0) || (skewY != 0)) {
        final float localSkewCenterX = this.mLocalSkewCenterX;
        final float localSkewCenterY = this.mLocalSkewCenterY;

        parentToLocalTransformation.postTranslate(-localSkewCenterX, -localSkewCenterY);
        parentToLocalTransformation.postSkew(-skewX, -skewY);
        parentToLocalTransformation.postTranslate(localSkewCenterX, localSkewCenterY);
      }

      /* Scale. */
      final float scaleX = this.mScaleX;
      final float scaleY = this.mScaleY;
      if ((scaleX != 1) || (scaleY != 1)) {
        final float localScaleCenterX = this.mLocalScaleCenterX;
        final float localScaleCenterY = this.mLocalScaleCenterY;

        parentToLocalTransformation.postTranslate(-localScaleCenterX, -localScaleCenterY);
        parentToLocalTransformation.postScale(
            1 / scaleX,
            1
                / scaleY); // TODO Division could be replaced by a multiplication of
                           // 'scale(X/Y)Inverse'...
        parentToLocalTransformation.postTranslate(localScaleCenterX, localScaleCenterY);
      }

      this.mParentToLocalTransformationDirty = false;
    }
    return parentToLocalTransformation;
  }
Esempio n. 2
0
  @Override
  public Transformation getLocalToParentTransformation() {
    if (this.mLocalToParentTransformation == null) {
      this.mLocalToParentTransformation = new Transformation();
    }

    final Transformation localToParentTransformation = this.mLocalToParentTransformation;
    if (this.mLocalToParentTransformationDirty) {
      localToParentTransformation.setToIdentity();

      /* Scale. */
      final float scaleX = this.mScaleX;
      final float scaleY = this.mScaleY;
      if ((scaleX != 1) || (scaleY != 1)) {
        final float scaleCenterX = this.mLocalScaleCenterX;
        final float scaleCenterY = this.mLocalScaleCenterY;

        /* TODO Check if it is worth to check for scaleCenterX == 0 && scaleCenterY == 0 as the two postTranslate can be saved.
         * The same obviously applies for all similar occurrences of this pattern in this class. */

        localToParentTransformation.postTranslate(-scaleCenterX, -scaleCenterY);
        localToParentTransformation.postScale(scaleX, scaleY);
        localToParentTransformation.postTranslate(scaleCenterX, scaleCenterY);
      }

      /* Skew. */
      final float skewX = this.mSkewX;
      final float skewY = this.mSkewY;
      if ((skewX != 0) || (skewY != 0)) {
        final float skewCenterX = this.mLocalSkewCenterX;
        final float skewCenterY = this.mLocalSkewCenterY;

        localToParentTransformation.postTranslate(-skewCenterX, -skewCenterY);
        localToParentTransformation.postSkew(skewX, skewY);
        localToParentTransformation.postTranslate(skewCenterX, skewCenterY);
      }

      /* Rotation. */
      final float rotation = this.mRotation;
      if (rotation != 0) {
        final float rotationCenterX = this.mLocalRotationCenterX;
        final float rotationCenterY = this.mLocalRotationCenterY;

        localToParentTransformation.postTranslate(-rotationCenterX, -rotationCenterY);
        localToParentTransformation.postRotate(-rotation);
        localToParentTransformation.postTranslate(rotationCenterX, rotationCenterY);
      }

      /* Translation. */
      localToParentTransformation.postTranslate(this.mX, this.mY);

      /* Offset. */
      localToParentTransformation.postTranslate(
          -this.mLocalOffsetCenterX, -this.mLocalOffsetCenterY);

      this.mLocalToParentTransformationDirty = false;
    }
    return localToParentTransformation;
  }