Пример #1
0
  /**
   * Calculates the inverse of this transform.
   *
   * @return the inverted transform
   */
  public CCTransform invert() {
    CCTransform result = new CCTransform();

    if (_myIsIdentity) {
      result.setIdentity();
      return result;
    }

    result._myMatrix.set(_myMatrix);
    if (_myIsRotationMatrix) {
      if (_myIsUniformScale) {
        final double sx = _myScale.x;
        result._myMatrix.transposeLocal();
        if (sx != 1.0) {
          result._myMatrix.multiplyLocal(1.0f / sx);
        }
      } else {
        result._myMatrix.set(result._myMatrix.multiplyDiagonalPost(_myScale).invertLocal());
      }
    } else {
      result._myMatrix.invertLocal();
    }

    result._myTranslation.set(result._myMatrix.applyPost(_myTranslation).negateLocal());
    result.updateFlags(_myIsRotationMatrix);

    return result;
  }
Пример #2
0
  /**
   * Copies the given transform values into this transform object.
   *
   * @param source
   * @return this transform for chaining.
   * @throws NullPointerException if source is null.
   */
  public CCTransform set(final CCTransform source) {
    if (source.isIdentity()) {
      setIdentity();
    } else {
      _myMatrix.set(source.getMatrix());
      _myScale.set(source.scale());
      _myTranslation.set(source.translation());

      _myIsIdentity = false;
      _myIsRotationMatrix = source.isRotationMatrix();
      _myIsUniformScale = source.isUniformScale();
    }
    return this;
  }