Created
August 20, 2015 05:24
-
-
Save metasmile/16ff11ba0b24018b1fcc to your computer and use it in GitHub Desktop.
Dynamically measure chest point from face by orientation
This file contains 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
- (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