Skip to content

Instantly share code, notes, and snippets.

@cupuyc
Created October 29, 2014 17:29
Show Gist options
  • Save cupuyc/d7b44ed47b8f522f2f70 to your computer and use it in GitHub Desktop.
Save cupuyc/d7b44ed47b8f522f2f70 to your computer and use it in GitHub Desktop.
Camera rotation
/**
* Get camera rotation to keep video shown properly.
* Video object attached to the camera will only show upright video in a landscape-aspect orientation.
* For iOS default orientation is not landscape.
* For Android it varies.
*/
public static function getCameraRotation(camera : Camera) : int {
if (isLandscapeOrientation()) {
// camera is OK in landscape
return 0;
}
var orientation : String = UIUtil.getStage().orientation;
if (Const.IS_IOS) {
return 90;
} else {
if (orientation == StageOrientation.DEFAULT || orientation == StageOrientation.UPSIDE_DOWN) {
// phones where portraite is default
if (camera.position == CameraPosition.BACK) {
return 90;
} else {
return -90;
}
} else {
// tablets when landscape is default
return 90;
}
}
}
public static function isLandscapeOrientation() : Boolean {
return UIUtil.getStage().stageWidth >= UIUtil.getStage().stageHeight;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment