Skip to content

Instantly share code, notes, and snippets.

Benjamin Kindle literalpie

Block or report user

Report or block literalpie

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@literalpie
literalpie / scenekit-better-pan-gesture-recognizer.swift
Last active May 19, 2019
a better approach to handling the pan gesture in scenekit. For use in part 3 of medium post
View scenekit-better-pan-gesture-recognizer.swift
@objc func handlePan(panGesture: UIPanGestureRecognizer) {
guard let view = view as? SCNView else { return }
let location = panGesture.location(in: self.view)
switch panGesture.state {
case .began:
// existing logic from previous approach. Keep this.
guard let hitNodeResult = view.hitTest(location, options: nil).first else { return }
panStartZ = CGFloat(view.projectPoint(lastPanLocation!).z)
// lastPanLocation is new
lastPanLocation = hitNodeResult.worldCoordinates
@literalpie
literalpie / scenekit-better-pan-gesture-recognizer.swift
Created May 19, 2019
a better approach to handling the pan gesture in scenekit. For use in part 3 of medium post
View scenekit-better-pan-gesture-recognizer.swift
@objc func handlePan(panGesture: UIPanGestureRecognizer) {
guard let view = view as? SCNView else { return }
switch panGesture.state {
case .began:
let location = panGesture.location(in: self.view)
guard let hitNodeResult = view.hitTest(location, options: nil).first else { return }
panStartZ = CGFloat(view.projectPoint(lastPanLocation!).z)
lastPanLocation = hitNodeResult.worldCoordinates
draggingNode = hitNodeResult.node
case .changed:
@literalpie
literalpie / SceneKit-simple-pan-gesture-handler.swift
Last active May 19, 2019
shows a simple pan gesture handler for use in part 2 of a literalpie medium post
View SceneKit-simple-pan-gesture-handler.swift
@objc func handlePan(panGesture: UIPanGestureRecognizer) {
guard let view = view as? SCNView else { return }
let location = panGesture.location(in: self.view)
switch panGesture.state {
case .began:
guard let hitNodeResult = view.hitTest(location, options: nil).first else { return }
// panStartZ and draggingNode should be defined in the containing class
panStartZ = CGFloat(view.projectPoint(lastPanLocation!).z)
draggingNode = hitNodeResult.node
case .changed:
@literalpie
literalpie / scenekit-pan-gesture-setup.swift
Last active May 19, 2019
for use in part 1 of a literalpie medium post
View scenekit-pan-gesture-setup.swift
// Create the box:
let cube = SCNBox(width: 10, height: 10, length: 10, chamferRadius: 1.0)
let cubeNode = SCNNode(geometry: cube)
scene.rootNode.addChildNode(cubeNode)
// Create the gesture recognizer:
let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan(panGesture:)))
view.addGestureRecognizer(panRecognizer)
You can’t perform that action at this time.