Skip to content

Commit

Permalink
Added automatic spherical or cylindrical determination logic and chan…
Browse files Browse the repository at this point in the history
…ged the interface
  • Loading branch information
scihant committed Oct 12, 2016
1 parent 2a710af commit adbf163
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 23 deletions.
20 changes: 16 additions & 4 deletions CTPanoramaController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

/* Begin PBXBuildFile section */
CF65D4001DADFD1100E89B64 /* normal.jpg in Resources */ = {isa = PBXBuildFile; fileRef = CF65D3FF1DADFD1100E89B64 /* normal.jpg */; };
CF65D4021DAE0F9200E89B64 /* ofis.jpg in Resources */ = {isa = PBXBuildFile; fileRef = CF65D4011DAE0F9200E89B64 /* ofis.jpg */; };
CF65D4041DAE1DF800E89B64 /* test2.jpg in Resources */ = {isa = PBXBuildFile; fileRef = CF65D4031DAE1DF800E89B64 /* test2.jpg */; };
CF65D4061DAE247000E89B64 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF65D4051DAE247000E89B64 /* ViewController.swift */; };
CFA340F21DAD679800599E48 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFA340F11DAD679800599E48 /* AppDelegate.swift */; };
CFA340F41DAD679800599E48 /* CTPanoramaController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFA340F31DAD679800599E48 /* CTPanoramaController.swift */; };
CFA340F41DAD679800599E48 /* CTPanoramaViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFA340F31DAD679800599E48 /* CTPanoramaViewController.swift */; };
CFA340F71DAD679800599E48 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CFA340F51DAD679800599E48 /* Main.storyboard */; };
CFA340F91DAD679800599E48 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CFA340F81DAD679800599E48 /* Assets.xcassets */; };
CFA340FC1DAD679800599E48 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CFA340FA1DAD679800599E48 /* LaunchScreen.storyboard */; };
Expand All @@ -18,9 +21,12 @@

