New Library Of Accelerometer Helper Functions

Hi all,

I just wanted to share a library I created for use in my own game. I do not have the permissions to post in the code exchange, so I uploaded it to github. Please check it out, and let me know how it works for you. You can find it here.

It includes several functions that calculate different angles angle based on the device’s accelerometer gravity. The documentation is available on that page. It includes one sample app. Also, the library is compatible with corona remote. [import]uid: 16410 topic_id: 5812 reply_id: 305812[/import]

hi

thanks for this!

just one thing…

i believe it is faster to “cache” math functions locally, if you are going to reuse them. i realise you only use it twice here but we want to squeeze every spare nanosecond out right? :wink:

eg

[lua]module(…, package.seeall)
local ceil = math.ceil – cache ceil function

function getAccelerometerTopAngle(xGravity, yGravity)
– return the rounded result of getPreciseAccelerometerTopAngle
return ceil(getPreciseAccelerometerTopAngle(xGravity, yGravity))
end

function getAccelerometerUpAngle(xGravity, yGravity)
– return the rounded result of getPreciseAccelerometerUpAngle
return ceil(getPreciseAccelerometerUpAngle(xGravity, yGravity))
end[/lua] [import]uid: 6645 topic_id: 5812 reply_id: 19964[/import]

Yep. Done. Thanks for the suggestion. If I’m going to create a library, I suppose it should be as “correct” as possible. I wonder what the performance increase is though…

How is it working for you? I updated the code to reflect the changes you suggested. You can find it at the same link. [import]uid: 16410 topic_id: 5812 reply_id: 20041[/import]

mtnbkrpro, awesome stuff. Thanks for sharing! [import]uid: 8045 topic_id: 5812 reply_id: 21632[/import]

You’re welcome. Glad it’s working for you. Let me know if you have any suggestions or ideas. [import]uid: 16410 topic_id: 5812 reply_id: 21727[/import]

Nice work, thanks for sharing. [import]uid: 3953 topic_id: 5812 reply_id: 22251[/import]