Skip to content

Commit

Permalink
init calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkarthik10 committed Nov 13, 2024
1 parent dbd5609 commit 32dbe19
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
4 changes: 2 additions & 2 deletions PodPals/Calibration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class Calibration: ObservableObject {

private var data: CMDeviceMotion = .init()

// calibration

private var idleGravity: CMAcceleration = .init()
private var idleQuaternion: CMQuaternion = .init(x: 0, y: 0, z: 0, w: 1)
private var calibration: CMQuaternion = .init(x: 0, y: 0, z: 0, w: 1)

init() {
// restoreCalibration()
restoreCalibration()
}

func update(data: CMDeviceMotion) {
Expand Down
18 changes: 6 additions & 12 deletions PodPals/HeadScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class HeadScene: SCNScene, ObservableObject {
let head = SCNNode()
let headGeometry = SCNSphere(radius: 1)
head.geometry = headGeometry
// headGeometry.firstMaterial?.diffuse.contents = NSColor(red: 156/255, green: 156/255, blue: 156/255, alpha: 1.0)

headGeometry.firstMaterial?.diffuse.contents = NSColor(red: 1, green: 1, blue: 1, alpha: 1.0)
headGeometry.firstMaterial?.transparency = 0.8
head.position = SCNVector3(x: 0, y: 0, z: 0)
Expand Down Expand Up @@ -89,9 +89,7 @@ class HeadScene: SCNScene, ObservableObject {
let mouth = SCNNode()
let mouthGeometry = SCNCylinder(radius: 0.2, height: 0.05)
mouth.geometry = mouthGeometry
// mouthGeometry.firstMaterial?.diffuse.contents = NSColor(
// calibratedRed: 0.8, green: 0.2, blue: 0.2, alpha: 1
// )

mouthGeometry.firstMaterial?.diffuse.contents = NSColor(
calibratedRed: 0, green: 0, blue: 0, alpha: 1
)
Expand Down Expand Up @@ -147,11 +145,7 @@ class HeadScene: SCNScene, ObservableObject {
ringGeometry3.firstMaterial?.emission.contents = NSColor(.white)
ring3.rotation = SCNVector4(x: 1, y: 0, z: 0, w: 3.14 / 2)

// headGroup.addChildNode(ring)
// headGroup.addChildNode(ring2)
// headGroup.addChildNode(ring3)

// add the light node to the scene
rootNode.addChildNode(lightNode)
rootNode.addChildNode(lightNode2)
headGroup.addChildNode(head)
Expand All @@ -162,19 +156,19 @@ class HeadScene: SCNScene, ObservableObject {
headGroup.addChildNode(nose)
headGroup.addChildNode(mouth)

// mirror

mirror.addChildNode(headGroup)

// set up scene

rootNode.addChildNode(mirror)

// set up camera

let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 3)
rootNode.addChildNode(cameraNode)

// Set camera to look at the origin

let constraint = SCNLookAtConstraint(target: rootNode)
cameraNode.constraints = [constraint]

Expand Down
4 changes: 1 addition & 3 deletions PodPals/PodPalsApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,19 @@ class AppState: ObservableObject {
var headphoneMotionDetector = HeadphoneMotionDetector()

init() {
// Initialize with stored values or defaults
self.sensitivity = UserDefaults.standard.string(forKey: "sensitivity") ?? "Low"
self.leftFlick = UserDefaults.standard.string(forKey: "leftFlick") ?? "Previous Track"
self.rightFlick = UserDefaults.standard.string(forKey: "rightFlick") ?? "Next Track"
self.nod = UserDefaults.standard.string(forKey: "nod") ?? "Play/Pause"
self.trackingEnabled = UserDefaults.standard.bool(forKey: "trackingEnabled")
self.mediaPlayerAvailability = MediaPlayerChecker.checkAvailability()
// Set up motion detector

headphoneMotionDetector.onUpdate = { [self] in
quaternion = self.headphoneMotionDetector.correctedQuaternion
}

headphoneMotionDetector.start()

// repeatedly check if access has been granted by the user
if !HeadphoneMotionDetector.isAuthorized() {
if HeadphoneMotionDetector.authorizationStatus == CMAuthorizationStatus.notDetermined {
accessCheckTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
Expand Down
2 changes: 1 addition & 1 deletion PodPals/RotationViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct RotationViewer: NSViewRepresentable {
var scene: HeadScene

func makeNSView(context _: Context) -> SCNView {
// set up scene

let sceneView = SCNView()

sceneView.scene = scene
Expand Down

0 comments on commit 32dbe19

Please sign in to comment.