• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Query about device orientation?

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to develop a simple game where players just tap a ball around.
So 4 players are positioned on a circle at gap of 90 degree each. What I want
to have is that for passing the ball from one player to another player user needs to tilt the device
in appropriate direction.
So my plan is to somehow determine the direction of tilt so that I can determine to which player
the ball would move next.
I have gone through articles and forum posts, and understand that to determine tilt direction
I need to make use of rotation matrix.
But I am not able to really understand how to go through it all. Android documentation seems to be sparse.
Can someone give me some direction on this?

Manish
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
....sorry to forget to mention that I am working on Android.
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If player holds the phone flat with screen facing up and then rotates the phone around z-axis (ie, "yaws" on the axis coming out of screen) while still keeping it flat, should the ball move?
If not, then I feel accelerometer sensor values are enough; you don't really need a rotation matrix.
I've written an app which visualizes accelerometer readings on a graphical x,y,z axis and I can confirm that accelerometer values change when phone is tilted while stationary. But they'll also change if phone
is moved along one of the axes while not changing the tilt. So your app may need some logic to differentiate between the two.
The image below shows which axis is which:
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Karthik,

Thanks for inputs.

So, when I have accelerometer values with me then how can tilt data be extracted from it? Do I need to use
trigonometry for it or is it much more involved?

Manish
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need any trigonometry at all, just division.
Imagine the diagram below is a phone kept flat with screen pointing up, and you're looking at the screen directly vertically down.

Documentation is here.
From observations, accelerometer values for a stationary phone that is tilted are:
- phone is flat with screen pointing up: x=0, y=0, z=+g (g = accel due to gravity, ~9.8)
- BC is tilted down towards the floor 45 degrees clockwise so that AD moves up (ie, clockwise rotation around y-axis): x = -g/2, y=0, z=+g/2
- BC is tilted down towards the floor 90 degrees clockwise so that AD is directly above it (clockwise rotation around y-axis): x = -g, y=0, z=0
- AD is tilted down towards the floor 45 degrees counterclockwise so that BC moves up (ie, CCW rotation around y-axis): x = +g/2, y=0, z=+g/2
- AD is tilted down towards the floor 90 degrees counterclockwise so that BC is directly above it (CCW rotation around y-axis): x = +g, y=0, z=0
- AB is tilted down towards the floor 45 degrees clockwise so that DC moves up (ie, clockwise rotation around x-axis): x=0, y=-g/2, z=g/2
- AB is tilted down towards the floor 90 degrees clockwise so that DC moves directly above it (ie, clockwise rotation around x-axis): x=0, y=-g, z=0
- DC is tilted down towards the floor 45 degrees counterclockwise so that AB moves up (ie, CCW rotation around x-axis): x=0, y=+g/2, z=g/2
- DC is tilted down towards the floor 90 degrees counterclockwise so that AB moves directly above it (ie, CCW rotation around x-axis): x=0, y=+g, z=0

So you can see that 45 degree angle corresponds to g/2 (I can see it's approximate; not sure why - but probably good enough for a game). You can use simple proportion of measured value / g to get angles.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic