Defold Gyro - The gyroscope extension

As was mentioned in this forum post I have published a first version of a gyroscope extension for Defold. The extension is pretty straight forward to use:

function init(self)
  gyro.start(function(self, pitch, roll, yaw, quatx, quaty, quatz, quatw)
    go.set_rotation(vmath.quat(quatx, quaty, quatz, quatw))
  end)
end

function final(self)
  gyro.stop()
end

The project also includes an example that uses the Defold camera extension to create an augmented reality experience:

24 Likes

Update: I’ve added Android support.

10 Likes

hi
thank you for publishing gyro extension.

I tested your gyro extension in my project on android device.
but, it dose not work.

but, it work normally on iOS device.

Do you get an error? Do you get a callback to your listener? What kind of Android device are you testing on?

I used this code.
Values are not changed.

gyro.start(function(self, self, quatx, quaty, quatz, quatw)
			local text = string.format("(%.2f, %.2f)", quatx, quaty)
			msg.post("@render:", "draw_text", {text = "gyro : " .. text, position = vmath.vector3(10, 200, 0)})
	end)

(at GitHub example)

and, I tested on Samsung GALAXY S4.

thank you.

You have two self parameters in your callback. Or are you not getting any callbacks at all?

1 Like

I get callback from listener.
but, quatx, y is always Zero(0.0).

Should I check ‘self’ parameters?

thank you.

Ah, I see now. There was an error in my example:

There should obviously only be one self. The correct example is:

function init(self)
  gyro.start(function(self, quatx, quaty, quatz, quatw)
    go.set_rotation(vmath.quat(quatx, quaty, quatz, quatw))
  end)
end
1 Like

thank you.

but, result is the same.
the callback is called, but the value is zero(0.000000).

I will try more.
thank you.

Strange. Could you please try to print quatx, quaty, quatz, quatw without the formatting that you have in your example?

local text = string.format("%f, %f, %f, %f", quatx, quaty, quatz, quatw)

I had test it.

local text = string.format("%d : %f, %f, %f, %f", testCount, quatx, quaty, quatz, quatw)

all parameters are 0.000000.
(ex, 134 : 0.000000, 0.000000, 0.000000, 0.000000)
(testCount parameter is callback count)

I would send you the code if you want.
Something I would have done wrong.

I’ll try to get hold of an S4 from our device pool and test the extension using it.

Thank you very much.

I tested on a Samsung Galaxy S3 with the example app that comes with the extension and it works as expected. I did however come across a crash after a short while, but I’ve pushed a fix for that.

Edit: I (no, correction @Mathias_Westerdahl) figured it out. The extension uses TYPE_GAME_ROTATION_VECTOR which was made available in API Level 18 (ie Android 4.3). I’ll try to fallback to TYPE_ROTATION_VECTOR on older devices. Stay tuned!

1 Like

Yep, that did the trick! I got it working on a Samsung Galaxy S2 with Android 4.0.3. I’ve pushed the new version of the extension. Please give it a try and let me know if it’s working for you as well.

3 Likes

I changed the gyro extension.
I’m sorry. It still dose not work.
Values are zero.

My test device is…
Galaxy S4
(SHV-E300L)
Android 5.0.1

I would test it on another device.
thank you.

I tested that it work on the Galaxy S2.
It works well. No problem.

There seems to be a problem with my phone(Galaxy S4).
but, I confirmed that My Galaxy S4 operates normally in other gyro APP.
strange…

Anyway…
Thank you for your support.

Hmm, very strange. I wonder if the S4 doesn’t support the TYPE_GAME_ROTATION_VECTOR? And it seems like it doesn’t: https://stackoverflow.com/questions/26697604/alternative-for-type-game-rotation-vector

I’ll get the sensor list and fallback to TYPE_ROTATION_VECTOR if possible.

I’ve added a fallback to the standard rotation vector sensor if the game rotation vector sensor isn’t available. I’ve verified that this works on an S4 Mini running Android 4.4.2. Would you mind testing on your S4 device as well?

7 Likes

I have tested it.

WONDERFUL!
It dose work well on my S4.

Thank you so much for your support.
^^

6 Likes