Skip to content

Commit

Permalink
Moving all the source code into the main Contents.swift file so you c…
Browse files Browse the repository at this point in the history
…an play around with the distance settings.
  • Loading branch information
kids authored and kids committed Jul 6, 2017
1 parent 582b262 commit 8440af9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -21,7 +21,7 @@ xcuserdata/
*.moved-aside
*.xccheckout
*.xcscmblueprint

.DS_Store
## Obj-C/Swift specific
*.hmap
*.ipa
Expand Down
44 changes: 41 additions & 3 deletions ARKitDemo.playground/Contents.swift
Expand Up @@ -3,6 +3,44 @@
import UIKit
import ARKit
import PlaygroundSupport
import SpriteKit

public class Scene: SKScene {

public override required init(size:CGSize) {
super.init(size:size)
}

public required init(coder: NSCoder) {
super.init(coder:coder)!
}
public override func didMove(to view: SKView) {
// Setup your scene here
}

public override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
}

public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let sceneView = self.view as? ARSKView else {
return
}

// Create anchor using the camera's current position
if let currentFrame = sceneView.session.currentFrame {
// Create a transform with a translation of 0.2 meters in front of the camera
var translation = matrix_identity_float4x4
translation.columns.3.z = -0.2
let transform = simd_mul(currentFrame.camera.transform, translation)

// Add a new anchor to the session
let anchor = ARAnchor(transform: transform)
sceneView.session.add(anchor: anchor)
}
}
}


class arKitViewController : UIViewController, ARSKViewDelegate {
@IBOutlet var sceneView: ARSKView!
Expand All @@ -18,7 +56,8 @@ class arKitViewController : UIViewController, ARSKViewDelegate {

// Load the SKScene from 'Scene.sks'
if let scene = SKScene(fileNamed: "Scene") {
sceneView.presentScene(scene)
let myScene = scene as! Scene
sceneView.presentScene(myScene)
}

let config = ARWorldTrackingSessionConfiguration()
Expand Down Expand Up @@ -55,5 +94,4 @@ class arKitViewController : UIViewController, ARSKViewDelegate {
}

PlaygroundPage.current.liveView = arKitViewController()


PlaygroundPage.current.needsIndefiniteExecution = true
40 changes: 0 additions & 40 deletions ARKitDemo.playground/Sources/Scene.swift

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -11,3 +11,5 @@ More info on ARKit:

`A messy kitchen and a virtual pear in the midst of it all`
![](http://www.wickedpearprogramming.com/w/wp-content/uploads/2017/06/IMG_584809A41BBF-1.jpg)

The `master` branch now includes all the code in one file so you can tweak the distance from the sample ARKit code in your Swift Playgrounds app. If you'd like the old behavior, check out the [`original`](https://github.com/mhanlon/ARKitDemoPlayground/tree/original) branch.

0 comments on commit 8440af9

Please sign in to comment.