Created
September 22, 2014 18:59
-
-
Save veeneck/aae205fe33a015e866f2 to your computer and use it in GitHub Desktop.
Translate matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Our for loop inside of the wheel() function | |
| for (index, unit) in enumerate(self.units) { | |
| var vector = self.formation!.getVectorAtPosition(index) | |
| // Translate unit to new point. Basically, subtract rotation center offset from units position | |
| vector = CGVectorMake(vector.dx - self.translateX, vector.dy - self.translateY) | |
| // Rotate the matrix at units position | |
| var newX = vector.dx * cosRadian - vector.dy * sinRadian | |
| var newY = vector.dx * sinRadian + vector.dy * cosRadian | |
| // Translate the center back to the original units center | |
| unit.moveToPoint(CGPoint(x:newX + self.translateX, y:newY + self.translateY), {}) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment