The Wayback Machine - https://web.archive.org/web/20220827054223/https://github.com/cwei/DaydreamController
Skip to content

cwei/DaydreamController

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

DaydreamController

Supports the Google VR Daydream View Controller on iOS. This is a first working hack.

Try it in your own project

Create a new iOS Game project (SceneKit) with Xcode, add the DaydreamController.swift file and modify GameViewController.swift like this:

class GameViewController: UIViewController
{
    let controller = DaydreamController()
    var ship: SCNNode!
    var orientation0 = GLKQuaternionIdentity
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        controller.delegate = self
        controller.connect()
            
        ....

        // retrieve the ship node
        ship = scene.rootNode.childNode(withName: "ship", recursively: true)!

        // animate the 3d object
        // ship.runAction(SCNAction.repeatForever(SCNAction.rotateBy(x: 0, y: 2, z: 0, duration: 1)))

        ....
    }
}

extension GameViewController: DaydreamControllerDelegate
{
    func daydreamControllerDidConnect(_ controller: DaydreamController) {
        print("Press the home button to recenter the controller's orientation")
    }

    func daydreamControllerDidUpdate(_ controller: DaydreamController, batteryLevel: UInt8) {
        print("battery level \(batteryLevel)%")
    }

    func daydreamControllerDidUpdate(_ controller: DaydreamController, state: DaydreamController.State) {
        if state.homeButtonDown {
            orientation0 = GLKQuaternionInvert(state.orientation)
        }
        
        let q = GLKQuaternionMultiply(orientation0, state.orientation)
        ship.orientation = SCNQuaternion(q.x, q.y, q.z, q.w)
    }
}

About

Google VR Daydream Controller on iOS.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages