From 22ef3207b6de27f7e9ae5a275e58662c9487b5c6 Mon Sep 17 00:00:00 2001 From: Charles Magahern Date: Fri, 1 Jan 2016 00:30:13 -0800 Subject: [PATCH] Visual refinements and additional effects --- .../Controllers/MainViewController.swift | 3 +- .../VisualizationViewController.swift | 59 ++++++++++++++++--- XIONControlPanel/Views/WemoCellView.swift | 2 + 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/XIONControlPanel/Controllers/MainViewController.swift b/XIONControlPanel/Controllers/MainViewController.swift index c6ae45f..be81868 100644 --- a/XIONControlPanel/Controllers/MainViewController.swift +++ b/XIONControlPanel/Controllers/MainViewController.swift @@ -71,7 +71,7 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate { let visualizationFrame = CGRect( x: bodyBounds.origin.x, y: bodyBounds.origin.y, - width: rint(0.6 * bodyBounds.size.width), + width: rint(0.55 * bodyBounds.size.width), height: bodyBounds.size.height ) _visualizationController.view.frame = visualizationFrame @@ -153,6 +153,7 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate { { dispatch_async(dispatch_get_main_queue()) { () -> Void in self._headerView.connectionStatusView.connectivityStatus = status + self._visualizationController.connectionStatus = status } } diff --git a/XIONControlPanel/Controllers/VisualizationViewController.swift b/XIONControlPanel/Controllers/VisualizationViewController.swift index b6fb096..602bde2 100644 --- a/XIONControlPanel/Controllers/VisualizationViewController.swift +++ b/XIONControlPanel/Controllers/VisualizationViewController.swift @@ -18,6 +18,7 @@ class VisualizationViewController: UIViewController { private var _scene: SCNScene = SCNScene() private var _sceneView: SCNView? private var _cameraNode: SCNNode = SCNNode() + private var _lightNode: SCNNode = SCNNode() private var _cubletsNode: SCNNode = SCNNode() private var _cublets: [SCNNode] = [] private var _percentActivated: Float = 0.0 @@ -25,6 +26,7 @@ class VisualizationViewController: UIViewController { static private let cubletsDimensions = 5 static private let cubletsSize = 1.0 static private let cubletsSpacing = 2.0 + static private let rotationAnimationKey = "RotationAnimation" // MARK: Overrides @@ -64,6 +66,21 @@ class VisualizationViewController: UIViewController { // MARK: API + var connectionStatus: ConnectionStatus = .Disconnected + { + didSet + { + switch (self.connectionStatus) { + case .Disconnected, .Connecting, .Error: + _cubletsNode.paused = true + _lightNode.light?.color = UIColor(white: 0.3, alpha: 1.0) + case .Connected: + _cubletsNode.paused = false + _lightNode.light?.color = UIColor.whiteColor() + } + } + } + var percentActivated: Float { get @@ -110,9 +127,18 @@ class VisualizationViewController: UIViewController { return min(((log10(4.0 * (t + 0.03)) + 1.0) / 1.5), 1.0) } - _cubletsNode.runAction(rotAction) + // modify the existing rotation animation as well, so that we have a + // smooth transition + let longTermAnimKey = VisualizationViewController.rotationAnimationKey + let newLongTermRotAction = _createLongTermRotationAnimation((rotCoeff * 2.0 * π), rotAxis) + _cubletsNode.removeActionForKey(longTermAnimKey) + + let actionSeq = SCNAction.sequence([rotAction, newLongTermRotAction]) + _cubletsNode.runAction(actionSeq, forKey: longTermAnimKey) } + _setAnimationSpeed(CGFloat(1.0 + (percentage * 2.0))) + _percentActivated = percentage } @@ -140,11 +166,11 @@ class VisualizationViewController: UIViewController { light.type = SCNLightTypeOmni light.color = UIColor.whiteColor() - let lightNode = SCNNode() - lightNode.light = light - lightNode.position = _cameraNode.position + _lightNode = SCNNode() + _lightNode.light = light + _lightNode.position = _cameraNode.position - _scene.rootNode.addChildNode(lightNode) + _scene.rootNode.addChildNode(_lightNode) } internal func _setupModel() @@ -158,7 +184,7 @@ class VisualizationViewController: UIViewController { let volume = (dimf * sz) + ((dimf - 1.0) * spacing) let orig = -volume / 2.0 - // setup material and geometry. each node needs its own material for activation effect. + // setup material and geometry. each node needs its own material for the activation effect. let geom = SCNBox(width: CGFloat(sz), height: CGFloat(sz), length: CGFloat(sz), chamferRadius: 0.0) let material = SCNMaterial() material.diffuse.contents = UIColor.whiteColor() @@ -191,10 +217,10 @@ class VisualizationViewController: UIViewController { internal func _setupAnimation() { - let rotAxis = SCNVector3Make(0.25, 1.75, 1.0) let rotAngle = 2.0 * π - let rotAction = SCNAction.repeatActionForever(SCNAction.rotateByAngle(rotAngle, aroundAxis: rotAxis, duration: 40.0)) - _cubletsNode.runAction(rotAction) + let rotAxis = SCNVector3Make(0.25, 1.75, 1.0) + let rotationAction = _createLongTermRotationAnimation(rotAngle, rotAxis) + _cubletsNode.runAction(rotationAction, forKey: VisualizationViewController.rotationAnimationKey) } internal func _setupEffects() @@ -211,4 +237,19 @@ class VisualizationViewController: UIViewController { let material = cublet.geometry?.firstMaterial material?.diffuse.contents = (activated ? UIColor.redColor() : UIColor.whiteColor()) } + + internal func _setAnimationSpeed(speed: CGFloat) + { + let key = VisualizationViewController.rotationAnimationKey + let action = _cubletsNode.actionForKey(key) + _cubletsNode.removeActionForKey(key) + + action?.speed = speed + _cubletsNode.runAction(action!, forKey: key) + } + + internal func _createLongTermRotationAnimation(rotAngle: CGFloat, _ rotAxis: SCNVector3) -> SCNAction + { + return SCNAction.repeatActionForever(SCNAction.rotateByAngle(rotAngle, aroundAxis: rotAxis, duration: 40.0)) + } } diff --git a/XIONControlPanel/Views/WemoCellView.swift b/XIONControlPanel/Views/WemoCellView.swift index 9ad6379..c608f40 100644 --- a/XIONControlPanel/Views/WemoCellView.swift +++ b/XIONControlPanel/Views/WemoCellView.swift @@ -69,6 +69,8 @@ public class WemoDeviceCellView: WemoCellView { _nameLabel.font = UIFont(name: "Orbitron-Medium", size: 16.0) _nameLabel.numberOfLines = 3 + _nameLabel.allowsDefaultTighteningForTruncation = true + _nameLabel.adjustsFontSizeToFitWidth = true _nameLabel.textColor = UIColor.whiteColor() self.contentView.addSubview(_nameLabel)