2

i am developing an augmented reality application with my team. we decided to choose phonegap as framework for developing it as a webapp. We use the Three.js framework to draw the augmented reality into the canvas.

My problem is to get the camera rotation working based on the phone movement. i searched through the internet for a few days but can't get it. the actual idea was to use the getRotationMatrix() method out of the android SDK and rewrite it to javascript. but the problem is to get the x, y, z data from the compass. phonegap only provides heading relative to the geographic north pole in degrees (0 .. 360) but the getRotationMatrix() method uses the x, y, z values.

is it possible to refract the axis values out of the heading value or get them directly?

do you have other ideas to calculate the camera rotation on all three axis?

thank you so much for any hints!

chsymann
  • 1,640
  • 1
  • 15
  • 15

2 Answers2

0

The compass will give you a heading but the accelerometer will give you the devices x,y,z values. See the example in our docs:

http://docs.phonegap.com/en/1.6.1/cordova_accelerometer_accelerometer.md.html#accelerometer.getCurrentAcceleration

Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • Thank you for your answer but thats not what i was looking for. I really wanted to get the x, y, z compass values. I finaly wrote my own Phonegap Plugin to get those values. – chsymann May 02 '12 at 22:24
  • @chsymann, is it possible to share with us the plugin you wrote? – Philip May 04 '12 at 14:21
  • @chsymann I think you're mixing up concepts. If you want it as a rotation matrix, you could just assume that the compass heading is your Z rotation, but X and Y you'd have to invent. What do you expect X & Y rotation axes to be for a compass which is essentially a 1-dimensional sensor? – Luke H Jun 29 '12 at 21:19
  • @Mateu Hey, its long time ago that I worked on this but I browsed my project and found the plugin part. My time is rare at moment so I am not able to get into it and tell you exactly how to get it working but I remind that phonegaps docu is good about this part. Here is the plugin stuff only.. hope you'll get it working. http://pastie.org/5721888 (Java Code for Android) http://pastie.org/5721909 (Phonegaps JS). attention: this will only work for android. you'll need to implement the native stuff for ios or whatever yourself. – chsymann Jan 18 '13 at 21:24
  • Thanks! At the end I managed to find an html5 alternative to solve the problem: http://www.html5rocks.com/en/tutorials/device/orientation/ – Mateu Jan 21 '13 at 10:58
  • @Mateu wow.. HTML5 rocks! Think this one is much cooler than my plugin-solution. Thanks for sharing! – chsymann Jul 17 '13 at 11:32
  • @chsymann I've posted the solution. You can accept it if you like it. ;) – Mateu Sep 12 '13 at 09:04
0

You can use html5 deviceorientation. It works great

I add a tutorial about it: http://html5rocks.com/en/tutorials/device/orientation

Mateu
  • 2,636
  • 6
  • 36
  • 54