Created
October 7, 2015 18:05
-
-
Save garmstro/c97e11399f6bc890ce78 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 | |
- parameter angle: The viewing angle for the object | |
- returns: xOffset CGFloat for the x location of the object on the screen | |
*/ | |
private func getXPixelOffset(angle: Double) -> CGFloat { | |
var xOffset = CGFloat(0.0) | |
var fieldOfView = CGFloat(0.0) | |
if orientation != nil && fov != nil { | |
switch orientation! { | |
case .Portrait, .PortraitUpsideDown: | |
fieldOfView = CGFloat(fov!) | |
case .LandscapeLeft, .LandscapeRight: | |
fieldOfView = CGFloat(fov!) * view.frame.height / view.frame.width | |
default: | |
fieldOfView = CGFloat(fov!) | |
} | |
} | |
if currentHeading != nil { | |
let pixPerDeg = view.frame.width / CGFloat(fieldOfView) | |
let viewAngle = angle - currentHeading! | |
xOffset = CGFloat(viewAngle) * pixPerDeg | |
} | |
//Larger value = more to the right | |
return xOffset + view.frame.width/2.0 | |
} | |
/** | |
Calculate the y-pixel offset for an angle | |
- parameter angle: The viewing angle for the object | |
- returns: yOffset CGFloat for the y location of the object on the screen | |
*/ | |
private func getYPixelOffset(angle: Double) -> CGFloat { | |
var yOffset = CGFloat(0.0) | |
var fieldOfView = CGFloat(0.0) | |
if orientation != nil && fov != nil { | |
switch orientation! { | |
case .Portrait, .PortraitUpsideDown: | |
fieldOfView = CGFloat(fov!) * view.frame.height / view.frame.width | |
case .LandscapeLeft, .LandscapeRight: | |
fieldOfView = CGFloat(fov!) | |
default: | |
fieldOfView = CGFloat(fov!) * view.frame.height / view.frame.width | |
} | |
} | |
if currentPitch != nil { | |
let pixPerDeg = view.frame.height / CGFloat(fieldOfView) | |
let viewAngle = angle - currentPitch! | |
yOffset = CGFloat(viewAngle) * pixPerDeg | |
} | |
//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