Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RunningMan.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -253,6 +254,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = saltpig.RunningMan;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -265,6 +267,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = saltpig.RunningMan;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
Empty file modified RunningMan/AppDelegate.swift
100644 → 100755
Empty file.
30 changes: 15 additions & 15 deletions RunningMan/ColladaRig.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ class ColladaRig {
playAnimation("rest")

//position node on ground
var min = SCNVector3(0,0,0)
var max = SCNVector3(0,0,0)
node.getBoundingBoxMin(&min, max: &max)
node.position = SCNVector3(0, -min.y, 0)
// var min = SCNVector3(0,0,0)
// var max = SCNVector3(0,0,0)
// node.boundingBox(min:&min, max: &max)
node.position = SCNVector3(0,0, 0)
}

static func getSceneSource(daeNamed: String) -> SCNSceneSource {
let collada = NSBundle.mainBundle().URLForResource("art.scnassets/\(daeNamed)", withExtension: "dae")!
return SCNSceneSource(URL: collada, options: nil)!
static func getSceneSource(_ daeNamed: String) -> SCNSceneSource {
let collada = Bundle.main.url(forResource: "art.scnassets/\(daeNamed)", withExtension: "dae")!
return SCNSceneSource(url: collada, options: nil)!
}

func loadAnimation(withKey: String, daeNamed: String, fade: CGFloat = 0.3){
func loadAnimation(_ withKey: String, daeNamed: String, fade: CGFloat = 0.3){
let sceneSource = ColladaRig.getSceneSource(daeNamed)
let animation = sceneSource.entryWithIdentifier("\(daeNamed)-1", withClass: CAAnimation.self)!

Expand All @@ -50,25 +50,25 @@ class ColladaRig {
animations[withKey] = animation
}

func playAnimation(named: String){ //also works for armature
func playAnimation(_ named: String){ //also works for armature
if let animation = animations[named] {
node.addAnimation(animation, forKey: named)
}
}

func walk() {
node.pauseAnimationForKey("rest")
node.pauseAnimation(forKey: "rest")
// node.removeAnimationForKey("rest", fadeOutDuration: 0.3)
playAnimation("walk")
let run = SCNAction.repeatActionForever( SCNAction.moveByX(0, y: 0, z: 12, duration: 1))
run.timingMode = .EaseInEaseOut //ease the action in to try to match the fade-in and fade-out of the animation
let run = SCNAction.repeatForever( SCNAction.moveBy(x: 0, y: 0, z: 12, duration: 1))
run.timingMode = .easeInEaseOut //ease the action in to try to match the fade-in and fade-out of the animation
node.runAction(run, forKey: "walk")
}

func stopWalking() {
node.resumeAnimationForKey("rest")
node.resumeAnimation(forKey:"rest")
// node.addAnimation(animations["rest"]!, forKey: "rest")
node.removeAnimationForKey("walk", fadeOutDuration: 0.3)
node.removeActionForKey("walk")
node.removeAnimation(forKey:"walk", fadeOutDuration: 0.3)
node.removeAction(forKey:"walk")
}
}
Empty file modified RunningMan/GameView.swift
100644 → 100755
Empty file.
32 changes: 17 additions & 15 deletions RunningMan/GameViewController.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ class GameViewController: NSViewController {
self.gameView!.showsStatistics = true

// configure the view
self.gameView!.backgroundColor = NSColor.blackColor()
self.gameView!.backgroundColor = NSColor.black
}

override func mouseDown(theEvent: NSEvent) {
override func mouseDown(with event: NSEvent) {

player!.walk()
}

override func mouseUp(theEvent: NSEvent) {
override func mouseUp(with event: NSEvent) {

player!.stopWalking()
}

Expand All @@ -54,17 +56,17 @@ class GameViewController: NSViewController {
// create and add a light to the scene
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeOmni
lightNode.light!.type = SCNLight.LightType.omni
lightNode.position = SCNVector3(x: 0, y: 10, z: 10)
scene.rootNode.addChildNode(lightNode)

let skyCube = getCubeMap("miramar")
let skyCube = getCubeMap(inFolder: "miramar")

// create and add an ambient light to the scene
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = SCNLightTypeAmbient
ambientLightNode.light!.color = NSColor.darkGrayColor()
ambientLightNode.light!.type = SCNLight.LightType.ambient
ambientLightNode.light!.color = NSColor.darkGray
scene.rootNode.addChildNode(ambientLightNode)

let floorNode = SCNNode(geometry: SCNFloor())
Expand All @@ -74,18 +76,18 @@ class GameViewController: NSViewController {
let trans = SCNMatrix4Rotate(SCNMatrix4MakeScale(scale, scale, 1),CGFloat(M_PI_2) / 3 ,0, 0, 1)

mat.diffuse.contents = "art.scnassets/floor07.tga"
mat.diffuse.wrapS = .Repeat
mat.diffuse.wrapT = .Repeat
mat.diffuse.wrapS = .repeat
mat.diffuse.wrapT = .repeat
mat.diffuse.contentsTransform = trans
mat.normal.contents = "art.scnassets/floor07_NRM.jpg"
mat.normal.wrapS = .Repeat
mat.normal.wrapT = .Repeat
mat.normal.wrapS = .repeat
mat.normal.wrapT = .repeat
mat.normal.contentsTransform = trans
// try to stop the floor textures trigger nasty moire jaggies at distance
mat.normal.mipFilter = .Linear
mat.normal.mipFilter = .linear
mat.normal.maxAnisotropy = 0
mat.normal.intensity = 0.5
mat.diffuse.mipFilter = .Linear
mat.diffuse.mipFilter = .linear
mat.diffuse.maxAnisotropy = 0
// reflectivity
mat.reflective.contents = skyCube
Expand All @@ -95,7 +97,7 @@ class GameViewController: NSViewController {
scene.rootNode.addChildNode(floorNode)

let animation = CABasicAnimation(keyPath: "rotation")
animation.toValue = NSValue(SCNVector4: SCNVector4(x: CGFloat(0), y: CGFloat(1), z: CGFloat(0), w: CGFloat(M_PI)*2))
animation.toValue = NSValue(scnVector4: SCNVector4(x: CGFloat(0), y: CGFloat(1), z: CGFloat(0), w: CGFloat(Double.pi)*2))
animation.duration = 28
animation.repeatCount = MAXFLOAT //repeat forever
cameraArm.addAnimation(animation, forKey: nil)
Expand All @@ -108,7 +110,7 @@ class GameViewController: NSViewController {

let playerMat = SCNMaterial()

playerMat.diffuse.contents = NSColor.darkGrayColor()
playerMat.diffuse.contents = NSColor.darkGray
playerMat.reflective.contents = skyCube
playerMat.fresnelExponent = 2
playerMat.shininess = 1
Expand Down