34
Device (dis)Orientation? Luz Caballero @gerbille

Device dis(orientation)?

Embed Size (px)

DESCRIPTION

Talk a

Citation preview

Page 1: Device dis(orientation)?

Device (dis)Orientation?

Luz Caballero @gerbille

Page 2: Device dis(orientation)?

•What is it?

•Some math you need to know

•Code

•Support and implementations

•Tips and tricks

Page 3: Device dis(orientation)?

•deviceorientation

•devicemotion

•compassneedscalibration

Page 4: Device dis(orientation)?

* image sources: http://mygadgetnews.com/tech/apple-looking-to-radically-improve-maps-and-location-services-in-ios-5

http://www.sub5zero.com/top-10-racing-games-iphone/

static / one off dynamic / interactive

Page 5: Device dis(orientation)?

deviceorientation

Page 6: Device dis(orientation)?

Code at: https://github.com/luzc/wiimote

Page 7: Device dis(orientation)?

QuickTime™ and a decompressor

are needed to see this picture.

(back up plan!)

Page 8: Device dis(orientation)?

The math

Page 9: Device dis(orientation)?
Page 10: Device dis(orientation)?

Tait-Bryan angles

Page 11: Device dis(orientation)?
Page 12: Device dis(orientation)?

QuickTime™ and aGIF decompressor

are needed to see this picture.

Page 13: Device dis(orientation)?

V = R(gamma, y’’).R(beta, x’).R(alpha, z).Vo

If you want to apply a rotation:

.VoV =

1st2nd3rd

Page 14: Device dis(orientation)?

alpha/gamma singularity

Page 15: Device dis(orientation)?

Disoriented much?

Page 16: Device dis(orientation)?

The code

Page 17: Device dis(orientation)?

remote.js model.js

server.jsα, β, ɣ α, β, ɣ

Page 18: Device dis(orientation)?

var ws = new WebSocket('ws://10.112.0.139:8080/');//listen to device orientationwindow.addEventListener('deviceorientation', function(e) {  if (ws.opened) {    ws.send(JSON.stringify({      alpha: e.alpha,      beta: e.beta,      gamma: e.gamma    }));  }});

remote.js:

Page 19: Device dis(orientation)?

model.js:

window.addEventListener('DOMContentLoaded', function init() {  //connect to server using websockets  var ws = new WebSocket('ws://10.112.0.139:8080/');  ws.onopen = function() {    ws.onmessage = function(e) {      var data = JSON.parse(e.data),        avalue = data.alpha / 180 * Math.PI,        bvalue = data.beta / 180 * Math.PI,        gvalue = data.gamma / 180 * Math.PI;                teapot.rotation.set(gvalue, avalue, -bvalue);     };   };});

Page 20: Device dis(orientation)?

Support

Page 21: Device dis(orientation)?
Page 22: Device dis(orientation)?

luzc.github.com/webtests/• orientation• compass• motion

Page 23: Device dis(orientation)?

Tested running luzc.github.com/webtests/orientation in a Samsung Galaxy 2 and an iPhone (iOS6), on February 18, 2013

α β ɣ

Chrome for Android

Firefox for Android

Opera Mobile for Android

Safari for iOS6

Specification

↑N ↑up ↑up

270360/0___|___180

| 90

360/0270___|___90

| 180

0/360 90___|___270

|180

0-90___|___90

| 0

0-90/270___|___90

| 180

0-90___|___90

|-180/180

0-90___|___90

| 0

0-90___|___90

| 0

0-90___|___90

|-180/180

0-90___|___90

| 0

0-90___|___90

| -180/180

0/360 90___|___270

|180

0-90___|___90

|-180/180

0-90___|___90

| 0

0/360 90___|___270

|180

Page 24: Device dis(orientation)?

Portrait vs. landscape matters!

Page 25: Device dis(orientation)?

Holding your device THE RIGTH WAY™

How FF thinks you should hold your landscape device

How Opera (and Chrome) think you should hold your

landscape device

Page 26: Device dis(orientation)?
Page 27: Device dis(orientation)?

BYO Calibration!!

Page 28: Device dis(orientation)?

You may want some buffering

https://github.com/richtr/Marine-Compass

Page 29: Device dis(orientation)?

devicemotion

Page 30: Device dis(orientation)?

•rotationRate

•acceleration

•accelerationIncludingGravity

•interval

Page 31: Device dis(orientation)?

•acceleration (Safari)

•accelerationIncludingGravity (Safari, Opera, FF)

•rotationRate (Safari)

•interval (Opera, Safari, FF)

run luzc.github.com/webtests/motion in a Samsung Galaxy Tab 2 and iOS6

Page 32: Device dis(orientation)?

window.addEventListener('devicemotion', function(e){ if(e.acceleration){ //e.acceleration.x

//e.acceleration.y//e.acceleration.z } if(e.accelerationIncludingGravity){//e.accelerationIncludingGravity.x

//e.accelerationIncludingGravity.y //e.accelerationIncludingGravity.z } if(e.rotationRate){ //e.rotationRate.alpha//e.rotationRate.beta//e.rotationRate.gamma } if(e.interval){ //e.interval } });

Page 33: Device dis(orientation)?

Things to remember:

• Angular position, angular speed and acceleration

• Intrinsic axes of rotation

• Rotations have to be applied *in order*

• Singularity in alpha/gamma

• 3D libraries / languages can make your life easier

• Browser support but different implementations

• BYO calibration

• Portrait/landscape matters

• You may want some buffering

• Device motion has only partial support

Page 34: Device dis(orientation)?

That’s all :)

Luz Caballero @gerbillegithub.com/luzc

Thanks!!