forked from ThumbWorks/AugmentedSolarSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTutorialViewController.swift
68 lines (54 loc) · 2.32 KB
/
TutorialViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// TutorialViewController.swift
// SolarSystem
//
// Created by Roderic Campbell on 9/1/17.
// Copyright © 2017 Roderic Campbell. All rights reserved.
//
import Foundation
import UIKit
import SceneKit
class TutorialViewController: UIViewController {
@IBOutlet weak var sceneView: SCNView!
func createTutorial() {
let scene = SCNScene()
sceneView.scene = scene
let sphere = SCNSphere(radius: 2)
let material = SCNMaterial()
material.diffuse.contents = UIColor.blue
sphere.materials = [material]
// let sphereNode = SCNNode(geometry: sphere)
// scene.rootNode.addChildNode(sphereNode)
// load the table asset
let tableNode = SCNScene(named: "art.scnassets/table.scn")!.rootNode
tableNode.position = SCNVector3Make(0, 0, -12)
tableNode.rotation = SCNVector4Make(1, 0, 0, Float.pi * 1.8)
tableNode.scale = SCNVector3Make(0.08, 0.08, 0.08)
scene.rootNode.addChildNode(tableNode)
// Load the device asset
let iOSDeviceNode = SCNScene(named: "art.scnassets/iPhone6.scn")!.rootNode
iOSDeviceNode.scale = SCNVector3Make(0.05, 0.05, 0.05)
iOSDeviceNode.position = SCNVector3Make(0, 0, 3)
// at this point, tutorialNode is just an empty node with no parent
let deviceRotatingNode = SCNNode()
deviceRotatingNode.addChildNode(iOSDeviceNode)
deviceRotatingNode.position = tableNode.position // SCNVector3Make(0, 0, -7)
scene.rootNode.addChildNode(deviceRotatingNode)
let camera = SCNCamera()
let pov = SCNNode()
pov.camera = camera
scene.rootNode.addChildNode(pov)
let cameraLookatTable = SCNLookAtConstraint(target: tableNode)
pov.constraints = [cameraLookatTable]
sceneView.pointOfView = pov
// create and add the repeating animation
let rotationValue = CGFloat.pi / 7
let action = SCNAction.createARKitCalibrationAction(rotationValue: rotationValue)
deviceRotatingNode.runAction(action)
let tableAction = SCNAction.createARKitCalibrationAction(rotationValue: -rotationValue/8)
tableNode.runAction(tableAction)
}
override func viewDidAppear(_ animated: Bool) {
createTutorial()
}
}