Skip to content

Instantly share code, notes, and snippets.

@AndriyBas
Last active November 9, 2016 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndriyBas/4f60539d13be10efb5571d13c53bb7f8 to your computer and use it in GitHub Desktop.
Save AndriyBas/4f60539d13be10efb5571d13c53bb7f8 to your computer and use it in GitHub Desktop.
all the math how to create Matrix from the model
// calculate params
float topLeftX = layer.getX() * canvasWidth;
float topLeftY = layer.getY() * canvasHeight;
// center - for rotation
float centerX = topLeftX + getWidth() * holyScale * 0.5F;
float centerY = topLeftY + getHeight() * holyScale * 0.5F;
float rotationInDegree = layer.getRotationInDegrees();
float scaleX = layer.getScale();
float scaleY = layer.getScale();
// applying transformations : L = S * R * T
// scale
matrix.preScale(scaleX, scaleY, centerX, centerY);
// rotate
matrix.preRotate(rotationInDegree, centerX, centerY);
// translate
matrix.preTranslate(topLeftX, topLeftY);
// applying holy scale - S`, the result will be : L = S * R * T * S`
matrix.preScale(holyScale, holyScale);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment