Created
October 7, 2015 18:04
-
-
Save garmstro/98d60c36d342b055c8f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
Calculate the x-pixel offset for an angle using perspective projection | |
http://stackoverflow.com/questions/16619104/perspective-projection-in-android-in-an-augmented-reality-application | |
- parameter angle: The viewing angle for the object | |
- returns: xOffset CGFloat for the x location of the object on the screen | |
*/ | |
private func getXPerspectiveOffset(angle: Double) -> CGFloat { | |
var xOffset = CGFloat(0.0) | |
if currentHeading != nil && focalLen != nil { | |
let viewAngle = degreesToRadians(angle - currentHeading!) | |
xOffset = CGFloat(tan(viewAngle)) * CGFloat(focalLen!) | |
} | |
//Larger value = more to the right | |
return xOffset + view.frame.width/2.0 | |
} | |
/** | |
Calculate the y-pixel offset for an angle using perspective projection | |
http://stackoverflow.com/questions/16619104/perspective-projection-in-android-in-an-augmented-reality-application | |
- parameter angle: The viewing angle for the object | |
- returns: yOffset CGFloat for the y location of the object on the screen | |
*/ | |
private func getYPerspectiveOffset(angle: Double) -> CGFloat { | |
var yOffset = CGFloat(0.0) | |
if currentPitch != nil && focalLen != nil { | |
let viewAngle = degreesToRadians(angle - currentPitch!) | |
yOffset = CGFloat(tan(viewAngle)) * CGFloat(focalLen!) | |
} | |
//Larger value = lower | |
return view.frame.height/2.0 - yOffset | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment