Skip to content

Instantly share code, notes, and snippets.

@metasmile
Created August 20, 2015 05:24
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 metasmile/16ff11ba0b24018b1fcc to your computer and use it in GitHub Desktop.
Save metasmile/16ff11ba0b24018b1fcc to your computer and use it in GitHub Desktop.
Dynamically measure chest point from face by orientation
- (CGPoint)calculateChestPointFromFace:(CGPoint)facePoint faceFrame:(CGRect)faceFrame inBounds:(CGRect)bounds{
//define
UIInterfaceOrientation currentOrientation = [STMotionManager sharedManager].interfaceOrientation;
CGPoint focusPointHeadBottomToBody = facePoint;
CGFloat totalLengthVertical = UIInterfaceOrientationIsPortrait(currentOrientation) ? bounds.size.height : bounds.size.width;
CGFloat faceLengthVertical = UIInterfaceOrientationIsPortrait(currentOrientation) ? faceFrame.size.height : faceFrame.size.width;
//calc focus point ~ bottom
CGFloat perToHeadToTotalLength = 1.5f;
CGFloat addedLengthHeadToTotalLength = 0;
CGFloat addedLengthHeadToFaceBottomWeight = faceLengthVertical * 2;
switch (currentOrientation){
case UIInterfaceOrientationUnknown:
break;
case UIInterfaceOrientationPortrait:
addedLengthHeadToTotalLength = totalLengthVertical - facePoint.y;
addedLengthHeadToTotalLength /= perToHeadToTotalLength;
focusPointHeadBottomToBody = CGPointMake(facePoint.x, CLAMP(facePoint.y+ addedLengthHeadToTotalLength, 0, totalLengthVertical));
break;
case UIInterfaceOrientationPortraitUpsideDown:
addedLengthHeadToTotalLength = facePoint.y;
addedLengthHeadToTotalLength /= perToHeadToTotalLength;
focusPointHeadBottomToBody = CGPointMake(facePoint.x, CLAMP(facePoint.y- addedLengthHeadToTotalLength, 0, totalLengthVertical));
break;
case UIInterfaceOrientationLandscapeLeft:
addedLengthHeadToTotalLength = facePoint.x;
addedLengthHeadToTotalLength /= perToHeadToTotalLength;
focusPointHeadBottomToBody = CGPointMake(CLAMP(facePoint.x- addedLengthHeadToTotalLength, 0, totalLengthVertical), facePoint.y);
break;
case UIInterfaceOrientationLandscapeRight:
addedLengthHeadToTotalLength = totalLengthVertical - facePoint.x;
addedLengthHeadToTotalLength /= perToHeadToTotalLength;
focusPointHeadBottomToBody = CGPointMake(CLAMP(facePoint.x+ addedLengthHeadToTotalLength, 0, totalLengthVertical), facePoint.y);
break;
}
return focusPointHeadBottomToBody;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment