iPhone GETJOYY, calibration, duplicate values?

Previous topic - Next topic

bigtunacan

I'm trying to add in tilt controls to my game on iPhone and I noticed for GETJOYY() any given value returned by GETJOYY actually indicates to possible positions of the phone.  Essentially if I start with the phone laying face up I will have a y value of 0.  A quarter turn in one direction will flow from 0 to positive 1; a quarter turn the other direction will flow from 0 to negative 1.  Continuing past the quarter turn point will cause the values to reduce back towards 0.  The result is that every value represents 2 phone positions rather than a unique phone position.

I'm testing this on an iPhone 3G.  I verified this behavior by pulling GETJOYY(0) and printing it to the screen of my iPhone as I rotated the phone after experience some rather bizarre behavior in my game.

This is the code I used to verify.
Code (glbasic) Select

LOCAL y = GETJOYY(0)
PRINT "ybefore: " + y, 0, 60


Is this the expected behavior?

Kitty Hello

y value is gravity direction component in Y direction (bottom of phone=1, top of phone=-1).

If you hold your phone like you are talking to a call, the values should be +1, thus.
If you flip it upside down then, the value should be -1
If you lay it flat on the table, it should be 0

matchy

And if you hold the axis diagonally (45 or 180+45 degree angle) the result is +/- 0.25/0.75.

Quote from: bigtunacan on 2011-Oct-18...as I rotated the phone after experience some rather bizarre behavior in my game.

Anyhow, what's the bizarre behavior?

Moebius

QuoteThe result is that every value represents 2 phone positions rather than a unique phone position.
That's why there are 'GETJOYX()' and 'GETJOYZ()'  :good:
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

bigtunacan

#4
Quote
If you hold your phone like you are talking to a call, the values should be +1, thus.
If you flip it upside down then, the value should be -1
If you lay it flat on the table, it should be 0

What you explain there is what I thought should happen.  But that is not what I'm seeing.  While phone is laying face up value is 0.  While phone is laying face down value again is 0.

@Serpent,

I'm not sure what you are trying to say there.  If I were able to rotate the phone perfectly about a single axis then the values related to the other 2 axis would not change so their values are not helpful.  Each axis is reports independently.  Or is there something I'm missing here?

Kitty Hello

face up and face down = 0. That's true. Because there's no gravity acting on the sensor that checks for the top-to-bottom axis. Do you understand?

bigtunacan

Ok, I will have to rethink how I am handling my tilt controls then

bigtunacan

#7
I've been agonizing over this all day and have not been making progress.

Here is what I currently have
Code (glbasic) Select


        // At initialization I grab the current y accelleration
IF platform = "IPHONE" THEN  yoff = GETJOYY(0)


        // Then in my game loop I get accelleration
LOCAL y = GETJOYY(0)
        // and try to offset it by the initial value
        y = y-yoff

IF y > .1 AND (play1.ent.locy > play1.ent.ymin)
        DEC play1.ent.locy, 10.0*y
DEC play1.shadow.locy, 10.0*y
ELSEIF y < -.1 AND (play1.ent.locy < play1.ent.ymax)
DEC play1.ent.locy, 10.0*y
DEC play1.shadow.locy, 10.0*y
        ENDIF


This does not work. Once the user hits a certain point of rotation the controls will invert.  Also at certain positions of rotation for the starting calibration controls will then not work at all (this seems to happen if the phone is held at a 90 degree rotation up from laying face down or up.

bigtunacan

I've been struggling with this for a few days; Googled it a hundred times; searched the forums here; and still have no idea what to do :(

I found the following post on the boards where another guy was having the exact same problem 2 years ago, but didn't look like he figured it out either...

http://www.glbasic.com/forum/index.php?topic=3939.msg28886#msg28886

I saw the Gernot replied to the other post with

Quoteget the accelerations for the "still" state. Then subtract these from the actual acceleration on each run.

I think to make it really work, you need to make a rotation matrix for the "is" state, then invert that and multiply the current state with the invese matrix each time. Overkill IMO.

The first part of that statement is what I've been attempting to do in my code, but it doesn't work correctly, not sure what I'm doing wrong.  For the second part I really don't understand how to even begin to do that.

Someone has to have solved this problem already; I will gladly write up a tutorial and post it back here for future users if someone can help me get this working.

Kitty Hello

I made a code snippet / math for this. Might be of interest for others as well:

http://www.glbasic.com/forum/index.php?topic=7115.0

bigtunacan

Thanks for the code snippet.  I updated my controls based off of your advice.  It works much better than before.  Now I can calibrate off of quite a few positions and the controls will still work, but there are some angles that you can calibrate from that just won't work correctly.  I wonder if this is a limitation of the accelerometer? I tried playing my game while sitting (worked fine), laying on my back (worked fine), and various stages of laying on my side (some angles from a side angle worked, others didn't not...)  I also searched the web and downloaded a few app store apps that use the motion controls, and every one I found locks the user into using the phone in a limited position, so hopefully this won't be a big deal if I release my game this way as well :)