I'm trying to rotate image(triangle) to align it to gravity. So that one corner is always down. But nothing helps. Triangle going mad.
double accelX = motion.userAcceleration.x;
double accelY = motion.userAcceleration.y;
rollingX = (accelX * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor));
rollingY = (accelY * kFilteringFactor) + (rollingY * (1.0 - kFilteringFactor));
accelX = accelX - rollingX;
accelY = accelY - rollingY;
float angle = atan2(accelY, accelX);
[rootLayer setAnchorPoint:CGPointMake(0.5, 0.5)];
CATransform3D rotation = CATransform3DIdentity;
rotation.m34 = 1.0f / -500.0f;
rotation = CATransform3DRotate(rotation, angle, 0.0f, 0.0f, 1.0f);
rootLayer.sublayerTransform = rotation;