Skip to content

Instantly share code, notes, and snippets.

@devindazzle
Last active August 29, 2015 14:02
Show Gist options
  • Save devindazzle/f106a0d580e1fba18a29 to your computer and use it in GitHub Desktop.
Save devindazzle/f106a0d580e1fba18a29 to your computer and use it in GitHub Desktop.
import Foundation
import UIKit
import SceneKit
import QuartzCore
class MyViewController : UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
// Create a SceneKit view
let skView = SCNView(frame:CGRectMake(0, 0, 960, 480), options:nil)
skView.backgroundColor = UIColor.grayColor()
skView.preferredFramesPerSecond = 60
// Create a SceneKit scene
let scene = SCNScene()
skView.scene = scene
// Create a camera
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3Make(0, 0, 30)
cameraNode.transform = SCNMatrix4Rotate(cameraNode.transform, 3.14159265358979323846264338327950288 / 7.0, 1, 0, 0)
scene.rootNode.addChildNode(cameraNode)
// Create a spotlight
let spotLight = SCNLight()
spotLight.type = SCNLightTypeSpot
spotLight.color = UIColor.redColor()
let spotLightNode = SCNNode()
spotLightNode.light = spotLight
spotLightNode.position = SCNVector3Make(-2, 1, 0)
cameraNode.addChildNode(spotLightNode)
// A square box
let boxSide = 15.0
let box = SCNBox(width: boxSide, height: boxSide, length: boxSide, chamferRadius: 0)
let boxNode = SCNNode(geometry: box)
boxNode.transform = SCNMatrix4Rotate(boxNode.transform, 1.57079632679489661923132169163975144 / 3.0, 0, 1, 0)
scene.rootNode.addChildNode(boxNode)
self.view = skView;
// Rotate the box
let boxRotationAnimation = CABasicAnimation(keyPath: "transform")
boxRotationAnimation.toValue = NSValue(SCNMatrix4: SCNMatrix4Rotate(boxNode.transform, 3.14159265358979323846264338327950288, 1, 1, 0))
boxRotationAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
boxRotationAnimation.repeatCount = -1
boxRotationAnimation.duration = 2.0
boxNode.addAnimation(boxRotationAnimation, forKey: "RotateTheBox")
println("Started running game")
}
override func shouldAutorotate() -> Bool
{
return true
}
override func supportedInterfaceOrientations() -> Int
{
return Int(UIInterfaceOrientationMask.Landscape.toRaw())
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment