Skip to content

Instantly share code, notes, and snippets.

@rentzsch
Created September 14, 2011 07:14
Show Gist options
  • Save rentzsch/1216022 to your computer and use it in GitHub Desktop.
Save rentzsch/1216022 to your computer and use it in GitHub Desktop.
NSString* JRNSStringFromCATransform3D(CATransform3D transform)
static NSString* prettyFloat(CGFloat f) {
if (f == 0) {
return @"0";
} else if (f == 1) {
return @"1";
} else {
return [NSString stringWithFormat:@"%.3f", f];
}
}
NSString* JRNSStringFromCATransform3D(CATransform3D transform) {
// format: [1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1]
return CATransform3DIsIdentity(transform)
? @"CATransform3DIdentity"
: [NSString stringWithFormat:@"[%@ %@ %@ %@; %@ %@ %@ %@; %@ %@ %@ %@; %@ %@ %@ %@]",
prettyFloat(transform.m11),
prettyFloat(transform.m12),
prettyFloat(transform.m13),
prettyFloat(transform.m14),
prettyFloat(transform.m21),
prettyFloat(transform.m22),
prettyFloat(transform.m23),
prettyFloat(transform.m24),
prettyFloat(transform.m31),
prettyFloat(transform.m32),
prettyFloat(transform.m33),
prettyFloat(transform.m34),
prettyFloat(transform.m41),
prettyFloat(transform.m42),
prettyFloat(transform.m43),
prettyFloat(transform.m44)
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment