Skip to content

Instantly share code, notes, and snippets.

@veeneck
Created September 22, 2014 18:59
Show Gist options
  • Select an option

  • Save veeneck/aae205fe33a015e866f2 to your computer and use it in GitHub Desktop.

Select an option

Save veeneck/aae205fe33a015e866f2 to your computer and use it in GitHub Desktop.
Translate matrix
// 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