Trying to understand Touch Orientation

Discussion and feedback on Construct 2

Post » Sun Jun 15, 2014 11:43 am

Hi guys,

I am trying to learn and understand how the alpha, beta and gamma in touch orientation work. I did a test where three text objects display the values for each at every tick. I rotate my phone in every type of axis to test it out and get a better understanding of how it works. Problem is I really don't understand the results.

For example: When I hold it standing up straight on a table, the gamma which I read is in charge of right to left tilt, was somewhere in 80s. I thought that it was reading it close to 90 degrees. But when I tilt it roughly 30 degrees to either side, the numbers jumped a lot. It even went until the 10s. Another thing, I just tilt my phone to the left or right, but all three values changed a lot. I tried various axis movement and all three values moved around a lot. And also sometimes the numbers jump from negative to positive. For example, holding it in my slightly shaking hands, the value could jump from +80s to -80s. That was really confusing to me.

I apologize if I am missing something obvious here, but I really do hope that someone would be able to shed some light on this. For your reference, I tested it out on my HTC One using Crosswalk in the Intel XDK debugger test. Would really appreciate any info and guidance on this. Thanks.
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Tue Jan 13, 2015 1:29 pm

Hey I'm experimenting with the orientation sensors, and having the same results
For example the Alpha seems to be okay at 0/180/360, but in between changes in some kind of non-linear ease-in ease-out way
Not sure about the Beta and Gamma... are we expected to do math related to euler angles & gimbal?

The manual says "Alpha is the compass direction in degrees", so I would expect a linear change while rotating my device (nexus 7)
Are we missing something, or can other people try this too and explain the results?
Feel free to post a capx as well if anyone manages to do a simple 2d compass for example that works
B
22
S
6
G
8
Posts: 328
Reputation: 6,651

Post » Tue Jan 13, 2015 3:36 pm

I still haven't figured it out as well. In fact, I had to give up on that game project for the time being as I couldn't find any solution. But I am still interested in learning about it, and maybe continue that project again. Hopefully someone will be able to shed more light.
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Thu Jan 15, 2015 1:38 am

Yeah I'd be keen to use it for 3-axis application, especially since Q3D went live
I might consider posting in the bug section if no one has an explanation
Maybe @Ashley can shine some light on this?
B
22
S
6
G
8
Posts: 328
Reputation: 6,651

Post » Sun Jan 18, 2015 2:31 pm

Replying here after I was tagged in that old thread. Not sure how helpful this'll be but this is how I do it.

- Alpha works kind-of like a compass, it's the rotation along the Z-axis of the phone. But it's not absolute, like a real compass. It resets its heading every time the app starts up. So 0 will always mean "the phone is pointing forwards". 180 means "the phone is pointing backwards."
- Beta is the front/back swivel of the phone. A negative value means that the phone is tilted forwards. A positive value means that it's tilted backwards.
- Gamma is the side-to-side swivel of the phone. A negative value means that the phone is tilted to the left. A positive value means that it's tilted to the right.

Using these values you can determine if a phone is upside-down (gamma -180), lying face-up (gamma 0), is held upright (beta 90), and so on.

Easiest example is using a tilt forwards/backwards/left/right mechanism to control a character on the screen. To do this, you want to figure out the angle that the character will move towards. Easiest way to do this is to use Construct's angle expression Angle(X1,Y1,X2,Y2) to determine the angle from the starting point to where you want to go. In our case, the starting point will always be 0,0. You're not moving a character from an actual place on the screen, just trying to figure out which angle it should face. Its position isn't important.

Our expression therefore becomes angle(0,0,touch.Gamma,touch.Beta). You use the gamma value as the X, and the beta value as the Y. Doing it this way you're plotting a position on an arbitrary cartesian plane based on the values you receive from the touch object.