/* Begin PBXFileReference section */
CF65D3FF1DADFD1100E89B64 /* normal.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = normal.jpg; sourceTree = "<group>"; };
CF65D4011DAE0F9200E89B64 /* ofis.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = ofis.jpg; sourceTree = "<group>"; };
CF65D4031DAE1DF800E89B64 /* test2.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = test2.jpg; sourceTree = "<group>"; };
CF65D4051DAE247000E89B64 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
CFA340EE1DAD679800599E48 /* CTPanoramaController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CTPanoramaController.app; sourceTree = BUILT_PRODUCTS_DIR; };
CFA340F11DAD679800599E48 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
CFA340F31DAD679800599E48 /* CTPanoramaController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CTPanoramaController.swift; sourceTree = "<group>"; };
CFA340F31DAD679800599E48 /* CTPanoramaViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CTPanoramaViewController.swift; sourceTree = "<group>"; };
CFA340F61DAD679800599E48 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
CFA340F81DAD679800599E48 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
CFA340FB1DAD679800599E48 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -59,9 +65,12 @@
isa = PBXGroup;
children = (
CFA340F11DAD679800599E48 /* AppDelegate.swift */,
CFA340F31DAD679800599E48 /* CTPanoramaController.swift */,
CF65D4051DAE247000E89B64 /* ViewController.swift */,
CFA340F31DAD679800599E48 /* CTPanoramaViewController.swift */,
CF65D4031DAE1DF800E89B64 /* test2.jpg */,
CFA341051DAD77CE00599E48 /* spherical.png */,
CF65D3FF1DADFD1100E89B64 /* normal.jpg */,
CF65D4011DAE0F9200E89B64 /* ofis.jpg */,
CFA340F51DAD679800599E48 /* Main.storyboard */,
CFA340F81DAD679800599E48 /* Assets.xcassets */,
CFA340FA1DAD679800599E48 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -132,8 +141,10 @@
files = (
CFA340FC1DAD679800599E48 /* LaunchScreen.storyboard in Resources */,
CF65D4001DADFD1100E89B64 /* normal.jpg in Resources */,
CF65D4041DAE1DF800E89B64 /* test2.jpg in Resources */,
CFA340F91DAD679800599E48 /* Assets.xcassets in Resources */,
CFA340F71DAD679800599E48 /* Main.storyboard in Resources */,
CF65D4021DAE0F9200E89B64 /* ofis.jpg in Resources */,
CFA341061DAD77CE00599E48 /* spherical.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -145,7 +156,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CFA340F41DAD679800599E48 /* CTPanoramaController.swift in Sources */,
CF65D4061DAE247000E89B64 /* ViewController.swift in Sources */,
CFA340F41DAD679800599E48 /* CTPanoramaViewController.swift in Sources */,
CFA340F21DAD679800599E48 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
24 changes: 10 additions & 14 deletions CTPanoramaController/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Panorama Controller-->
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="CTPanoramaController" customModule="CTPanoramaController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="CTPanoramaController" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
Expand All @@ -18,22 +18,18 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<sceneKitView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="WyM-lo-Vmr"/>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="YM3-Hu-R4S">
<frame key="frameInset" minX="164" minY="109" width="46" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Button"/>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="WyM-lo-Vmr" secondAttribute="bottom" id="CQQ-Xi-WcA"/>
<constraint firstAttribute="trailing" secondItem="WyM-lo-Vmr" secondAttribute="trailing" id="D4K-Ps-gHS"/>
<constraint firstItem="WyM-lo-Vmr" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="MGr-X0-PIg"/>
<constraint firstItem="WyM-lo-Vmr" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="iQz-3c-YrW"/>
</constraints>
</view>
<connections>
<outlet property="sceneView" destination="WyM-lo-Vmr" id="ezX-HA-Ase"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-294" y="1"/>
</scene>
</scenes>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import UIKit
import SceneKit
import CoreMotion
import ImageIO

@objc public enum CTPanaromaControlMethod: Int {
case Motion
Expand All @@ -22,8 +23,6 @@ import CoreMotion

@objc public class CTPanoramaController: UIViewController {

@IBOutlet weak var sceneView: SCNView!

override public var shouldAutorotate: Bool {
return true
}
Expand All @@ -36,25 +35,47 @@ import CoreMotion
return true
}

public var image: UIImage?
public var controlMethod = CTPanaromaControlMethod.Touch
public var panaromaType = CTPanaromaType.Cylindirical
public var speed = CGPoint(x: 0.005, y: 0.005)

private var sceneView: SCNView!
private let cameraNode = SCNNode()
private var prevLocation = CGPoint.zero
private var motionManger = CMMotionManager()

private var panoramaTypeForCurrentImage: CTPanaromaType {
if let image = image {
if (image.size.width / image.size.height == 2) {
return .Spherical
}
}
return .Cylindirical
}

init(image: UIImage) {
super.init(nibName: nil, bundle: nil)
self.image = image
}

public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override public func viewDidLoad() {
super.viewDidLoad()

prepareUI()
self.panaromaType = panoramaTypeForCurrentImage

let camera = SCNCamera()
camera.zFar = 100
camera.xFov = 70
camera.yFov = 70
cameraNode.camera = camera

let material = SCNMaterial()
let texture = UIImage(named: "normal.jpg")
material.diffuse.contents = texture
material.diffuse.contents = image!
material.diffuse.mipFilter = .nearest
material.diffuse.magnificationFilter = .nearest
material.diffuse.contentsTransform = SCNMatrix4MakeScale(-1, 1, 1)
Expand Down Expand Up @@ -117,6 +138,18 @@ import CoreMotion
}
}

private func prepareUI() {
sceneView = SCNView()
sceneView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(sceneView)

let views = ["sceneView" : sceneView!]

view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "|[sceneView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views))
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[sceneView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views))
view.backgroundColor = UIColor.green
}

@objc private func handlePan(panRec: UIPanGestureRecognizer) {
if (panRec.state == .began) {
prevLocation = CGPoint.zero
Expand Down
22 changes: 22 additions & 0 deletions CTPanoramaController/ViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ViewController.swift
// CTPanoramaController
//
// Created by Cihan on 12/10/2016.
// Copyright © 2016 Home. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

let image = UIImage(named: "spherical.png")
let p = CTPanoramaController(image: image!)
self.addChildViewController(p)
view.addSubview(p.view)
p.view.frame = view.bounds
}
}

0 comments on commit adbf163

Please sign in to comment.