@Override public float[] convertLocalCoordinatesToSceneCoordinates( final float[] pCoordinates, final float[] pReuse) { final Transformation localToSceneTransformation = this.getLocalToSceneTransformation(); pReuse[Constants.VERTEX_INDEX_X] = pCoordinates[Constants.VERTEX_INDEX_X]; pReuse[Constants.VERTEX_INDEX_Y] = pCoordinates[Constants.VERTEX_INDEX_Y]; localToSceneTransformation.transform(pReuse); return pReuse; }
@Override public float[] convertLocalCoordinatesToParentCoordinates( final float pX, final float pY, final float[] pReuse) { final Transformation localToParentTransformation = this.getLocalToParentTransformation(); pReuse[Constants.VERTEX_INDEX_X] = pX; pReuse[Constants.VERTEX_INDEX_Y] = pY; localToParentTransformation.transform(pReuse); return pReuse; }
@Override public Transformation getSceneToLocalTransformation() { if (this.mSceneToLocalTransformation == null) { this.mSceneToLocalTransformation = new Transformation(); } // TODO Cache if parent(recursive) not dirty. final Transformation sceneToLocalTransformation = this.mSceneToLocalTransformation; sceneToLocalTransformation.setTo(this.getParentToLocalTransformation()); final IEntity parent = this.mParent; if (parent != null) { sceneToLocalTransformation.preConcat(parent.getSceneToLocalTransformation()); } return sceneToLocalTransformation; }
@Override public Transformation getLocalToSceneTransformation() { if (this.mLocalToSceneTransformation == null) { this.mLocalToSceneTransformation = new Transformation(); } // TODO Cache if parent(recursive) not dirty. final Transformation localToSceneTransformation = this.mLocalToSceneTransformation; localToSceneTransformation.setTo(this.getLocalToParentTransformation()); final IEntity parent = this.mParent; if (parent != null) { localToSceneTransformation.postConcat(parent.getLocalToSceneTransformation()); } return localToSceneTransformation; }
@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; }
@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; }