Super important: find an initial offset when you start your app, and add/subtract it from your touch values when using them. If the player starts a game with their phone slightly tilted up, or entirely upside-down (maybe they're lying down), you need to take this into account. The touch values assume a phone is lying completely flat, and the whole thing is very twitchy. Best not to use the touch values directly for player input: smooth them out a bit first.
B
57
S
15
G
11
Posts: 912
Reputation: 12,626

Post » Sun Jan 18, 2015 4:18 pm

@GeometriX. Thank you! Any help on the matter is really appreciated. I am not sure, but maybe in my previous capx, I didn't find the initial offset which is why it didn't work at all. I'm now working halfway on another project, so I don't want to leave it first or I will get confused when I return. But will definitely want to return to my old capx once I have the time and try it. Hope you won't mind if I tag you again in the near future in this post if I was to encounter a problem with regards to this exact topic. Again, thanks!
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Sun Jan 18, 2015 5:20 pm

Thanks for the reply @GeometriX, but my main issue, and I believe rekjl's original one as well, was not about the code logic, but rather about the actual sensor value readings

And probably most people indeed use the values for C2 games like you described, but this mechanism doesn't work for "absolute" orientation, because the numbers are not "proportional"

For example you can try yourself, if you lift the left side of your device to read Gamma 45, it's actually just around 30 degrees rotation (and then catch up fine at Gamma 90 / 90 degrees)

Like I mentioned before, this looks like ease-in ease-out, and I'm starting to wonder if C2 is applying that on purpose for more precision with the kind of gameplay mechanism you described

But then it breaks the option to make a simple compass, and I still invite anyone to make a working one using the Alpha value...
B
22
S
6
G
8
Posts: 328
Reputation: 6,651

Post » Sun Jan 18, 2015 5:40 pm

@lemo, it might be interpolating the values. Personally, I haven't found an occasion where that factor is so destructive that I can't work around it, considering that its most typical usage scenario would be character movement. I'm not sure what you mean by the numbers not being "proportional", though.

I'd hazard to guess that this lag has more to do with the fact that accelerometers/gyroscopes aren't digital devices. They're analogue (albeit tiny): there's physical motion that has to happen to determine a phone's orientation.

Depending on your phone, the polling rate for the accelerometer might be quick or slow. I tested mine (Galaxy S3) and it takes about a second to "catch up" from 90 to 0 degrees.

I haven't seen a phone-based compass that behaves in the way you're describing - practically instant, right? Do you have an example app that you could link to? I don't know if C2 can even access a phone's compass, but I doubt that'd be too much of a challenge for a plugin to handle.

EDIT: Actually, I'm mistaken. Alpha does read the actual, absolute, compass heading. Not sure why I thought otherwise, but it seems to work pretty well for me.
B
57
S
15
G
11
Posts: 912
Reputation: 12,626

Post » Sun Jan 18, 2015 7:18 pm

@GeometriX I mean the evolution of each is not proportional/linear from 0 to 180 (or 360)

The lag or delay doesn't bother me, what does is strange values between 0 to 90

Also Alpha range should be 0-360, did you ever manage to have it between 100-260 in C2?

Yeah it should be just like an absolute compass

And in theory it should point North with "Set Angle to > 360 - Touch.Alpha", but it doesn't
B
22
S
6
G
8
Posts: 328
Reputation: 6,651

Post » Sun Jan 18, 2015 8:05 pm

@lemo Try this on your phone: https://dl.dropboxusercontent.com/u/145 ... index.html

The event is just System: Every tick | Compass: Set angle to Touch.Alpha-90 degrees

Not sure why it's offset by 90 degrees, but hey, it works. I tested it with a real compass right beside and it's very consistent.

I can read values across the range, 0-360. It sometimes lags a bit if I turn quickly, but it always finds itself after a second or two.
B
57
S
15
G
11
Posts: 912
Reputation: 12,626

Next

Return to Construct 2 General

Who is online

Users browsing this forum: ardhitosen and 6 guests